@toruslabs/ethereum-controllers 4.4.0 → 4.5.2

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.
@@ -1,6 +1,6 @@
1
1
  import { InPageWalletProviderState } from "@toruslabs/base-controllers";
2
2
  import { JRPCEngineEndCallback, JRPCEngineNextCallback, JRPCMiddleware, JRPCRequest, JRPCResponse } from "@toruslabs/openlogin-jrpc";
3
- import { BlockParams, EthereumTransactionMeta, MessageParams, TransactionParams, TransactionRPCMeta, TypedMessageParams, UserRequestApprovalParams } from "../utils/interfaces";
3
+ import { BlockParams, EncryptionPublicKeyParams, EthereumTransactionMeta, MessageParams, TransactionParams, TransactionRPCMeta, TypedMessageParams, UserRequestApprovalParams } from "../utils/interfaces";
4
4
  export interface IProviderHandlers {
5
5
  version: string;
6
6
  requestAccounts?: (req: JRPCRequest<string[]>) => Promise<string[]>;
@@ -11,7 +11,7 @@ export interface IProviderHandlers {
11
11
  processTypedMessageV3?: (msgParams: TypedMessageParams, req: JRPCRequest<TypedMessageParams> & UserRequestApprovalParams) => Promise<string>;
12
12
  processTypedMessageV4?: (msgParams: TypedMessageParams, req: JRPCRequest<TypedMessageParams> & UserRequestApprovalParams) => Promise<string>;
13
13
  processPersonalMessage?: (msgParams: MessageParams, req: JRPCRequest<MessageParams> & UserRequestApprovalParams) => Promise<string>;
14
- processEncryptionPublicKey?: (address: string, req: JRPCRequest<string> & UserRequestApprovalParams) => Promise<string>;
14
+ processEncryptionPublicKey?: (msgParams: EncryptionPublicKeyParams, req: JRPCRequest<EncryptionPublicKeyParams> & UserRequestApprovalParams) => Promise<string>;
15
15
  processDecryptMessage?: (msgParams: MessageParams, req: JRPCRequest<MessageParams> & UserRequestApprovalParams) => Promise<string>;
16
16
  getPendingNonce?: (nonceParams: {
17
17
  address: string;
@@ -34,7 +34,7 @@ export declare function createProcessEthSignMessage({ processEthSignMessage, }:
34
34
  }): JRPCMiddleware<MessageParams, string>;
35
35
  export declare function createProcessTypedMessage({ processTypedMessage, }: {
36
36
  processTypedMessage: IProviderHandlers["processTypedMessage"];
37
- }): JRPCMiddleware<MessageParams, string>;
37
+ }): JRPCMiddleware<TypedMessageParams, string>;
38
38
  export declare function createProcessTypedMessageV3({ processTypedMessageV3, }: {
39
39
  processTypedMessageV3: IProviderHandlers["processTypedMessageV3"];
40
40
  }): JRPCMiddleware<TypedMessageParams, string>;
@@ -56,7 +56,7 @@ export declare function createPendingTxMiddleware({ getPendingTransactionByHash,
56
56
  }): JRPCMiddleware<string, TransactionRPCMeta>;
57
57
  export declare function createProcessEncryptionPublicKeyMiddleware({ processEncryptionPublicKey, }: {
58
58
  processEncryptionPublicKey: IProviderHandlers["processEncryptionPublicKey"];
59
- }): JRPCMiddleware<string, string>;
59
+ }): JRPCMiddleware<EncryptionPublicKeyParams, string>;
60
60
  export declare function createProcessDecryptMessageMiddleware({ processDecryptMessage, }: {
61
61
  processDecryptMessage: IProviderHandlers["processDecryptMessage"];
62
62
  }): JRPCMiddleware<MessageParams, string>;
@@ -28,6 +28,8 @@ export default class PreferencesController extends BasePreferencesController<Ext
28
28
  rehydrate?: boolean;
29
29
  locale?: string;
30
30
  type?: string;
31
+ signatures?: string[];
32
+ network?: string;
31
33
  }): Promise<void>;
32
34
  getSelectedAddress(): string;
33
35
  sync(address: string): Promise<boolean>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toruslabs/ethereum-controllers",
3
- "version": "4.4.0",
3
+ "version": "4.5.2",
4
4
  "homepage": "https://github.com/torusresearch/controllers#readme",
5
5
  "license": "ISC",
6
6
  "main": "dist/ethereumControllers.cjs.js",
@@ -24,7 +24,7 @@
24
24
  "@ethereumjs/util": "^9.0.0",
25
25
  "@metamask/eth-sig-util": "^7.0.0",
26
26
  "@metamask/rpc-errors": "^6.0.0",
27
- "@toruslabs/base-controllers": "^4.4.0",
27
+ "@toruslabs/base-controllers": "^4.5.2",
28
28
  "@toruslabs/http-helpers": "^5.0.0",
29
29
  "@toruslabs/openlogin-jrpc": "^5.1.0",
30
30
  "async-mutex": "^0.4.0",
@@ -64,7 +64,7 @@
64
64
  "publishConfig": {
65
65
  "access": "public"
66
66
  },
67
- "gitHead": "121c3cbe5e56fd96a0421ed16fbc176ae766f5d0",
67
+ "gitHead": "b9cdf82ea7bf007ae8461e27d7213baeb4a84768",
68
68
  "devDependencies": {
69
69
  "ganache": "^7.9.1"
70
70
  }
@@ -60,7 +60,7 @@ export class DecryptMessageController extends AbstractMessageController<DecryptM
60
60
  messageParams.origin = req.origin;
61
61
  }
62
62
  messageParams.data = normalizeMessageData(messageParams.data);
63
- const messageId = randomId();
63
+ const messageId = messageParams.id || randomId();
64
64
  const messageData: DecryptMessage = {
65
65
  id: messageId,
66
66
  messageParams,
@@ -61,7 +61,7 @@ export class EncryptionPublicKeyController extends AbstractMessageController<Enc
61
61
  if (req) {
62
62
  messageParams.origin = req.origin;
63
63
  }
64
- const messageId = randomId();
64
+ const messageId = messageParams.id || randomId();
65
65
  const messageData: EncryptionPublicKey = {
66
66
  id: messageId,
67
67
  messageParams,
@@ -55,7 +55,7 @@ export class MessageController extends AbstractMessageController<Message, Messag
55
55
  messageParams.origin = req.origin;
56
56
  }
57
57
  messageParams.data = normalizeMessageData(messageParams.data);
58
- const messageId = randomId();
58
+ const messageId = messageParams.id || randomId();
59
59
  const messageData: Message = {
60
60
  id: messageId,
61
61
  messageParams,
@@ -48,11 +48,8 @@ export class TypedMessageController extends AbstractMessageController<TypedMessa
48
48
  try {
49
49
  const msgObject = this.getMessage(messageId);
50
50
  const cleanMsgParams = await this.approveMessage(messageId, msgObject.messageParams);
51
- const rawSig = await this.signTypedData(
52
- cleanMsgParams.data as TypedDataV1 | EthSigTypedMessage<MessageTypes>,
53
- cleanMsgParams.from,
54
- cleanMsgParams.version
55
- );
51
+ const msgData = cleanMsgParams.version === SignTypedDataVersion.V1 ? cleanMsgParams.data : JSON.parse(cleanMsgParams.data as string);
52
+ const rawSig = await this.signTypedData(msgData as TypedDataV1 | EthSigTypedMessage<MessageTypes>, cleanMsgParams.from, cleanMsgParams.version);
56
53
  this.updateMessage({ ...msgObject, rawSig });
57
54
  this.setMessageStatus(messageId, MessageStatus.SIGNED);
58
55
  return rawSig;
@@ -93,7 +90,7 @@ export class TypedMessageController extends AbstractMessageController<TypedMessa
93
90
  messageParams.origin = req.origin;
94
91
  }
95
92
  messageParams.version = version;
96
- const messageId = randomId();
93
+ const messageId = messageParams.id || randomId();
97
94
  const messageData: TypedMessage = {
98
95
  id: messageId,
99
96
  messageParams,
@@ -13,6 +13,7 @@ import {
13
13
  import { METHOD_TYPES, TRANSACTION_ENVELOPE_TYPES } from "../utils/constants";
14
14
  import {
15
15
  BlockParams,
16
+ EncryptionPublicKeyParams,
16
17
  EthereumTransactionMeta,
17
18
  MessageParams,
18
19
  TransactionParams,
@@ -35,7 +36,10 @@ export interface IProviderHandlers {
35
36
  processTypedMessageV4?: (msgParams: TypedMessageParams, req: JRPCRequest<TypedMessageParams> & UserRequestApprovalParams) => Promise<string>;
36
37
  processPersonalMessage?: (msgParams: MessageParams, req: JRPCRequest<MessageParams> & UserRequestApprovalParams) => Promise<string>;
37
38
 
38
- processEncryptionPublicKey?: (address: string, req: JRPCRequest<string> & UserRequestApprovalParams) => Promise<string>;
39
+ processEncryptionPublicKey?: (
40
+ msgParams: EncryptionPublicKeyParams,
41
+ req: JRPCRequest<EncryptionPublicKeyParams> & UserRequestApprovalParams
42
+ ) => Promise<string>;
39
43
  processDecryptMessage?: (msgParams: MessageParams, req: JRPCRequest<MessageParams> & UserRequestApprovalParams) => Promise<string>;
40
44
 
41
45
  getPendingNonce?: (
@@ -98,7 +102,7 @@ export function createProcessTypedMessage({
98
102
  processTypedMessage,
99
103
  }: {
100
104
  processTypedMessage: IProviderHandlers["processTypedMessage"];
101
- }): JRPCMiddleware<MessageParams, string> {
105
+ }): JRPCMiddleware<TypedMessageParams, string> {
102
106
  return createAsyncMiddleware(async (request, response, next) => {
103
107
  const { method } = request;
104
108
  if (method !== METHOD_TYPES.ETH_SIGN_TYPED_DATA) return next();
@@ -226,7 +230,7 @@ export function createProcessEncryptionPublicKeyMiddleware({
226
230
  processEncryptionPublicKey,
227
231
  }: {
228
232
  processEncryptionPublicKey: IProviderHandlers["processEncryptionPublicKey"];
229
- }): JRPCMiddleware<string, string> {
233
+ }): JRPCMiddleware<EncryptionPublicKeyParams, string> {
230
234
  return createAsyncMiddleware(async (request, response, next) => {
231
235
  const { params, method } = request;
232
236
  if (method !== METHOD_TYPES.ETH_GET_ENCRYPTION_PUBLIC_KEY) return next();
@@ -90,9 +90,11 @@ export default class PreferencesController
90
90
  rehydrate?: boolean;
91
91
  locale?: string;
92
92
  type?: string;
93
+ signatures?: string[];
94
+ network?: string;
93
95
  }): Promise<void> {
94
- const { address, jwtToken, calledFromEmbed, userInfo, rehydrate, locale = "en-US", type } = params;
95
- await super.init(address, userInfo, jwtToken, { type, email: userInfo.email });
96
+ const { address, jwtToken, calledFromEmbed, userInfo, rehydrate, locale = "en-US", type, signatures, network } = params;
97
+ await super.init(address, userInfo, jwtToken, { type, email: userInfo.email, signatures, network });
96
98
  const { aggregateVerifier, verifier, verifierId } = userInfo || {};
97
99
  const userExists = await this.sync(address);
98
100
  if (!userExists) {