@metamask-previews/message-manager 11.0.3-preview-e5e6db48 → 11.0.3-preview-e96ca40c
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 +0 -8
- package/dist/AbstractMessageManager.cjs +48 -53
- package/dist/AbstractMessageManager.cjs.map +1 -1
- package/dist/AbstractMessageManager.d.cts +49 -48
- package/dist/AbstractMessageManager.d.cts.map +1 -1
- package/dist/AbstractMessageManager.d.mts +49 -48
- package/dist/AbstractMessageManager.d.mts.map +1 -1
- package/dist/AbstractMessageManager.mjs +49 -54
- package/dist/AbstractMessageManager.mjs.map +1 -1
- package/dist/DecryptMessageManager.cjs +8 -11
- package/dist/DecryptMessageManager.cjs.map +1 -1
- package/dist/DecryptMessageManager.d.cts +10 -22
- package/dist/DecryptMessageManager.d.cts.map +1 -1
- package/dist/DecryptMessageManager.d.mts +10 -22
- package/dist/DecryptMessageManager.d.mts.map +1 -1
- package/dist/DecryptMessageManager.mjs +8 -11
- package/dist/DecryptMessageManager.mjs.map +1 -1
- package/dist/EncryptionPublicKeyManager.cjs +8 -11
- package/dist/EncryptionPublicKeyManager.cjs.map +1 -1
- package/dist/EncryptionPublicKeyManager.d.cts +10 -21
- package/dist/EncryptionPublicKeyManager.d.cts.map +1 -1
- package/dist/EncryptionPublicKeyManager.d.mts +10 -21
- package/dist/EncryptionPublicKeyManager.d.mts.map +1 -1
- package/dist/EncryptionPublicKeyManager.mjs +8 -11
- package/dist/EncryptionPublicKeyManager.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -1,19 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, MessageManagerState, OriginalRequest, SecurityProviderRequest } from "./AbstractMessageManager.cjs";
|
|
1
|
+
import type { AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, OriginalRequest } from "./AbstractMessageManager.cjs";
|
|
3
2
|
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 DecryptMessageManagerMessenger = RestrictedControllerMessenger<string, ActionConstraint, EventConstraint | DecryptMessageManagerUnapprovedMessageAddedEvent, string, string>;
|
|
11
|
-
type DecryptMessageManagerOptions = {
|
|
12
|
-
messenger: DecryptMessageManagerMessenger;
|
|
13
|
-
securityProviderRequest?: SecurityProviderRequest;
|
|
14
|
-
state?: MessageManagerState<DecryptMessage>;
|
|
15
|
-
additionalFinishStatuses?: string[];
|
|
16
|
-
};
|
|
17
3
|
/**
|
|
18
4
|
* @type DecryptMessage
|
|
19
5
|
*
|
|
@@ -24,18 +10,18 @@ type DecryptMessageManagerOptions = {
|
|
|
24
10
|
* @property type - The json-prc signing method for which a signature request has been made.
|
|
25
11
|
* A 'DecryptMessage' which always has a 'eth_decrypt' type
|
|
26
12
|
*/
|
|
27
|
-
export
|
|
13
|
+
export interface DecryptMessage extends AbstractMessage {
|
|
28
14
|
messageParams: DecryptMessageParams;
|
|
29
|
-
}
|
|
15
|
+
}
|
|
30
16
|
/**
|
|
31
17
|
* @type DecryptMessageParams
|
|
32
18
|
*
|
|
33
19
|
* Represents the parameters to pass to the eth_decrypt method once the request is approved.
|
|
34
20
|
* @property data - A hex string conversion of the raw buffer data of the signature request
|
|
35
21
|
*/
|
|
36
|
-
export
|
|
22
|
+
export interface DecryptMessageParams extends AbstractMessageParams {
|
|
37
23
|
data: string;
|
|
38
|
-
}
|
|
24
|
+
}
|
|
39
25
|
/**
|
|
40
26
|
* @type DecryptMessageParamsMetamask
|
|
41
27
|
*
|
|
@@ -52,8 +38,11 @@ export interface DecryptMessageParamsMetamask extends AbstractMessageParamsMetam
|
|
|
52
38
|
/**
|
|
53
39
|
* Controller in charge of managing - storing, adding, removing, updating - DecryptMessages.
|
|
54
40
|
*/
|
|
55
|
-
export declare class DecryptMessageManager extends AbstractMessageManager<DecryptMessage, DecryptMessageParams, DecryptMessageParamsMetamask
|
|
56
|
-
|
|
41
|
+
export declare class DecryptMessageManager extends AbstractMessageManager<DecryptMessage, DecryptMessageParams, DecryptMessageParamsMetamask> {
|
|
42
|
+
/**
|
|
43
|
+
* Name of this controller used during composition
|
|
44
|
+
*/
|
|
45
|
+
name: "DecryptMessageManager";
|
|
57
46
|
/**
|
|
58
47
|
* Creates a new Message with an 'unapproved' status using the passed messageParams.
|
|
59
48
|
* this.addMessage is called to add the new Message to this.messages, and to save the unapproved Messages.
|
|
@@ -83,5 +72,4 @@ export declare class DecryptMessageManager extends AbstractMessageManager<Decryp
|
|
|
83
72
|
*/
|
|
84
73
|
prepMessageForSigning(messageParams: DecryptMessageParamsMetamask): Promise<DecryptMessageParams>;
|
|
85
74
|
}
|
|
86
|
-
export {};
|
|
87
75
|
//# 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":"AAEA,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,eAAe,EAChB,qCAAiC;AAClC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAGlE;;;;;;;;;GASG;AAIH,MAAM,WAAW,cAAe,SAAQ,eAAe;IACrD,aAAa,EAAE,oBAAoB,CAAC;CACrC;AAED;;;;;GAKG;AAIH,MAAM,WAAW,oBAAqB,SAAQ,qBAAqB;IACjE,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;GASG;AAIH,MAAM,WAAW,4BACf,SAAQ,6BAA6B;IACrC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,sBAAsB,CAC/D,cAAc,EACd,oBAAoB,EACpB,4BAA4B,CAC7B;IACC;;OAEG;IACM,IAAI,0BAAoC;IAEjD;;;;;;;OAOG;IACG,yBAAyB,CAC7B,aAAa,EAAE,oBAAoB,EACnC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IAkClB;;;;;;;;;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,19 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, MessageManagerState, OriginalRequest, SecurityProviderRequest } from "./AbstractMessageManager.mjs";
|
|
1
|
+
import type { AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, OriginalRequest } from "./AbstractMessageManager.mjs";
|
|
3
2
|
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 DecryptMessageManagerMessenger = RestrictedControllerMessenger<string, ActionConstraint, EventConstraint | DecryptMessageManagerUnapprovedMessageAddedEvent, string, string>;
|
|
11
|
-
type DecryptMessageManagerOptions = {
|
|
12
|
-
messenger: DecryptMessageManagerMessenger;
|
|
13
|
-
securityProviderRequest?: SecurityProviderRequest;
|
|
14
|
-
state?: MessageManagerState<DecryptMessage>;
|
|
15
|
-
additionalFinishStatuses?: string[];
|
|
16
|
-
};
|
|
17
3
|
/**
|
|
18
4
|
* @type DecryptMessage
|
|
19
5
|
*
|
|
@@ -24,18 +10,18 @@ type DecryptMessageManagerOptions = {
|
|
|
24
10
|
* @property type - The json-prc signing method for which a signature request has been made.
|
|
25
11
|
* A 'DecryptMessage' which always has a 'eth_decrypt' type
|
|
26
12
|
*/
|
|
27
|
-
export
|
|
13
|
+
export interface DecryptMessage extends AbstractMessage {
|
|
28
14
|
messageParams: DecryptMessageParams;
|
|
29
|
-
}
|
|
15
|
+
}
|
|
30
16
|
/**
|
|
31
17
|
* @type DecryptMessageParams
|
|
32
18
|
*
|
|
33
19
|
* Represents the parameters to pass to the eth_decrypt method once the request is approved.
|
|
34
20
|
* @property data - A hex string conversion of the raw buffer data of the signature request
|
|
35
21
|
*/
|
|
36
|
-
export
|
|
22
|
+
export interface DecryptMessageParams extends AbstractMessageParams {
|
|
37
23
|
data: string;
|
|
38
|
-
}
|
|
24
|
+
}
|
|
39
25
|
/**
|
|
40
26
|
* @type DecryptMessageParamsMetamask
|
|
41
27
|
*
|
|
@@ -52,8 +38,11 @@ export interface DecryptMessageParamsMetamask extends AbstractMessageParamsMetam
|
|
|
52
38
|
/**
|
|
53
39
|
* Controller in charge of managing - storing, adding, removing, updating - DecryptMessages.
|
|
54
40
|
*/
|
|
55
|
-
export declare class DecryptMessageManager extends AbstractMessageManager<DecryptMessage, DecryptMessageParams, DecryptMessageParamsMetamask
|
|
56
|
-
|
|
41
|
+
export declare class DecryptMessageManager extends AbstractMessageManager<DecryptMessage, DecryptMessageParams, DecryptMessageParamsMetamask> {
|
|
42
|
+
/**
|
|
43
|
+
* Name of this controller used during composition
|
|
44
|
+
*/
|
|
45
|
+
name: "DecryptMessageManager";
|
|
57
46
|
/**
|
|
58
47
|
* Creates a new Message with an 'unapproved' status using the passed messageParams.
|
|
59
48
|
* this.addMessage is called to add the new Message to this.messages, and to save the unapproved Messages.
|
|
@@ -83,5 +72,4 @@ export declare class DecryptMessageManager extends AbstractMessageManager<Decryp
|
|
|
83
72
|
*/
|
|
84
73
|
prepMessageForSigning(messageParams: DecryptMessageParamsMetamask): Promise<DecryptMessageParams>;
|
|
85
74
|
}
|
|
86
|
-
export {};
|
|
87
75
|
//# 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":"AAEA,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,eAAe,EAChB,qCAAiC;AAClC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAGlE;;;;;;;;;GASG;AAIH,MAAM,WAAW,cAAe,SAAQ,eAAe;IACrD,aAAa,EAAE,oBAAoB,CAAC;CACrC;AAED;;;;;GAKG;AAIH,MAAM,WAAW,oBAAqB,SAAQ,qBAAqB;IACjE,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;GASG;AAIH,MAAM,WAAW,4BACf,SAAQ,6BAA6B;IACrC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,sBAAsB,CAC/D,cAAc,EACd,oBAAoB,EACpB,4BAA4B,CAC7B;IACC;;OAEG;IACM,IAAI,0BAAoC;IAEjD;;;;;;;OAOG;IACG,yBAAyB,CAC7B,aAAa,EAAE,oBAAoB,EACnC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IAkClB;;;;;;;;;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,19 +1,16 @@
|
|
|
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';
|
|
5
4
|
/**
|
|
6
5
|
* Controller in charge of managing - storing, adding, removing, updating - DecryptMessages.
|
|
7
6
|
*/
|
|
8
7
|
export class DecryptMessageManager extends AbstractMessageManager {
|
|
9
|
-
constructor(
|
|
10
|
-
super(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
state,
|
|
16
|
-
});
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
/**
|
|
11
|
+
* Name of this controller used during composition
|
|
12
|
+
*/
|
|
13
|
+
this.name = 'DecryptMessageManager';
|
|
17
14
|
}
|
|
18
15
|
/**
|
|
19
16
|
* Creates a new Message with an 'unapproved' status using the passed messageParams.
|
|
@@ -27,7 +24,7 @@ export class DecryptMessageManager extends AbstractMessageManager {
|
|
|
27
24
|
validateDecryptedMessageData(messageParams);
|
|
28
25
|
const messageId = await this.addUnapprovedMessage(messageParams, req);
|
|
29
26
|
return new Promise((resolve, reject) => {
|
|
30
|
-
this.
|
|
27
|
+
this.hub.once(`${messageId}:finished`, (data) => {
|
|
31
28
|
switch (data.status) {
|
|
32
29
|
case 'decrypted':
|
|
33
30
|
return resolve(data.rawSig);
|
|
@@ -57,7 +54,7 @@ export class DecryptMessageManager extends AbstractMessageManager {
|
|
|
57
54
|
const messageData = this.createUnapprovedMessage(updatedMessageParams, ApprovalType.EthDecrypt, req);
|
|
58
55
|
const messageId = messageData.id;
|
|
59
56
|
await this.addMessage(messageData);
|
|
60
|
-
this.
|
|
57
|
+
this.hub.emit(`unapprovedMessage`, {
|
|
61
58
|
...updatedMessageParams,
|
|
62
59
|
metamaskId: messageId,
|
|
63
60
|
});
|
|
@@ -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":"AAAA,OAAO,EAAE,YAAY,EAAE,mCAAmC;AAQ1D,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,OAAO,EAAE,oBAAoB,EAAE,4BAA4B,EAAE,oBAAgB;AAkD7E;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,sBAI1C;IAJD;;QAKE;;WAEG;QACM,SAAI,GAAG,uBAAgC,CAAC;IAgGnD,CAAC;IA9FC;;;;;;;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,GAAG,CAAC,IAAI,CAAC,GAAG,SAAS,WAAW,EAAE,CAAC,IAAoB,EAAE,EAAE;gBAC9D,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,CAAC,CAAC;QACL,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,GAAG,CAAC,IAAI,CAAC,mBAAmB,EAAE;YACjC,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 { ApprovalType } from '@metamask/controller-utils';\n\nimport type {\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n OriginalRequest,\n} from './AbstractMessageManager';\nimport { AbstractMessageManager } from './AbstractMessageManager';\nimport { normalizeMessageData, validateDecryptedMessageData } from './utils';\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 */\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 DecryptMessage extends 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 */\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 DecryptMessageParams extends 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> {\n /**\n * Name of this controller used during composition\n */\n override name = 'DecryptMessageManager' as const;\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.hub.once(`${messageId}:finished`, (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 * 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.hub.emit(`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,19 +4,16 @@ 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';
|
|
8
7
|
/**
|
|
9
8
|
* Controller in charge of managing - storing, adding, removing, updating - Messages.
|
|
10
9
|
*/
|
|
11
10
|
class EncryptionPublicKeyManager extends AbstractMessageManager_1.AbstractMessageManager {
|
|
12
|
-
constructor(
|
|
13
|
-
super(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
state,
|
|
19
|
-
});
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
/**
|
|
14
|
+
* Name of this controller used during composition
|
|
15
|
+
*/
|
|
16
|
+
this.name = 'EncryptionPublicKeyManager';
|
|
20
17
|
}
|
|
21
18
|
/**
|
|
22
19
|
* Creates a new Message with an 'unapproved' status using the passed messageParams.
|
|
@@ -30,7 +27,7 @@ class EncryptionPublicKeyManager extends AbstractMessageManager_1.AbstractMessag
|
|
|
30
27
|
(0, utils_1.validateEncryptionPublicKeyMessageData)(messageParams);
|
|
31
28
|
const messageId = await this.addUnapprovedMessage(messageParams, req);
|
|
32
29
|
return new Promise((resolve, reject) => {
|
|
33
|
-
this.
|
|
30
|
+
this.hub.once(`${messageId}:finished`, (data) => {
|
|
34
31
|
switch (data.status) {
|
|
35
32
|
case 'received':
|
|
36
33
|
return resolve(data.rawSig);
|
|
@@ -57,7 +54,7 @@ class EncryptionPublicKeyManager extends AbstractMessageManager_1.AbstractMessag
|
|
|
57
54
|
const messageData = this.createUnapprovedMessage(updatedMessageParams, controller_utils_1.ApprovalType.EthGetEncryptionPublicKey, req);
|
|
58
55
|
const messageId = messageData.id;
|
|
59
56
|
await this.addMessage(messageData);
|
|
60
|
-
this.
|
|
57
|
+
this.hub.emit(`unapprovedMessage`, {
|
|
61
58
|
...updatedMessageParams,
|
|
62
59
|
metamaskId: messageId,
|
|
63
60
|
});
|
|
@@ -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":";;;AAAA,iEAA0D;AAQ1D,yEAAkE;AAClE,uCAAiE;AA+CjE;;GAEG;AACH,MAAa,0BAA2B,SAAQ,+CAI/C;IAJD;;QAKE;;WAEG;QACM,SAAI,GAAG,4BAAqC,CAAC;IAyFxD,CAAC;IAvFC;;;;;;;OAOG;IACH,KAAK,CAAC,yBAAyB,CAC7B,aAAwC,EACxC,GAAqB;QAErB,IAAA,8CAAsC,EAAC,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,GAAG,CAAC,IAAI,CAAC,GAAG,SAAS,WAAW,EAAE,CAAC,IAAyB,EAAE,EAAE;gBACnE,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,CAAC,CAAC;QACL,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,+BAAY,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,GAAG,CAAC,IAAI,CAAC,mBAAmB,EAAE;YACjC,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;AAjGD,gEAiGC;AAED,kBAAe,0BAA0B,CAAC","sourcesContent":["import { ApprovalType } from '@metamask/controller-utils';\n\nimport type {\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n OriginalRequest,\n} from './AbstractMessageManager';\nimport { AbstractMessageManager } from './AbstractMessageManager';\nimport { validateEncryptionPublicKeyMessageData } from './utils';\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 */\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 EncryptionPublicKey extends 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 */\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 EncryptionPublicKeyParamsMetamask\n extends 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> {\n /**\n * Name of this controller used during composition\n */\n override name = 'EncryptionPublicKeyManager' as const;\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.hub.once(`${messageId}:finished`, (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 * 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.hub.emit(`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,19 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, MessageManagerState, OriginalRequest, SecurityProviderRequest } from "./AbstractMessageManager.cjs";
|
|
1
|
+
import type { AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, OriginalRequest } from "./AbstractMessageManager.cjs";
|
|
3
2
|
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 EncryptionPublicKeyManagerMessenger = RestrictedControllerMessenger<string, ActionConstraint, EventConstraint | EncryptionPublicKeyManagerUnapprovedMessageAddedEvent, string, string>;
|
|
11
|
-
type EncryptionPublicKeyManagerOptions = {
|
|
12
|
-
messenger: EncryptionPublicKeyManagerMessenger;
|
|
13
|
-
securityProviderRequest?: SecurityProviderRequest;
|
|
14
|
-
state?: MessageManagerState<EncryptionPublicKey>;
|
|
15
|
-
additionalFinishStatuses?: string[];
|
|
16
|
-
};
|
|
17
3
|
/**
|
|
18
4
|
* @type EncryptionPublicKey
|
|
19
5
|
*
|
|
@@ -25,9 +11,9 @@ type EncryptionPublicKeyManagerOptions = {
|
|
|
25
11
|
* A 'Message' which always has a 'eth_getEncryptionPublicKey' type
|
|
26
12
|
* @property rawSig - Encryption public key
|
|
27
13
|
*/
|
|
28
|
-
export
|
|
14
|
+
export interface EncryptionPublicKey extends AbstractMessage {
|
|
29
15
|
messageParams: EncryptionPublicKeyParams;
|
|
30
|
-
}
|
|
16
|
+
}
|
|
31
17
|
/**
|
|
32
18
|
* @type EncryptionPublicKeyParams
|
|
33
19
|
*
|
|
@@ -46,14 +32,17 @@ export type EncryptionPublicKeyParams = AbstractMessageParams;
|
|
|
46
32
|
* @property from - Address from which to extract the encryption public key
|
|
47
33
|
* @property origin? - Added for request origin identification
|
|
48
34
|
*/
|
|
49
|
-
export
|
|
35
|
+
export interface EncryptionPublicKeyParamsMetamask extends AbstractMessageParamsMetamask {
|
|
50
36
|
data: string;
|
|
51
|
-
}
|
|
37
|
+
}
|
|
52
38
|
/**
|
|
53
39
|
* Controller in charge of managing - storing, adding, removing, updating - Messages.
|
|
54
40
|
*/
|
|
55
|
-
export declare class EncryptionPublicKeyManager extends AbstractMessageManager<EncryptionPublicKey, EncryptionPublicKeyParams, EncryptionPublicKeyParamsMetamask
|
|
56
|
-
|
|
41
|
+
export declare class EncryptionPublicKeyManager extends AbstractMessageManager<EncryptionPublicKey, EncryptionPublicKeyParams, EncryptionPublicKeyParamsMetamask> {
|
|
42
|
+
/**
|
|
43
|
+
* Name of this controller used during composition
|
|
44
|
+
*/
|
|
45
|
+
name: "EncryptionPublicKeyManager";
|
|
57
46
|
/**
|
|
58
47
|
* Creates a new Message with an 'unapproved' status using the passed messageParams.
|
|
59
48
|
* 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":"AAEA,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,eAAe,EAChB,qCAAiC;AAClC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAGlE;;;;;;;;;;GAUG;AAIH,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC1D,aAAa,EAAE,yBAAyB,CAAC;CAC1C;AAED;;;;;;GAMG;AACH,MAAM,MAAM,yBAAyB,GAAG,qBAAqB,CAAC;AAE9D;;;;;;;;;GASG;AAIH,MAAM,WAAW,iCACf,SAAQ,6BAA6B;IACrC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,sBAAsB,CACpE,mBAAmB,EACnB,yBAAyB,EACzB,iCAAiC,CAClC;IACC;;OAEG;IACM,IAAI,+BAAyC;IAEtD;;;;;;;OAOG;IACG,yBAAyB,CAC7B,aAAa,EAAE,yBAAyB,EACxC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IA4BlB;;;;;;;;;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,19 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, MessageManagerState, OriginalRequest, SecurityProviderRequest } from "./AbstractMessageManager.mjs";
|
|
1
|
+
import type { AbstractMessage, AbstractMessageParams, AbstractMessageParamsMetamask, OriginalRequest } from "./AbstractMessageManager.mjs";
|
|
3
2
|
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 EncryptionPublicKeyManagerMessenger = RestrictedControllerMessenger<string, ActionConstraint, EventConstraint | EncryptionPublicKeyManagerUnapprovedMessageAddedEvent, string, string>;
|
|
11
|
-
type EncryptionPublicKeyManagerOptions = {
|
|
12
|
-
messenger: EncryptionPublicKeyManagerMessenger;
|
|
13
|
-
securityProviderRequest?: SecurityProviderRequest;
|
|
14
|
-
state?: MessageManagerState<EncryptionPublicKey>;
|
|
15
|
-
additionalFinishStatuses?: string[];
|
|
16
|
-
};
|
|
17
3
|
/**
|
|
18
4
|
* @type EncryptionPublicKey
|
|
19
5
|
*
|
|
@@ -25,9 +11,9 @@ type EncryptionPublicKeyManagerOptions = {
|
|
|
25
11
|
* A 'Message' which always has a 'eth_getEncryptionPublicKey' type
|
|
26
12
|
* @property rawSig - Encryption public key
|
|
27
13
|
*/
|
|
28
|
-
export
|
|
14
|
+
export interface EncryptionPublicKey extends AbstractMessage {
|
|
29
15
|
messageParams: EncryptionPublicKeyParams;
|
|
30
|
-
}
|
|
16
|
+
}
|
|
31
17
|
/**
|
|
32
18
|
* @type EncryptionPublicKeyParams
|
|
33
19
|
*
|
|
@@ -46,14 +32,17 @@ export type EncryptionPublicKeyParams = AbstractMessageParams;
|
|
|
46
32
|
* @property from - Address from which to extract the encryption public key
|
|
47
33
|
* @property origin? - Added for request origin identification
|
|
48
34
|
*/
|
|
49
|
-
export
|
|
35
|
+
export interface EncryptionPublicKeyParamsMetamask extends AbstractMessageParamsMetamask {
|
|
50
36
|
data: string;
|
|
51
|
-
}
|
|
37
|
+
}
|
|
52
38
|
/**
|
|
53
39
|
* Controller in charge of managing - storing, adding, removing, updating - Messages.
|
|
54
40
|
*/
|
|
55
|
-
export declare class EncryptionPublicKeyManager extends AbstractMessageManager<EncryptionPublicKey, EncryptionPublicKeyParams, EncryptionPublicKeyParamsMetamask
|
|
56
|
-
|
|
41
|
+
export declare class EncryptionPublicKeyManager extends AbstractMessageManager<EncryptionPublicKey, EncryptionPublicKeyParams, EncryptionPublicKeyParamsMetamask> {
|
|
42
|
+
/**
|
|
43
|
+
* Name of this controller used during composition
|
|
44
|
+
*/
|
|
45
|
+
name: "EncryptionPublicKeyManager";
|
|
57
46
|
/**
|
|
58
47
|
* Creates a new Message with an 'unapproved' status using the passed messageParams.
|
|
59
48
|
* 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":"AAEA,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,eAAe,EAChB,qCAAiC;AAClC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAGlE;;;;;;;;;;GAUG;AAIH,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC1D,aAAa,EAAE,yBAAyB,CAAC;CAC1C;AAED;;;;;;GAMG;AACH,MAAM,MAAM,yBAAyB,GAAG,qBAAqB,CAAC;AAE9D;;;;;;;;;GASG;AAIH,MAAM,WAAW,iCACf,SAAQ,6BAA6B;IACrC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,sBAAsB,CACpE,mBAAmB,EACnB,yBAAyB,EACzB,iCAAiC,CAClC;IACC;;OAEG;IACM,IAAI,+BAAyC;IAEtD;;;;;;;OAOG;IACG,yBAAyB,CAC7B,aAAa,EAAE,yBAAyB,EACxC,GAAG,CAAC,EAAE,eAAe,GACpB,OAAO,CAAC,MAAM,CAAC;IA4BlB;;;;;;;;;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,19 +1,16 @@
|
|
|
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';
|
|
5
4
|
/**
|
|
6
5
|
* Controller in charge of managing - storing, adding, removing, updating - Messages.
|
|
7
6
|
*/
|
|
8
7
|
export class EncryptionPublicKeyManager extends AbstractMessageManager {
|
|
9
|
-
constructor(
|
|
10
|
-
super(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
state,
|
|
16
|
-
});
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
/**
|
|
11
|
+
* Name of this controller used during composition
|
|
12
|
+
*/
|
|
13
|
+
this.name = 'EncryptionPublicKeyManager';
|
|
17
14
|
}
|
|
18
15
|
/**
|
|
19
16
|
* Creates a new Message with an 'unapproved' status using the passed messageParams.
|
|
@@ -27,7 +24,7 @@ export class EncryptionPublicKeyManager extends AbstractMessageManager {
|
|
|
27
24
|
validateEncryptionPublicKeyMessageData(messageParams);
|
|
28
25
|
const messageId = await this.addUnapprovedMessage(messageParams, req);
|
|
29
26
|
return new Promise((resolve, reject) => {
|
|
30
|
-
this.
|
|
27
|
+
this.hub.once(`${messageId}:finished`, (data) => {
|
|
31
28
|
switch (data.status) {
|
|
32
29
|
case 'received':
|
|
33
30
|
return resolve(data.rawSig);
|
|
@@ -54,7 +51,7 @@ export class EncryptionPublicKeyManager extends AbstractMessageManager {
|
|
|
54
51
|
const messageData = this.createUnapprovedMessage(updatedMessageParams, ApprovalType.EthGetEncryptionPublicKey, req);
|
|
55
52
|
const messageId = messageData.id;
|
|
56
53
|
await this.addMessage(messageData);
|
|
57
|
-
this.
|
|
54
|
+
this.hub.emit(`unapprovedMessage`, {
|
|
58
55
|
...updatedMessageParams,
|
|
59
56
|
metamaskId: messageId,
|
|
60
57
|
});
|
|
@@ -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":"AAAA,OAAO,EAAE,YAAY,EAAE,mCAAmC;AAQ1D,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAClE,OAAO,EAAE,sCAAsC,EAAE,oBAAgB;AA+CjE;;GAEG;AACH,MAAM,OAAO,0BAA2B,SAAQ,sBAI/C;IAJD;;QAKE;;WAEG;QACM,SAAI,GAAG,4BAAqC,CAAC;IAyFxD,CAAC;IAvFC;;;;;;;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,GAAG,CAAC,IAAI,CAAC,GAAG,SAAS,WAAW,EAAE,CAAC,IAAyB,EAAE,EAAE;gBACnE,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,CAAC,CAAC;QACL,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,GAAG,CAAC,IAAI,CAAC,mBAAmB,EAAE;YACjC,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 { ApprovalType } from '@metamask/controller-utils';\n\nimport type {\n AbstractMessage,\n AbstractMessageParams,\n AbstractMessageParamsMetamask,\n OriginalRequest,\n} from './AbstractMessageManager';\nimport { AbstractMessageManager } from './AbstractMessageManager';\nimport { validateEncryptionPublicKeyMessageData } from './utils';\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 */\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 EncryptionPublicKey extends 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 */\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 EncryptionPublicKeyParamsMetamask\n extends 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> {\n /**\n * Name of this controller used during composition\n */\n override name = 'EncryptionPublicKeyManager' as const;\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.hub.once(`${messageId}:finished`, (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 * 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.hub.emit(`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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/message-manager",
|
|
3
|
-
"version": "11.0.3-preview-
|
|
3
|
+
"version": "11.0.3-preview-e96ca40c",
|
|
4
4
|
"description": "Stores and manages interactions with signing requests",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -47,10 +47,10 @@
|
|
|
47
47
|
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@metamask/base-controller": "^7.
|
|
50
|
+
"@metamask/base-controller": "^7.0.2",
|
|
51
51
|
"@metamask/controller-utils": "^11.4.4",
|
|
52
52
|
"@metamask/eth-sig-util": "^8.0.0",
|
|
53
|
-
"@metamask/utils": "^
|
|
53
|
+
"@metamask/utils": "^10.0.0",
|
|
54
54
|
"@types/uuid": "^8.3.0",
|
|
55
55
|
"jsonschema": "^1.4.1",
|
|
56
56
|
"uuid": "^8.3.2"
|