@metamask-previews/message-manager 11.0.3-preview-ca1f35f → 11.0.3-preview-e05b7d3e
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 +7 -0
- package/dist/AbstractMessageManager.cjs +53 -49
- package/dist/AbstractMessageManager.cjs.map +1 -1
- package/dist/AbstractMessageManager.d.cts +48 -49
- package/dist/AbstractMessageManager.d.cts.map +1 -1
- package/dist/AbstractMessageManager.d.mts +48 -49
- package/dist/AbstractMessageManager.d.mts.map +1 -1
- package/dist/AbstractMessageManager.mjs +54 -50
- package/dist/AbstractMessageManager.mjs.map +1 -1
- package/dist/DecryptMessageManager.cjs +11 -8
- package/dist/DecryptMessageManager.cjs.map +1 -1
- package/dist/DecryptMessageManager.d.cts +26 -10
- package/dist/DecryptMessageManager.d.cts.map +1 -1
- package/dist/DecryptMessageManager.d.mts +26 -10
- package/dist/DecryptMessageManager.d.mts.map +1 -1
- package/dist/DecryptMessageManager.mjs +11 -8
- package/dist/DecryptMessageManager.mjs.map +1 -1
- package/dist/EncryptionPublicKeyManager.cjs +11 -8
- package/dist/EncryptionPublicKeyManager.cjs.map +1 -1
- package/dist/EncryptionPublicKeyManager.d.cts +25 -10
- package/dist/EncryptionPublicKeyManager.d.cts.map +1 -1
- package/dist/EncryptionPublicKeyManager.d.mts +25 -10
- package/dist/EncryptionPublicKeyManager.d.mts.map +1 -1
- package/dist/EncryptionPublicKeyManager.mjs +11 -8
- package/dist/EncryptionPublicKeyManager.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,23 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ActionConstraint, EventConstraint, RestrictedControllerMessenger } from "@metamask/base-controller";
|
|
2
|
+
import type { AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, MessageManagerState, OriginalRequest, SecurityProviderRequest } from "./AbstractMessageManager.cjs";
|
|
2
3
|
import { AbstractMessageManager } from "./AbstractMessageManager.cjs";
|
|
4
|
+
declare const managerName = "DecryptMessageManager";
|
|
5
|
+
export type DecryptMessageManagerState = MessageManagerState<DecryptMessage>;
|
|
6
|
+
export type DecryptMessageManagerUnapprovedMessageAddedEvent = {
|
|
7
|
+
type: `${typeof managerName}:unapprovedMessage`;
|
|
8
|
+
payload: [AbstractMessageParamsMetamask];
|
|
9
|
+
};
|
|
10
|
+
export type DecryptMessageManagerUpdateBadgeEvent = {
|
|
11
|
+
type: `${typeof managerName}:updateBadge`;
|
|
12
|
+
payload: [];
|
|
13
|
+
};
|
|
14
|
+
export type DecryptMessageManagerMessenger = RestrictedControllerMessenger<string, ActionConstraint, EventConstraint | DecryptMessageManagerUnapprovedMessageAddedEvent | DecryptMessageManagerUpdateBadgeEvent, string, string>;
|
|
15
|
+
type DecryptMessageManagerOptions = {
|
|
16
|
+
messenger: DecryptMessageManagerMessenger;
|
|
17
|
+
securityProviderRequest?: SecurityProviderRequest;
|
|
18
|
+
state?: MessageManagerState<DecryptMessage>;
|
|
19
|
+
additionalFinishStatuses?: string[];
|
|
20
|
+
};
|
|
3
21
|
/**
|
|
4
22
|
* @type DecryptMessage
|
|
5
23
|
*
|
|
@@ -10,18 +28,18 @@ import { AbstractMessageManager } from "./AbstractMessageManager.cjs";
|
|
|
10
28
|
* @property type - The json-prc signing method for which a signature request has been made.
|
|
11
29
|
* A 'DecryptMessage' which always has a 'eth_decrypt' type
|
|
12
30
|
*/
|
|
13
|
-
export
|
|
31
|
+
export type DecryptMessage = AbstractMessage & {
|
|
14
32
|
messageParams: DecryptMessageParams;
|
|
15
|
-
}
|
|
33
|
+
};
|
|
16
34
|
/**
|
|
17
35
|
* @type DecryptMessageParams
|
|
18
36
|
*
|
|
19
37
|
* Represents the parameters to pass to the eth_decrypt method once the request is approved.
|
|
20
38
|
* @property data - A hex string conversion of the raw buffer data of the signature request
|
|
21
39
|
*/
|
|
22
|
-
export
|
|
40
|
+
export type DecryptMessageParams = AbstractMessageParams & {
|
|
23
41
|
data: string;
|
|
24
|
-
}
|
|
42
|
+
};
|
|
25
43
|
/**
|
|
26
44
|
* @type DecryptMessageParamsMetamask
|
|
27
45
|
*
|
|
@@ -38,11 +56,8 @@ export interface DecryptMessageParamsMetamask extends AbstractMessageParamsMetam
|
|
|
38
56
|
/**
|
|
39
57
|
* Controller in charge of managing - storing, adding, removing, updating - DecryptMessages.
|
|
40
58
|
*/
|
|
41
|
-
export declare class DecryptMessageManager extends AbstractMessageManager<DecryptMessage, DecryptMessageParams, DecryptMessageParamsMetamask> {
|
|
42
|
-
|
|
43
|
-
* Name of this controller used during composition
|
|
44
|
-
*/
|
|
45
|
-
name: "DecryptMessageManager";
|
|
59
|
+
export declare class DecryptMessageManager extends AbstractMessageManager<DecryptMessage, DecryptMessageParams, DecryptMessageParamsMetamask, ActionConstraint, EventConstraint | DecryptMessageManagerUnapprovedMessageAddedEvent | DecryptMessageManagerUpdateBadgeEvent> {
|
|
60
|
+
constructor({ additionalFinishStatuses, messenger, securityProviderRequest, state, }: DecryptMessageManagerOptions);
|
|
46
61
|
/**
|
|
47
62
|
* Creates a new Message with an 'unapproved' status using the passed messageParams.
|
|
48
63
|
* this.addMessage is called to add the new Message to this.messages, and to save the unapproved Messages.
|
|
@@ -72,4 +87,5 @@ export declare class DecryptMessageManager extends AbstractMessageManager<Decryp
|
|
|
72
87
|
*/
|
|
73
88
|
prepMessageForSigning(messageParams: DecryptMessageParamsMetamask): Promise<DecryptMessageParams>;
|
|
74
89
|
}
|
|
90
|
+
export {};
|
|
75
91
|
//# sourceMappingURL=DecryptMessageManager.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DecryptMessageManager.d.cts","sourceRoot":"","sources":["../src/DecryptMessageManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DecryptMessageManager.d.cts","sourceRoot":"","sources":["../src/DecryptMessageManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,E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AAa,qBAAsB,SAAQ,sBAAsB,CAC/D,cAAc,EACd,oBAAoB,EACpB,4BAA4B,EAC5B,gBAAgB,EACd,eAAe,GACf,gDAAgD,GAChD,qCAAqC,CACxC;gBACa,EACV,wBAAwB,EACxB,SAAS,EACT,uBAAuB,EACvB,KAAK,GACN,EAAE,4BAA4B;IAU/B;;;;;;;OAOG;IACG,yBAAyB,CAC7B,aAAa,EAAE,oBAAoB,EACnC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IAqClB;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAa,EAAE,oBAAoB,EACnC,GAAG,CAAC,EAAE,eAAe;IAwBvB;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAa,EAAE,4BAA4B,GAC1C,OAAO,CAAC,oBAAoB,CAAC;CAIjC"}
|
|
@@ -1,5 +1,23 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ActionConstraint, EventConstraint, RestrictedControllerMessenger } from "@metamask/base-controller";
|
|
2
|
+
import type { AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, MessageManagerState, OriginalRequest, SecurityProviderRequest } from "./AbstractMessageManager.mjs";
|
|
2
3
|
import { AbstractMessageManager } from "./AbstractMessageManager.mjs";
|
|
4
|
+
declare const managerName = "DecryptMessageManager";
|
|
5
|
+
export type DecryptMessageManagerState = MessageManagerState<DecryptMessage>;
|
|
6
|
+
export type DecryptMessageManagerUnapprovedMessageAddedEvent = {
|
|
7
|
+
type: `${typeof managerName}:unapprovedMessage`;
|
|
8
|
+
payload: [AbstractMessageParamsMetamask];
|
|
9
|
+
};
|
|
10
|
+
export type DecryptMessageManagerUpdateBadgeEvent = {
|
|
11
|
+
type: `${typeof managerName}:updateBadge`;
|
|
12
|
+
payload: [];
|
|
13
|
+
};
|
|
14
|
+
export type DecryptMessageManagerMessenger = RestrictedControllerMessenger<string, ActionConstraint, EventConstraint | DecryptMessageManagerUnapprovedMessageAddedEvent | DecryptMessageManagerUpdateBadgeEvent, string, string>;
|
|
15
|
+
type DecryptMessageManagerOptions = {
|
|
16
|
+
messenger: DecryptMessageManagerMessenger;
|
|
17
|
+
securityProviderRequest?: SecurityProviderRequest;
|
|
18
|
+
state?: MessageManagerState<DecryptMessage>;
|
|
19
|
+
additionalFinishStatuses?: string[];
|
|
20
|
+
};
|
|
3
21
|
/**
|
|
4
22
|
* @type DecryptMessage
|
|
5
23
|
*
|
|
@@ -10,18 +28,18 @@ import { AbstractMessageManager } from "./AbstractMessageManager.mjs";
|
|
|
10
28
|
* @property type - The json-prc signing method for which a signature request has been made.
|
|
11
29
|
* A 'DecryptMessage' which always has a 'eth_decrypt' type
|
|
12
30
|
*/
|
|
13
|
-
export
|
|
31
|
+
export type DecryptMessage = AbstractMessage & {
|
|
14
32
|
messageParams: DecryptMessageParams;
|
|
15
|
-
}
|
|
33
|
+
};
|
|
16
34
|
/**
|
|
17
35
|
* @type DecryptMessageParams
|
|
18
36
|
*
|
|
19
37
|
* Represents the parameters to pass to the eth_decrypt method once the request is approved.
|
|
20
38
|
* @property data - A hex string conversion of the raw buffer data of the signature request
|
|
21
39
|
*/
|
|
22
|
-
export
|
|
40
|
+
export type DecryptMessageParams = AbstractMessageParams & {
|
|
23
41
|
data: string;
|
|
24
|
-
}
|
|
42
|
+
};
|
|
25
43
|
/**
|
|
26
44
|
* @type DecryptMessageParamsMetamask
|
|
27
45
|
*
|
|
@@ -38,11 +56,8 @@ export interface DecryptMessageParamsMetamask extends AbstractMessageParamsMetam
|
|
|
38
56
|
/**
|
|
39
57
|
* Controller in charge of managing - storing, adding, removing, updating - DecryptMessages.
|
|
40
58
|
*/
|
|
41
|
-
export declare class DecryptMessageManager extends AbstractMessageManager<DecryptMessage, DecryptMessageParams, DecryptMessageParamsMetamask> {
|
|
42
|
-
|
|
43
|
-
* Name of this controller used during composition
|
|
44
|
-
*/
|
|
45
|
-
name: "DecryptMessageManager";
|
|
59
|
+
export declare class DecryptMessageManager extends AbstractMessageManager<DecryptMessage, DecryptMessageParams, DecryptMessageParamsMetamask, ActionConstraint, EventConstraint | DecryptMessageManagerUnapprovedMessageAddedEvent | DecryptMessageManagerUpdateBadgeEvent> {
|
|
60
|
+
constructor({ additionalFinishStatuses, messenger, securityProviderRequest, state, }: DecryptMessageManagerOptions);
|
|
46
61
|
/**
|
|
47
62
|
* Creates a new Message with an 'unapproved' status using the passed messageParams.
|
|
48
63
|
* this.addMessage is called to add the new Message to this.messages, and to save the unapproved Messages.
|
|
@@ -72,4 +87,5 @@ export declare class DecryptMessageManager extends AbstractMessageManager<Decryp
|
|
|
72
87
|
*/
|
|
73
88
|
prepMessageForSigning(messageParams: DecryptMessageParamsMetamask): Promise<DecryptMessageParams>;
|
|
74
89
|
}
|
|
90
|
+
export {};
|
|
75
91
|
//# sourceMappingURL=DecryptMessageManager.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DecryptMessageManager.d.mts","sourceRoot":"","sources":["../src/DecryptMessageManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DecryptMessageManager.d.mts","sourceRoot":"","sources":["../src/DecryptMessageManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,6BAA6B,EAC9B,kCAAkC;AAGnC,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,mBAAmB,EACnB,eAAe,EACf,uBAAuB,EACxB,qCAAiC;AAClC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAGlE,QAAA,MAAM,WAAW,0BAA0B,CAAC;AAE5C,MAAM,MAAM,0BAA0B,GAAG,mBAAmB,CAAC,cAAc,CAAC,CAAC;AAE7E,MAAM,MAAM,gDAAgD,GAAG;IAC7D,IAAI,EAAE,GAAG,OAAO,WAAW,oBAAoB,CAAC;IAChD,OAAO,EAAE,CAAC,6BAA6B,CAAC,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,qCAAq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nB,aAAa,EAAE,4BAA4B,GAC1C,OAAO,CAAC,oBAAoB,CAAC;CAIjC"}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { ApprovalType } from "@metamask/controller-utils";
|
|
2
2
|
import { AbstractMessageManager } from "./AbstractMessageManager.mjs";
|
|
3
3
|
import { normalizeMessageData, validateDecryptedMessageData } from "./utils.mjs";
|
|
4
|
+
const managerName = 'DecryptMessageManager';
|
|
4
5
|
/**
|
|
5
6
|
* Controller in charge of managing - storing, adding, removing, updating - DecryptMessages.
|
|
6
7
|
*/
|
|
7
8
|
export class DecryptMessageManager extends AbstractMessageManager {
|
|
8
|
-
constructor() {
|
|
9
|
-
super(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
constructor({ additionalFinishStatuses, messenger, securityProviderRequest, state, }) {
|
|
10
|
+
super({
|
|
11
|
+
additionalFinishStatuses,
|
|
12
|
+
messenger,
|
|
13
|
+
name: managerName,
|
|
14
|
+
securityProviderRequest,
|
|
15
|
+
state,
|
|
16
|
+
});
|
|
14
17
|
}
|
|
15
18
|
/**
|
|
16
19
|
* Creates a new Message with an 'unapproved' status using the passed messageParams.
|
|
@@ -24,7 +27,7 @@ export class DecryptMessageManager extends AbstractMessageManager {
|
|
|
24
27
|
validateDecryptedMessageData(messageParams);
|
|
25
28
|
const messageId = await this.addUnapprovedMessage(messageParams, req);
|
|
26
29
|
return new Promise((resolve, reject) => {
|
|
27
|
-
this.
|
|
30
|
+
this.internalEvents.once(`${messageId}:finished`, (data) => {
|
|
28
31
|
switch (data.status) {
|
|
29
32
|
case 'decrypted':
|
|
30
33
|
return resolve(data.rawSig);
|
|
@@ -54,7 +57,7 @@ export class DecryptMessageManager extends AbstractMessageManager {
|
|
|
54
57
|
const messageData = this.createUnapprovedMessage(updatedMessageParams, ApprovalType.EthDecrypt, req);
|
|
55
58
|
const messageId = messageData.id;
|
|
56
59
|
await this.addMessage(messageData);
|
|
57
|
-
this.
|
|
60
|
+
this.messagingSystem.publish(`${managerName}:unapprovedMessage`, {
|
|
58
61
|
...updatedMessageParams,
|
|
59
62
|
metamaskId: messageId,
|
|
60
63
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DecryptMessageManager.mjs","sourceRoot":"","sources":["../src/DecryptMessageManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DecryptMessageManager.mjs","sourceRoot":"","sources":["../src/DecryptMessageManager.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,mCAAmC;AAU1D,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,OAAO,EAAE,oBAAoB,EAAE,4BAA4B,EAAE,oBAAgB;AAE7E,MAAM,WAAW,GAAG,uBAAuB,CAAC;AAyE5C;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,sBAQ1C;IACC,YAAY,EACV,wBAAwB,EACxB,SAAS,EACT,uBAAuB,EACvB,KAAK,GACwB;QAC7B,KAAK,CAAC;YACJ,wBAAwB;YACxB,SAAS;YACT,IAAI,EAAE,WAAW;YACjB,uBAAuB;YACvB,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,yBAAyB,CAC7B,aAAmC,EACnC,GAAqB;QAErB,4BAA4B,CAAC,aAAa,CAAC,CAAC;QAC5C,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;QAEtE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,cAAc,CAAC,IAAI,CACtB,GAAG,SAAS,WAAW,EACvB,CAAC,IAAoB,EAAE,EAAE;gBACvB,QAAQ,IAAI,CAAC,MAAM,EAAE;oBACnB,KAAK,WAAW;wBACd,OAAO,OAAO,CAAC,IAAI,CAAC,MAAgB,CAAC,CAAC;oBACxC,KAAK,UAAU;wBACb,OAAO,MAAM,CACX,IAAI,KAAK,CACP,0DAA0D,CAC3D,CACF,CAAC;oBACJ,KAAK,SAAS;wBACZ,OAAO,MAAM,CACX,IAAI,KAAK,CACP,4DAA4D,CAC7D,CACF,CAAC;oBACJ;wBACE,OAAO,MAAM,CACX,IAAI,KAAK,CACP,6CAA6C,IAAI,CAAC,SAAS,CACzD,aAAa,CACd,EAAE,CACJ,CACF,CAAC;iBACL;YACH,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,oBAAoB,CACxB,aAAmC,EACnC,GAAqB;QAErB,MAAM,oBAAoB,GAAG,IAAI,CAAC,yBAAyB,CACzD,aAAa,EACb,GAAG,CAC2B,CAAC;QACjC,aAAa,CAAC,IAAI,GAAG,oBAAoB,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAE9D,MAAM,WAAW,GAAG,IAAI,CAAC,uBAAuB,CAC9C,oBAAoB,EACpB,YAAY,CAAC,UAAU,EACvB,GAAG,CACqB,CAAC;QAE3B,MAAM,SAAS,GAAG,WAAW,CAAC,EAAE,CAAC;QAEjC,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QACnC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,WAAW,oBAAoB,EAAE;YAC/D,GAAG,oBAAoB;YACvB,UAAU,EAAE,SAAS;SACtB,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;;OAMG;IACH,qBAAqB,CACnB,aAA2C;QAE3C,OAAO,aAAa,CAAC,UAAU,CAAC;QAChC,OAAO,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACxC,CAAC;CACF","sourcesContent":["import type {\n ActionConstraint,\n EventConstraint,\n RestrictedControllerMessenger,\n} from '@metamask/base-controller';\nimport { ApprovalType } from '@metamask/controller-utils';\n\nimport type {\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n MessageManagerState,\n OriginalRequest,\n SecurityProviderRequest,\n} from './AbstractMessageManager';\nimport { AbstractMessageManager } from './AbstractMessageManager';\nimport { normalizeMessageData, validateDecryptedMessageData } from './utils';\n\nconst managerName = 'DecryptMessageManager';\n\nexport type DecryptMessageManagerState = MessageManagerState<DecryptMessage>;\n\nexport type DecryptMessageManagerUnapprovedMessageAddedEvent = {\n type: `${typeof managerName}:unapprovedMessage`;\n payload: [AbstractMessageParamsMetamask];\n};\n\nexport type DecryptMessageManagerUpdateBadgeEvent = {\n type: `${typeof managerName}:updateBadge`;\n payload: [];\n};\n\nexport type DecryptMessageManagerMessenger = RestrictedControllerMessenger<\n string,\n ActionConstraint,\n | EventConstraint\n | DecryptMessageManagerUnapprovedMessageAddedEvent\n | DecryptMessageManagerUpdateBadgeEvent,\n string,\n string\n>;\n\ntype DecryptMessageManagerOptions = {\n messenger: DecryptMessageManagerMessenger;\n securityProviderRequest?: SecurityProviderRequest;\n state?: MessageManagerState<DecryptMessage>;\n additionalFinishStatuses?: string[];\n};\n\n/**\n * @type DecryptMessage\n *\n * Represents and contains data about a 'eth_decrypt' type signature request.\n * These are created when a signature for an eth_decrypt call is requested.\n * @property id - An id to track and identify the message object\n * @property messageParams - The parameters to pass to the eth_decrypt method once the request is approved\n * @property type - The json-prc signing method for which a signature request has been made.\n * A 'DecryptMessage' which always has a 'eth_decrypt' type\n */\nexport type DecryptMessage = AbstractMessage & {\n messageParams: DecryptMessageParams;\n};\n\n/**\n * @type DecryptMessageParams\n *\n * Represents the parameters to pass to the eth_decrypt method once the request is approved.\n * @property data - A hex string conversion of the raw buffer data of the signature request\n */\nexport type DecryptMessageParams = AbstractMessageParams & {\n data: string;\n};\n\n/**\n * @type DecryptMessageParamsMetamask\n *\n * Represents the parameters to pass to the eth_decrypt method once the request is approved\n * plus data added by MetaMask.\n * @property metamaskId - Added for tracking and identification within MetaMask\n * @property data - A hex string conversion of the raw buffer data of the signature request\n * @property from - Address to sign this message from\n * @property origin? - Added for request origin identification\n */\n// This interface was created before this ESLint rule was added.\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface DecryptMessageParamsMetamask\n extends AbstractMessageParamsMetamask {\n data: string;\n}\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - DecryptMessages.\n */\nexport class DecryptMessageManager extends AbstractMessageManager<\n DecryptMessage,\n DecryptMessageParams,\n DecryptMessageParamsMetamask,\n ActionConstraint,\n | EventConstraint\n | DecryptMessageManagerUnapprovedMessageAddedEvent\n | DecryptMessageManagerUpdateBadgeEvent\n> {\n constructor({\n additionalFinishStatuses,\n messenger,\n securityProviderRequest,\n state,\n }: DecryptMessageManagerOptions) {\n super({\n additionalFinishStatuses,\n messenger,\n name: managerName,\n securityProviderRequest,\n state,\n });\n }\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the unapproved Messages.\n *\n * @param messageParams - The params for the personal_sign call to be made after the message is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns Promise resolving to the raw data of the signature request.\n */\n async addUnapprovedMessageAsync(\n messageParams: DecryptMessageParams,\n req?: OriginalRequest,\n ): Promise<string> {\n validateDecryptedMessageData(messageParams);\n const messageId = await this.addUnapprovedMessage(messageParams, req);\n\n return new Promise((resolve, reject) => {\n this.internalEvents.once(\n `${messageId}:finished`,\n (data: DecryptMessage) => {\n switch (data.status) {\n case 'decrypted':\n return resolve(data.rawSig as string);\n case 'rejected':\n return reject(\n new Error(\n 'MetaMask DecryptMessage: User denied message decryption.',\n ),\n );\n case 'errored':\n return reject(\n new Error(\n 'MetaMask DecryptMessage: This message cannot be decrypted.',\n ),\n );\n default:\n return reject(\n new Error(\n `MetaMask DecryptMessage: Unknown problem: ${JSON.stringify(\n messageParams,\n )}`,\n ),\n );\n }\n },\n );\n });\n }\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the\n * unapproved Messages.\n *\n * @param messageParams - The params for the personal_sign call to be made after the message\n * is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns The id of the newly created message.\n */\n async addUnapprovedMessage(\n messageParams: DecryptMessageParams,\n req?: OriginalRequest,\n ) {\n const updatedMessageParams = this.addRequestToMessageParams(\n messageParams,\n req,\n ) satisfies DecryptMessageParams;\n messageParams.data = normalizeMessageData(messageParams.data);\n\n const messageData = this.createUnapprovedMessage(\n updatedMessageParams,\n ApprovalType.EthDecrypt,\n req,\n ) satisfies DecryptMessage;\n\n const messageId = messageData.id;\n\n await this.addMessage(messageData);\n this.messagingSystem.publish(`${managerName}:unapprovedMessage`, {\n ...updatedMessageParams,\n metamaskId: messageId,\n });\n return messageId;\n }\n\n /**\n * Removes the metamaskId property from passed messageParams and returns a promise which\n * resolves the updated messageParams.\n *\n * @param messageParams - The messageParams to modify.\n * @returns Promise resolving to the messageParams with the metamaskId property removed.\n */\n prepMessageForSigning(\n messageParams: DecryptMessageParamsMetamask,\n ): Promise<DecryptMessageParams> {\n delete messageParams.metamaskId;\n return Promise.resolve(messageParams);\n }\n}\n"]}
|
|
@@ -4,16 +4,19 @@ exports.EncryptionPublicKeyManager = void 0;
|
|
|
4
4
|
const controller_utils_1 = require("@metamask/controller-utils");
|
|
5
5
|
const AbstractMessageManager_1 = require("./AbstractMessageManager.cjs");
|
|
6
6
|
const utils_1 = require("./utils.cjs");
|
|
7
|
+
const managerName = 'EncryptionPublicKeyManager';
|
|
7
8
|
/**
|
|
8
9
|
* Controller in charge of managing - storing, adding, removing, updating - Messages.
|
|
9
10
|
*/
|
|
10
11
|
class EncryptionPublicKeyManager extends AbstractMessageManager_1.AbstractMessageManager {
|
|
11
|
-
constructor() {
|
|
12
|
-
super(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
constructor({ additionalFinishStatuses, messenger, securityProviderRequest, state, }) {
|
|
13
|
+
super({
|
|
14
|
+
additionalFinishStatuses,
|
|
15
|
+
messenger,
|
|
16
|
+
name: managerName,
|
|
17
|
+
securityProviderRequest,
|
|
18
|
+
state,
|
|
19
|
+
});
|
|
17
20
|
}
|
|
18
21
|
/**
|
|
19
22
|
* Creates a new Message with an 'unapproved' status using the passed messageParams.
|
|
@@ -27,7 +30,7 @@ class EncryptionPublicKeyManager extends AbstractMessageManager_1.AbstractMessag
|
|
|
27
30
|
(0, utils_1.validateEncryptionPublicKeyMessageData)(messageParams);
|
|
28
31
|
const messageId = await this.addUnapprovedMessage(messageParams, req);
|
|
29
32
|
return new Promise((resolve, reject) => {
|
|
30
|
-
this.
|
|
33
|
+
this.internalEvents.once(`${messageId}:finished`, (data) => {
|
|
31
34
|
switch (data.status) {
|
|
32
35
|
case 'received':
|
|
33
36
|
return resolve(data.rawSig);
|
|
@@ -54,7 +57,7 @@ class EncryptionPublicKeyManager extends AbstractMessageManager_1.AbstractMessag
|
|
|
54
57
|
const messageData = this.createUnapprovedMessage(updatedMessageParams, controller_utils_1.ApprovalType.EthGetEncryptionPublicKey, req);
|
|
55
58
|
const messageId = messageData.id;
|
|
56
59
|
await this.addMessage(messageData);
|
|
57
|
-
this.
|
|
60
|
+
this.messagingSystem.publish(`${this.name}:unapprovedMessage`, {
|
|
58
61
|
...updatedMessageParams,
|
|
59
62
|
metamaskId: messageId,
|
|
60
63
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EncryptionPublicKeyManager.cjs","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"EncryptionPublicKeyManager.cjs","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":";;;AAKA,iEAA0D;AAU1D,yEAAkE;AAClE,uCAAiE;AAEjE,MAAM,WAAW,GAAG,4BAA4B,CAAC;AAuEjD;;GAEG;AACH,MAAa,0BAA2B,SAAQ,+CAQ/C;IACC,YAAY,EACV,wBAAwB,EAC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AI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QACnC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,IAAc,oBAAoB,EAAE;YACvE,GAAG,oBAAoB;YACvB,UAAU,EAAE,SAAS;SACtB,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAgD;QAEhD,OAAO,aAAa,CAAC,UAAU,CAAC;QAChC,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC;IACvD,CAAC;CACF;AAlHD,gEAkHC;AAED,kBAAe,0BAA0B,CAAC","sourcesContent":["import type {\n ActionConstraint,\n EventConstraint,\n RestrictedControllerMessenger,\n} from '@metamask/base-controller';\nimport { ApprovalType } from '@metamask/controller-utils';\n\nimport type {\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n MessageManagerState,\n OriginalRequest,\n SecurityProviderRequest,\n} from './AbstractMessageManager';\nimport { AbstractMessageManager } from './AbstractMessageManager';\nimport { validateEncryptionPublicKeyMessageData } from './utils';\n\nconst managerName = 'EncryptionPublicKeyManager';\n\nexport type EncryptionPublicKeyManagerState =\n MessageManagerState<EncryptionPublicKey>;\n\nexport type EncryptionPublicKeyManagerUnapprovedMessageAddedEvent = {\n type: `${typeof managerName}:unapprovedMessage`;\n payload: [AbstractMessageParamsMetamask];\n};\n\nexport type EncryptionPublicKeyManagerUpdateBadgeEvent = {\n type: `${typeof managerName}:updateBadge`;\n payload: [];\n};\n\nexport type EncryptionPublicKeyManagerMessenger = RestrictedControllerMessenger<\n string,\n ActionConstraint,\n | EventConstraint\n | EncryptionPublicKeyManagerUnapprovedMessageAddedEvent\n | EncryptionPublicKeyManagerUpdateBadgeEvent,\n string,\n string\n>;\n\ntype EncryptionPublicKeyManagerOptions = {\n messenger: EncryptionPublicKeyManagerMessenger;\n securityProviderRequest?: SecurityProviderRequest;\n state?: MessageManagerState<EncryptionPublicKey>;\n additionalFinishStatuses?: string[];\n};\n\n/**\n * @type EncryptionPublicKey\n *\n * Represents and contains data about a 'eth_getEncryptionPublicKey' type request.\n * These are created when an encryption public key is requested.\n * @property id - An id to track and identify the message object\n * @property messageParams - The parameters to pass to the eth_getEncryptionPublicKey method once the request is approved\n * @property type - The json-prc method for which an encryption public key request has been made.\n * A 'Message' which always has a 'eth_getEncryptionPublicKey' type\n * @property rawSig - Encryption public key\n */\nexport type EncryptionPublicKey = AbstractMessage & {\n messageParams: EncryptionPublicKeyParams;\n};\n\n/**\n * @type EncryptionPublicKeyParams\n *\n * Represents the parameters to pass to the method once the request is approved.\n * @property from - Address from which to extract the encryption public key\n * @property origin? - Added for request origin identification\n */\nexport type EncryptionPublicKeyParams = AbstractMessageParams;\n\n/**\n * @type MessageParamsMetamask\n *\n * Represents the parameters to pass to the eth_getEncryptionPublicKey method once the request is approved\n * plus data added by MetaMask.\n * @property metamaskId - Added for tracking and identification within MetaMask\n * @property data - Encryption public key\n * @property from - Address from which to extract the encryption public key\n * @property origin? - Added for request origin identification\n */\nexport type EncryptionPublicKeyParamsMetamask =\n AbstractMessageParamsMetamask & {\n data: string;\n };\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - Messages.\n */\nexport class EncryptionPublicKeyManager extends AbstractMessageManager<\n EncryptionPublicKey,\n EncryptionPublicKeyParams,\n EncryptionPublicKeyParamsMetamask,\n ActionConstraint,\n | EventConstraint\n | EncryptionPublicKeyManagerUnapprovedMessageAddedEvent\n | EncryptionPublicKeyManagerUpdateBadgeEvent\n> {\n constructor({\n additionalFinishStatuses,\n messenger,\n securityProviderRequest,\n state,\n }: EncryptionPublicKeyManagerOptions) {\n super({\n additionalFinishStatuses,\n messenger,\n name: managerName,\n securityProviderRequest,\n state,\n });\n }\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the unapproved Messages.\n *\n * @param messageParams - The params for the eth_getEncryptionPublicKey call to be made after the message is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns Promise resolving to the raw data of the request.\n */\n async addUnapprovedMessageAsync(\n messageParams: EncryptionPublicKeyParams,\n req?: OriginalRequest,\n ): Promise<string> {\n validateEncryptionPublicKeyMessageData(messageParams);\n const messageId = await this.addUnapprovedMessage(messageParams, req);\n\n return new Promise((resolve, reject) => {\n this.internalEvents.once(\n `${messageId}:finished`,\n (data: EncryptionPublicKey) => {\n switch (data.status) {\n case 'received':\n return resolve(data.rawSig as string);\n case 'rejected':\n return reject(\n new Error(\n 'MetaMask EncryptionPublicKey: User denied message EncryptionPublicKey.',\n ),\n );\n default:\n return reject(\n new Error(\n `MetaMask EncryptionPublicKey: Unknown problem: ${JSON.stringify(\n messageParams,\n )}`,\n ),\n );\n }\n },\n );\n });\n }\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the\n * unapproved Messages.\n *\n * @param messageParams - The params for the eth_getEncryptionPublicKey call to be made after the message\n * is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns The id of the newly created message.\n */\n async addUnapprovedMessage(\n messageParams: EncryptionPublicKeyParams,\n req?: OriginalRequest,\n ): Promise<string> {\n const updatedMessageParams = this.addRequestToMessageParams(\n messageParams,\n req,\n ) satisfies EncryptionPublicKeyParams;\n\n const messageData = this.createUnapprovedMessage(\n updatedMessageParams,\n ApprovalType.EthGetEncryptionPublicKey,\n req,\n ) satisfies EncryptionPublicKey;\n\n const messageId = messageData.id;\n\n await this.addMessage(messageData);\n this.messagingSystem.publish(`${this.name as string}:unapprovedMessage`, {\n ...updatedMessageParams,\n metamaskId: messageId,\n });\n return messageId;\n }\n\n /**\n * Removes the metamaskId property from passed messageParams and returns a promise which\n * resolves the updated messageParams.\n *\n * @param messageParams - The messageParams to modify.\n * @returns Promise resolving to the messageParams with the metamaskId property removed.\n */\n prepMessageForSigning(\n messageParams: EncryptionPublicKeyParamsMetamask,\n ): Promise<EncryptionPublicKeyParams> {\n delete messageParams.metamaskId;\n return Promise.resolve({ from: messageParams.data });\n }\n}\n\nexport default EncryptionPublicKeyManager;\n"]}
|
|
@@ -1,5 +1,23 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ActionConstraint, EventConstraint, RestrictedControllerMessenger } from "@metamask/base-controller";
|
|
2
|
+
import type { AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, MessageManagerState, OriginalRequest, SecurityProviderRequest } from "./AbstractMessageManager.cjs";
|
|
2
3
|
import { AbstractMessageManager } from "./AbstractMessageManager.cjs";
|
|
4
|
+
declare const managerName = "EncryptionPublicKeyManager";
|
|
5
|
+
export type EncryptionPublicKeyManagerState = MessageManagerState<EncryptionPublicKey>;
|
|
6
|
+
export type EncryptionPublicKeyManagerUnapprovedMessageAddedEvent = {
|
|
7
|
+
type: `${typeof managerName}:unapprovedMessage`;
|
|
8
|
+
payload: [AbstractMessageParamsMetamask];
|
|
9
|
+
};
|
|
10
|
+
export type EncryptionPublicKeyManagerUpdateBadgeEvent = {
|
|
11
|
+
type: `${typeof managerName}:updateBadge`;
|
|
12
|
+
payload: [];
|
|
13
|
+
};
|
|
14
|
+
export type EncryptionPublicKeyManagerMessenger = RestrictedControllerMessenger<string, ActionConstraint, EventConstraint | EncryptionPublicKeyManagerUnapprovedMessageAddedEvent | EncryptionPublicKeyManagerUpdateBadgeEvent, string, string>;
|
|
15
|
+
type EncryptionPublicKeyManagerOptions = {
|
|
16
|
+
messenger: EncryptionPublicKeyManagerMessenger;
|
|
17
|
+
securityProviderRequest?: SecurityProviderRequest;
|
|
18
|
+
state?: MessageManagerState<EncryptionPublicKey>;
|
|
19
|
+
additionalFinishStatuses?: string[];
|
|
20
|
+
};
|
|
3
21
|
/**
|
|
4
22
|
* @type EncryptionPublicKey
|
|
5
23
|
*
|
|
@@ -11,9 +29,9 @@ import { AbstractMessageManager } from "./AbstractMessageManager.cjs";
|
|
|
11
29
|
* A 'Message' which always has a 'eth_getEncryptionPublicKey' type
|
|
12
30
|
* @property rawSig - Encryption public key
|
|
13
31
|
*/
|
|
14
|
-
export
|
|
32
|
+
export type EncryptionPublicKey = AbstractMessage & {
|
|
15
33
|
messageParams: EncryptionPublicKeyParams;
|
|
16
|
-
}
|
|
34
|
+
};
|
|
17
35
|
/**
|
|
18
36
|
* @type EncryptionPublicKeyParams
|
|
19
37
|
*
|
|
@@ -32,17 +50,14 @@ export type EncryptionPublicKeyParams = AbstractMessageParams;
|
|
|
32
50
|
* @property from - Address from which to extract the encryption public key
|
|
33
51
|
* @property origin? - Added for request origin identification
|
|
34
52
|
*/
|
|
35
|
-
export
|
|
53
|
+
export type EncryptionPublicKeyParamsMetamask = AbstractMessageParamsMetamask & {
|
|
36
54
|
data: string;
|
|
37
|
-
}
|
|
55
|
+
};
|
|
38
56
|
/**
|
|
39
57
|
* Controller in charge of managing - storing, adding, removing, updating - Messages.
|
|
40
58
|
*/
|
|
41
|
-
export declare class EncryptionPublicKeyManager extends AbstractMessageManager<EncryptionPublicKey, EncryptionPublicKeyParams, EncryptionPublicKeyParamsMetamask> {
|
|
42
|
-
|
|
43
|
-
* Name of this controller used during composition
|
|
44
|
-
*/
|
|
45
|
-
name: "EncryptionPublicKeyManager";
|
|
59
|
+
export declare class EncryptionPublicKeyManager extends AbstractMessageManager<EncryptionPublicKey, EncryptionPublicKeyParams, EncryptionPublicKeyParamsMetamask, ActionConstraint, EventConstraint | EncryptionPublicKeyManagerUnapprovedMessageAddedEvent | EncryptionPublicKeyManagerUpdateBadgeEvent> {
|
|
60
|
+
constructor({ additionalFinishStatuses, messenger, securityProviderRequest, state, }: EncryptionPublicKeyManagerOptions);
|
|
46
61
|
/**
|
|
47
62
|
* Creates a new Message with an 'unapproved' status using the passed messageParams.
|
|
48
63
|
* this.addMessage is called to add the new Message to this.messages, and to save the unapproved Messages.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EncryptionPublicKeyManager.d.cts","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EncryptionPublicKeyManager.d.cts","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,6BAA6B,EAC9B,kCAAkC;AAGnC,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,mBAAmB,EACnB,eAAe,EACf,uBAAuB,EACxB,qCAAiC;AAClC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAGlE,QAAA,MAAM,WAAW,+BAA+B,CAAC;AAEjD,MAAM,MAAM,+BAA+B,GACzC,mBAAmB,CAAC,mBAAmB,CAAC,CAAC;AAE3C,MAAM,MAAM,qDAAqD,GAAG;IAClE,IAAI,EAAE,GAAG,OAAO,WAAW,oBAAoB,CAAC;IAChD,OAAO,EAAE,CAAC,6BAA6B,CAAC,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,0CAA0C,GAAG;IACvD,IAAI,EAAE,GAAG,OAAO,WAAW,cAAc,CAAC;IAC1C,OAAO,EAAE,EAAE,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,mCAAmC,GAAG,6BAA6B,CAC7E,MAAM,EACN,gBAAgB,EACd,eAAe,GACf,qDAAqD,GACrD,0CAA0C,EAC5C,MAAM,EACN,MAAM,CACP,CAAC;AAEF,KAAK,iCAAiC,GAAG;IACvC,SAAS,EAAE,mCAAmC,CAAC;IAC/C,uBAAuB,CAAC,EAAE,uBAAuB,CAAC;IAClD,KAAK,CAAC,EAAE,mBAAmB,CAAC,mBAAmB,CAAC,CAAC;IACjD,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAC;CACrC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,MAAM,mBAAmB,GAAG,eAAe,GAAG;IAClD,aAAa,EAAE,yBAAyB,CAAC;CAC1C,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,yBAAyB,GAAG,qBAAqB,CAAC;AAE9D;;;;;;;;;GASG;AACH,MAAM,MAAM,iCAAiC,GAC3C,6BAA6B,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEJ;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,sBAAsB,CACpE,mBAAmB,EACnB,yBAAyB,EACzB,iCAAiC,EACjC,gBAAgB,EACd,eAAe,GACf,qDAAqD,GACrD,0CAA0C,CAC7C;gBACa,EACV,wBAAwB,EACxB,SAAS,EACT,uBAAuB,EACvB,KAAK,GACN,EAAE,iCAAiC;IAUpC;;;;;;;OAOG;IACG,yBAAyB,CAC7B,aAAa,EAAE,yBAAyB,EACxC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IA+BlB;;;;;;;;;OASG;IACG,oBAAoB,CACxB,aAAa,EAAE,yBAAyB,EACxC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IAsBlB;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAa,EAAE,iCAAiC,GAC/C,OAAO,CAAC,yBAAyB,CAAC;CAItC;AAED,eAAe,0BAA0B,CAAC"}
|
|
@@ -1,5 +1,23 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ActionConstraint, EventConstraint, RestrictedControllerMessenger } from "@metamask/base-controller";
|
|
2
|
+
import type { AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, MessageManagerState, OriginalRequest, SecurityProviderRequest } from "./AbstractMessageManager.mjs";
|
|
2
3
|
import { AbstractMessageManager } from "./AbstractMessageManager.mjs";
|
|
4
|
+
declare const managerName = "EncryptionPublicKeyManager";
|
|
5
|
+
export type EncryptionPublicKeyManagerState = MessageManagerState<EncryptionPublicKey>;
|
|
6
|
+
export type EncryptionPublicKeyManagerUnapprovedMessageAddedEvent = {
|
|
7
|
+
type: `${typeof managerName}:unapprovedMessage`;
|
|
8
|
+
payload: [AbstractMessageParamsMetamask];
|
|
9
|
+
};
|
|
10
|
+
export type EncryptionPublicKeyManagerUpdateBadgeEvent = {
|
|
11
|
+
type: `${typeof managerName}:updateBadge`;
|
|
12
|
+
payload: [];
|
|
13
|
+
};
|
|
14
|
+
export type EncryptionPublicKeyManagerMessenger = RestrictedControllerMessenger<string, ActionConstraint, EventConstraint | EncryptionPublicKeyManagerUnapprovedMessageAddedEvent | EncryptionPublicKeyManagerUpdateBadgeEvent, string, string>;
|
|
15
|
+
type EncryptionPublicKeyManagerOptions = {
|
|
16
|
+
messenger: EncryptionPublicKeyManagerMessenger;
|
|
17
|
+
securityProviderRequest?: SecurityProviderRequest;
|
|
18
|
+
state?: MessageManagerState<EncryptionPublicKey>;
|
|
19
|
+
additionalFinishStatuses?: string[];
|
|
20
|
+
};
|
|
3
21
|
/**
|
|
4
22
|
* @type EncryptionPublicKey
|
|
5
23
|
*
|
|
@@ -11,9 +29,9 @@ import { AbstractMessageManager } from "./AbstractMessageManager.mjs";
|
|
|
11
29
|
* A 'Message' which always has a 'eth_getEncryptionPublicKey' type
|
|
12
30
|
* @property rawSig - Encryption public key
|
|
13
31
|
*/
|
|
14
|
-
export
|
|
32
|
+
export type EncryptionPublicKey = AbstractMessage & {
|
|
15
33
|
messageParams: EncryptionPublicKeyParams;
|
|
16
|
-
}
|
|
34
|
+
};
|
|
17
35
|
/**
|
|
18
36
|
* @type EncryptionPublicKeyParams
|
|
19
37
|
*
|
|
@@ -32,17 +50,14 @@ export type EncryptionPublicKeyParams = AbstractMessageParams;
|
|
|
32
50
|
* @property from - Address from which to extract the encryption public key
|
|
33
51
|
* @property origin? - Added for request origin identification
|
|
34
52
|
*/
|
|
35
|
-
export
|
|
53
|
+
export type EncryptionPublicKeyParamsMetamask = AbstractMessageParamsMetamask & {
|
|
36
54
|
data: string;
|
|
37
|
-
}
|
|
55
|
+
};
|
|
38
56
|
/**
|
|
39
57
|
* Controller in charge of managing - storing, adding, removing, updating - Messages.
|
|
40
58
|
*/
|
|
41
|
-
export declare class EncryptionPublicKeyManager extends AbstractMessageManager<EncryptionPublicKey, EncryptionPublicKeyParams, EncryptionPublicKeyParamsMetamask> {
|
|
42
|
-
|
|
43
|
-
* Name of this controller used during composition
|
|
44
|
-
*/
|
|
45
|
-
name: "EncryptionPublicKeyManager";
|
|
59
|
+
export declare class EncryptionPublicKeyManager extends AbstractMessageManager<EncryptionPublicKey, EncryptionPublicKeyParams, EncryptionPublicKeyParamsMetamask, ActionConstraint, EventConstraint | EncryptionPublicKeyManagerUnapprovedMessageAddedEvent | EncryptionPublicKeyManagerUpdateBadgeEvent> {
|
|
60
|
+
constructor({ additionalFinishStatuses, messenger, securityProviderRequest, state, }: EncryptionPublicKeyManagerOptions);
|
|
46
61
|
/**
|
|
47
62
|
* Creates a new Message with an 'unapproved' status using the passed messageParams.
|
|
48
63
|
* this.addMessage is called to add the new Message to this.messages, and to save the unapproved Messages.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EncryptionPublicKeyManager.d.mts","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EncryptionPublicKeyManager.d.mts","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,6BAA6B,EAC9B,kCAAkC;AAGnC,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,mBAAmB,EACnB,eAAe,EACf,uBAAuB,EACxB,qCAAiC;AAClC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAGlE,QAAA,MAAM,WAAW,+BAA+B,CAAC;AAEjD,MAAM,MAAM,+BAA+B,GACzC,mBAAmB,CAAC,mBAAmB,CAAC,CAAC;AAE3C,MAAM,MAAM,qDAAqD,GAAG;IAClE,IAAI,EAAE,GAAG,OAAO,WAAW,oBAAoB,C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E,yBAAyB,EACxC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IAsBlB;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAa,EAAE,iCAAiC,GAC/C,OAAO,CAAC,yBAAyB,CAAC;CAItC;AAED,eAAe,0BAA0B,CAAC"}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { ApprovalType } from "@metamask/controller-utils";
|
|
2
2
|
import { AbstractMessageManager } from "./AbstractMessageManager.mjs";
|
|
3
3
|
import { validateEncryptionPublicKeyMessageData } from "./utils.mjs";
|
|
4
|
+
const managerName = 'EncryptionPublicKeyManager';
|
|
4
5
|
/**
|
|
5
6
|
* Controller in charge of managing - storing, adding, removing, updating - Messages.
|
|
6
7
|
*/
|
|
7
8
|
export class EncryptionPublicKeyManager extends AbstractMessageManager {
|
|
8
|
-
constructor() {
|
|
9
|
-
super(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
constructor({ additionalFinishStatuses, messenger, securityProviderRequest, state, }) {
|
|
10
|
+
super({
|
|
11
|
+
additionalFinishStatuses,
|
|
12
|
+
messenger,
|
|
13
|
+
name: managerName,
|
|
14
|
+
securityProviderRequest,
|
|
15
|
+
state,
|
|
16
|
+
});
|
|
14
17
|
}
|
|
15
18
|
/**
|
|
16
19
|
* Creates a new Message with an 'unapproved' status using the passed messageParams.
|
|
@@ -24,7 +27,7 @@ export class EncryptionPublicKeyManager extends AbstractMessageManager {
|
|
|
24
27
|
validateEncryptionPublicKeyMessageData(messageParams);
|
|
25
28
|
const messageId = await this.addUnapprovedMessage(messageParams, req);
|
|
26
29
|
return new Promise((resolve, reject) => {
|
|
27
|
-
this.
|
|
30
|
+
this.internalEvents.once(`${messageId}:finished`, (data) => {
|
|
28
31
|
switch (data.status) {
|
|
29
32
|
case 'received':
|
|
30
33
|
return resolve(data.rawSig);
|
|
@@ -51,7 +54,7 @@ export class EncryptionPublicKeyManager extends AbstractMessageManager {
|
|
|
51
54
|
const messageData = this.createUnapprovedMessage(updatedMessageParams, ApprovalType.EthGetEncryptionPublicKey, req);
|
|
52
55
|
const messageId = messageData.id;
|
|
53
56
|
await this.addMessage(messageData);
|
|
54
|
-
this.
|
|
57
|
+
this.messagingSystem.publish(`${this.name}:unapprovedMessage`, {
|
|
55
58
|
...updatedMessageParams,
|
|
56
59
|
metamaskId: messageId,
|
|
57
60
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EncryptionPublicKeyManager.mjs","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EncryptionPublicKeyManager.mjs","sourceRoot":"","sources":["../src/EncryptionPublicKeyManager.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,mCAAmC;AAU1D,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,OAAO,EAAE,sCAAsC,EAAE,oBAAgB;AAEjE,MAAM,WAAW,GAAG,4BAA4B,CAAC;AAuEjD;;GAEG;AACH,MAAM,OAAO,0BAA2B,SAAQ,sBAQ/C;IACC,YAAY,EACV,wBAAwB,EACxB,SAAS,EACT,uBAAuB,EACvB,KAAK,GAC6B;QAClC,KAAK,CAAC;YACJ,wBAAwB;YACxB,SAAS;YACT,IAAI,EAAE,WAAW;YACjB,uBAAuB;YACvB,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,yBAAyB,CAC7B,aAAwC,EACxC,GAAqB;QAErB,sCAAsC,CAAC,aAAa,CAAC,CAAC;QACtD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;QAEtE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,cAAc,CAAC,IAAI,CACtB,GAAG,SAAS,WAAW,EACvB,CAAC,IAAyB,EAAE,EAAE;gBAC5B,QAAQ,IAAI,CAAC,MAAM,EAAE;oBACnB,KAAK,UAAU;wBACb,OAAO,OAAO,CAAC,IAAI,CAAC,MAAgB,CAAC,CAAC;oBACxC,KAAK,UAAU;wBACb,OAAO,MAAM,CACX,IAAI,KAAK,CACP,wEAAwE,CACzE,CACF,CAAC;oBACJ;wBACE,OAAO,MAAM,CACX,IAAI,KAAK,CACP,kDAAkD,IAAI,CAAC,SAAS,CAC9D,aAAa,CACd,EAAE,CACJ,CACF,CAAC;iBACL;YACH,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,oBAAoB,CACxB,aAAwC,EACxC,GAAqB;QAErB,MAAM,oBAAoB,GAAG,IAAI,CAAC,yBAAyB,CACzD,aAAa,EACb,GAAG,CACgC,CAAC;QAEtC,MAAM,WAAW,GAAG,IAAI,CAAC,uBAAuB,CAC9C,oBAAoB,EACpB,YAAY,CAAC,yBAAyB,EACtC,GAAG,CAC0B,CAAC;QAEhC,MAAM,SAAS,GAAG,WAAW,CAAC,EAAE,CAAC;QAEjC,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QACnC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,IAAc,oBAAoB,EAAE;YACvE,GAAG,oBAAoB;YACvB,UAAU,EAAE,SAAS;SACtB,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;;OAMG;IACH,qBAAqB,CACnB,aAAgD;QAEhD,OAAO,aAAa,CAAC,UAAU,CAAC;QAChC,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC;IACvD,CAAC;CACF;AAED,eAAe,0BAA0B,CAAC","sourcesContent":["import type {\n ActionConstraint,\n EventConstraint,\n RestrictedControllerMessenger,\n} from '@metamask/base-controller';\nimport { ApprovalType } from '@metamask/controller-utils';\n\nimport type {\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n MessageManagerState,\n OriginalRequest,\n SecurityProviderRequest,\n} from './AbstractMessageManager';\nimport { AbstractMessageManager } from './AbstractMessageManager';\nimport { validateEncryptionPublicKeyMessageData } from './utils';\n\nconst managerName = 'EncryptionPublicKeyManager';\n\nexport type EncryptionPublicKeyManagerState =\n MessageManagerState<EncryptionPublicKey>;\n\nexport type EncryptionPublicKeyManagerUnapprovedMessageAddedEvent = {\n type: `${typeof managerName}:unapprovedMessage`;\n payload: [AbstractMessageParamsMetamask];\n};\n\nexport type EncryptionPublicKeyManagerUpdateBadgeEvent = {\n type: `${typeof managerName}:updateBadge`;\n payload: [];\n};\n\nexport type EncryptionPublicKeyManagerMessenger = RestrictedControllerMessenger<\n string,\n ActionConstraint,\n | EventConstraint\n | EncryptionPublicKeyManagerUnapprovedMessageAddedEvent\n | EncryptionPublicKeyManagerUpdateBadgeEvent,\n string,\n string\n>;\n\ntype EncryptionPublicKeyManagerOptions = {\n messenger: EncryptionPublicKeyManagerMessenger;\n securityProviderRequest?: SecurityProviderRequest;\n state?: MessageManagerState<EncryptionPublicKey>;\n additionalFinishStatuses?: string[];\n};\n\n/**\n * @type EncryptionPublicKey\n *\n * Represents and contains data about a 'eth_getEncryptionPublicKey' type request.\n * These are created when an encryption public key is requested.\n * @property id - An id to track and identify the message object\n * @property messageParams - The parameters to pass to the eth_getEncryptionPublicKey method once the request is approved\n * @property type - The json-prc method for which an encryption public key request has been made.\n * A 'Message' which always has a 'eth_getEncryptionPublicKey' type\n * @property rawSig - Encryption public key\n */\nexport type EncryptionPublicKey = AbstractMessage & {\n messageParams: EncryptionPublicKeyParams;\n};\n\n/**\n * @type EncryptionPublicKeyParams\n *\n * Represents the parameters to pass to the method once the request is approved.\n * @property from - Address from which to extract the encryption public key\n * @property origin? - Added for request origin identification\n */\nexport type EncryptionPublicKeyParams = AbstractMessageParams;\n\n/**\n * @type MessageParamsMetamask\n *\n * Represents the parameters to pass to the eth_getEncryptionPublicKey method once the request is approved\n * plus data added by MetaMask.\n * @property metamaskId - Added for tracking and identification within MetaMask\n * @property data - Encryption public key\n * @property from - Address from which to extract the encryption public key\n * @property origin? - Added for request origin identification\n */\nexport type EncryptionPublicKeyParamsMetamask =\n AbstractMessageParamsMetamask & {\n data: string;\n };\n\n/**\n * Controller in charge of managing - storing, adding, removing, updating - Messages.\n */\nexport class EncryptionPublicKeyManager extends AbstractMessageManager<\n EncryptionPublicKey,\n EncryptionPublicKeyParams,\n EncryptionPublicKeyParamsMetamask,\n ActionConstraint,\n | EventConstraint\n | EncryptionPublicKeyManagerUnapprovedMessageAddedEvent\n | EncryptionPublicKeyManagerUpdateBadgeEvent\n> {\n constructor({\n additionalFinishStatuses,\n messenger,\n securityProviderRequest,\n state,\n }: EncryptionPublicKeyManagerOptions) {\n super({\n additionalFinishStatuses,\n messenger,\n name: managerName,\n securityProviderRequest,\n state,\n });\n }\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the unapproved Messages.\n *\n * @param messageParams - The params for the eth_getEncryptionPublicKey call to be made after the message is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns Promise resolving to the raw data of the request.\n */\n async addUnapprovedMessageAsync(\n messageParams: EncryptionPublicKeyParams,\n req?: OriginalRequest,\n ): Promise<string> {\n validateEncryptionPublicKeyMessageData(messageParams);\n const messageId = await this.addUnapprovedMessage(messageParams, req);\n\n return new Promise((resolve, reject) => {\n this.internalEvents.once(\n `${messageId}:finished`,\n (data: EncryptionPublicKey) => {\n switch (data.status) {\n case 'received':\n return resolve(data.rawSig as string);\n case 'rejected':\n return reject(\n new Error(\n 'MetaMask EncryptionPublicKey: User denied message EncryptionPublicKey.',\n ),\n );\n default:\n return reject(\n new Error(\n `MetaMask EncryptionPublicKey: Unknown problem: ${JSON.stringify(\n messageParams,\n )}`,\n ),\n );\n }\n },\n );\n });\n }\n\n /**\n * Creates a new Message with an 'unapproved' status using the passed messageParams.\n * this.addMessage is called to add the new Message to this.messages, and to save the\n * unapproved Messages.\n *\n * @param messageParams - The params for the eth_getEncryptionPublicKey call to be made after the message\n * is approved.\n * @param req - The original request object possibly containing the origin.\n * @returns The id of the newly created message.\n */\n async addUnapprovedMessage(\n messageParams: EncryptionPublicKeyParams,\n req?: OriginalRequest,\n ): Promise<string> {\n const updatedMessageParams = this.addRequestToMessageParams(\n messageParams,\n req,\n ) satisfies EncryptionPublicKeyParams;\n\n const messageData = this.createUnapprovedMessage(\n updatedMessageParams,\n ApprovalType.EthGetEncryptionPublicKey,\n req,\n ) satisfies EncryptionPublicKey;\n\n const messageId = messageData.id;\n\n await this.addMessage(messageData);\n this.messagingSystem.publish(`${this.name as string}:unapprovedMessage`, {\n ...updatedMessageParams,\n metamaskId: messageId,\n });\n return messageId;\n }\n\n /**\n * Removes the metamaskId property from passed messageParams and returns a promise which\n * resolves the updated messageParams.\n *\n * @param messageParams - The messageParams to modify.\n * @returns Promise resolving to the messageParams with the metamaskId property removed.\n */\n prepMessageForSigning(\n messageParams: EncryptionPublicKeyParamsMetamask,\n ): Promise<EncryptionPublicKeyParams> {\n delete messageParams.metamaskId;\n return Promise.resolve({ from: messageParams.data });\n }\n}\n\nexport default EncryptionPublicKeyManager;\n"]}
|