@metamask-previews/eth-json-rpc-middleware 21.0.0-preview-2045196c → 21.0.0-preview-5a558267
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/dist/utils/normalize.cjs +7 -2
- package/dist/utils/normalize.cjs.map +1 -1
- package/dist/utils/normalize.d.cts.map +1 -1
- package/dist/utils/normalize.d.mts.map +1 -1
- package/dist/utils/normalize.mjs +7 -2
- package/dist/utils/normalize.mjs.map +1 -1
- package/dist/wallet.cjs +2 -2
- package/dist/wallet.cjs.map +1 -1
- package/dist/wallet.mjs +2 -2
- package/dist/wallet.mjs.map +1 -1
- package/package.json +3 -1
package/dist/utils/normalize.cjs
CHANGED
|
@@ -20,8 +20,13 @@ function normalizeTypedMessage(messageData) {
|
|
|
20
20
|
if (!verifyingContract) {
|
|
21
21
|
return messageData;
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
return JSON.stringify({
|
|
24
|
+
...data,
|
|
25
|
+
domain: {
|
|
26
|
+
...data.domain,
|
|
27
|
+
verifyingContract: normalizeContractAddress(verifyingContract),
|
|
28
|
+
},
|
|
29
|
+
});
|
|
25
30
|
}
|
|
26
31
|
exports.normalizeTypedMessage = normalizeTypedMessage;
|
|
27
32
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.cjs","sourceRoot":"","sources":["../../src/utils/normalize.ts"],"names":[],"mappings":";;;AAaA;;;;;GAKG;AACH,SAAgB,qBAAqB,CAAC,WAAmB;IACvD,IAAI,IAAI,CAAC;IACT,IAAI;QACF,IAAI,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC;KACvC;IAAC,MAAM;QACN,yDAAyD;QACzD,OAAO,WAAW,CAAC;KACpB;IAED,MAAM,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;IAEhD,IAAI,CAAC,iBAAiB,EAAE;QACtB,OAAO,WAAW,CAAC;KACpB;IAED,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"normalize.cjs","sourceRoot":"","sources":["../../src/utils/normalize.ts"],"names":[],"mappings":";;;AAaA;;;;;GAKG;AACH,SAAgB,qBAAqB,CAAC,WAAmB;IACvD,IAAI,IAAI,CAAC;IACT,IAAI;QACF,IAAI,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC;KACvC;IAAC,MAAM;QACN,yDAAyD;QACzD,OAAO,WAAW,CAAC;KACpB;IAED,MAAM,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;IAEhD,IAAI,CAAC,iBAAiB,EAAE;QACtB,OAAO,WAAW,CAAC;KACpB;IAED,OAAO,IAAI,CAAC,SAAS,CAAC;QACpB,GAAG,IAAI;QACP,MAAM,EAAE;YACN,GAAG,IAAI,CAAC,MAAM;YACd,iBAAiB,EAAE,wBAAwB,CAAC,iBAAiB,CAAC;SAC/D;KACF,CAAC,CAAC;AACL,CAAC;AAtBD,sDAsBC;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,IAAY;IAC5C,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,OAAO,IAAI,CAAC;KACb;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAwC,CAAC;AACjE,CAAC;AAND,8CAMC;AAED;;;;;GAKG;AACH,SAAS,wBAAwB,CAAC,OAAY;IAC5C,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAC5B,OAAO,KAAK,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;KAChC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\ntype EIP712Domain = {\n verifyingContract: Hex;\n};\n\ntype SignTypedMessageDataV3V4 = {\n types: Record<string, unknown>;\n domain: EIP712Domain;\n primaryType: string;\n message: unknown;\n};\n\n/**\n * Normalizes the messageData for the eth_signTypedData\n *\n * @param messageData - The messageData to normalize.\n * @returns The normalized messageData.\n */\nexport function normalizeTypedMessage(messageData: string) {\n let data;\n try {\n data = parseTypedMessage(messageData);\n } catch {\n // Ignore normalization errors and pass the message as is\n return messageData;\n }\n\n const { verifyingContract } = data.domain ?? {};\n\n if (!verifyingContract) {\n return messageData;\n }\n\n return JSON.stringify({\n ...data,\n domain: {\n ...data.domain,\n verifyingContract: normalizeContractAddress(verifyingContract),\n },\n });\n}\n\n/**\n * Parses the messageData to obtain the data object for EIP712 normalization\n *\n * @param data - The messageData to parse.\n * @returns The data object for EIP712 normalization.\n */\nexport function parseTypedMessage(data: string) {\n if (typeof data !== 'string') {\n return data;\n }\n\n return JSON.parse(data) as unknown as SignTypedMessageDataV3V4;\n}\n\n/**\n * Normalizes the address to standard hexadecimal format\n *\n * @param address - The address to normalize.\n * @returns The normalized address.\n */\nfunction normalizeContractAddress(address: Hex): Hex {\n if (address.startsWith('0X')) {\n return `0x${address.slice(2)}`;\n }\n return address;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.d.cts","sourceRoot":"","sources":["../../src/utils/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,KAAK,YAAY,GAAG;IAClB,iBAAiB,EAAE,GAAG,CAAC;CACxB,CAAC;AAEF,KAAK,wBAAwB,GAAG;IAC9B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,MAAM,EAAE,YAAY,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"normalize.d.cts","sourceRoot":"","sources":["../../src/utils/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,KAAK,YAAY,GAAG;IAClB,iBAAiB,EAAE,GAAG,CAAC;CACxB,CAAC;AAEF,KAAK,wBAAwB,GAAG;IAC9B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,MAAM,EAAE,YAAY,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,MAAM,UAsBxD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,4BAM7C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.d.mts","sourceRoot":"","sources":["../../src/utils/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,KAAK,YAAY,GAAG;IAClB,iBAAiB,EAAE,GAAG,CAAC;CACxB,CAAC;AAEF,KAAK,wBAAwB,GAAG;IAC9B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,MAAM,EAAE,YAAY,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"normalize.d.mts","sourceRoot":"","sources":["../../src/utils/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,KAAK,YAAY,GAAG;IAClB,iBAAiB,EAAE,GAAG,CAAC;CACxB,CAAC;AAEF,KAAK,wBAAwB,GAAG;IAC9B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,MAAM,EAAE,YAAY,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,MAAM,UAsBxD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,4BAM7C"}
|
package/dist/utils/normalize.mjs
CHANGED
|
@@ -17,8 +17,13 @@ export function normalizeTypedMessage(messageData) {
|
|
|
17
17
|
if (!verifyingContract) {
|
|
18
18
|
return messageData;
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
return JSON.stringify({
|
|
21
|
+
...data,
|
|
22
|
+
domain: {
|
|
23
|
+
...data.domain,
|
|
24
|
+
verifyingContract: normalizeContractAddress(verifyingContract),
|
|
25
|
+
},
|
|
26
|
+
});
|
|
22
27
|
}
|
|
23
28
|
/**
|
|
24
29
|
* Parses the messageData to obtain the data object for EIP712 normalization
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.mjs","sourceRoot":"","sources":["../../src/utils/normalize.ts"],"names":[],"mappings":"AAaA;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,WAAmB;IACvD,IAAI,IAAI,CAAC;IACT,IAAI;QACF,IAAI,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC;KACvC;IAAC,MAAM;QACN,yDAAyD;QACzD,OAAO,WAAW,CAAC;KACpB;IAED,MAAM,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;IAEhD,IAAI,CAAC,iBAAiB,EAAE;QACtB,OAAO,WAAW,CAAC;KACpB;IAED,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"normalize.mjs","sourceRoot":"","sources":["../../src/utils/normalize.ts"],"names":[],"mappings":"AAaA;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,WAAmB;IACvD,IAAI,IAAI,CAAC;IACT,IAAI;QACF,IAAI,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC;KACvC;IAAC,MAAM;QACN,yDAAyD;QACzD,OAAO,WAAW,CAAC;KACpB;IAED,MAAM,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;IAEhD,IAAI,CAAC,iBAAiB,EAAE;QACtB,OAAO,WAAW,CAAC;KACpB;IAED,OAAO,IAAI,CAAC,SAAS,CAAC;QACpB,GAAG,IAAI;QACP,MAAM,EAAE;YACN,GAAG,IAAI,CAAC,MAAM;YACd,iBAAiB,EAAE,wBAAwB,CAAC,iBAAiB,CAAC;SAC/D;KACF,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,OAAO,IAAI,CAAC;KACb;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAwC,CAAC;AACjE,CAAC;AAED;;;;;GAKG;AACH,SAAS,wBAAwB,CAAC,OAAY;IAC5C,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAC5B,OAAO,KAAK,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;KAChC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\ntype EIP712Domain = {\n verifyingContract: Hex;\n};\n\ntype SignTypedMessageDataV3V4 = {\n types: Record<string, unknown>;\n domain: EIP712Domain;\n primaryType: string;\n message: unknown;\n};\n\n/**\n * Normalizes the messageData for the eth_signTypedData\n *\n * @param messageData - The messageData to normalize.\n * @returns The normalized messageData.\n */\nexport function normalizeTypedMessage(messageData: string) {\n let data;\n try {\n data = parseTypedMessage(messageData);\n } catch {\n // Ignore normalization errors and pass the message as is\n return messageData;\n }\n\n const { verifyingContract } = data.domain ?? {};\n\n if (!verifyingContract) {\n return messageData;\n }\n\n return JSON.stringify({\n ...data,\n domain: {\n ...data.domain,\n verifyingContract: normalizeContractAddress(verifyingContract),\n },\n });\n}\n\n/**\n * Parses the messageData to obtain the data object for EIP712 normalization\n *\n * @param data - The messageData to parse.\n * @returns The data object for EIP712 normalization.\n */\nexport function parseTypedMessage(data: string) {\n if (typeof data !== 'string') {\n return data;\n }\n\n return JSON.parse(data) as unknown as SignTypedMessageDataV3V4;\n}\n\n/**\n * Normalizes the address to standard hexadecimal format\n *\n * @param address - The address to normalize.\n * @returns The normalized address.\n */\nfunction normalizeContractAddress(address: Hex): Hex {\n if (address.startsWith('0X')) {\n return `0x${address.slice(2)}`;\n }\n return address;\n}\n"]}
|
package/dist/wallet.cjs
CHANGED
|
@@ -342,7 +342,7 @@ function createWalletMiddleware({ getAccounts, processDecryptMessage, processEnc
|
|
|
342
342
|
return await processEncryptionPublicKey(address, {
|
|
343
343
|
id: request.id,
|
|
344
344
|
origin: context.assertGet('origin'),
|
|
345
|
-
securityAlertResponse: context.
|
|
345
|
+
securityAlertResponse: context.get('securityAlertResponse'),
|
|
346
346
|
});
|
|
347
347
|
}
|
|
348
348
|
/**
|
|
@@ -374,7 +374,7 @@ function createWalletMiddleware({ getAccounts, processDecryptMessage, processEnc
|
|
|
374
374
|
return await processDecryptMessage(msgParams, {
|
|
375
375
|
id: request.id,
|
|
376
376
|
origin: context.assertGet('origin'),
|
|
377
|
-
securityAlertResponse: context.
|
|
377
|
+
securityAlertResponse: context.get('securityAlertResponse'),
|
|
378
378
|
});
|
|
379
379
|
}
|
|
380
380
|
//
|
package/dist/wallet.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.cjs","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gEAAkD;AAMlD,qDAAwE;AAExE,qDAAiD;AACjD,2CAAoD;AAGpD,6GAGwD;AACxD,yGAGsD;AACtD,+CAAyD;AACzD,qDAA6E;AAC7E,uDAG4B;AAiF5B;;;;;;;;;;;;;;;;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AC;IACvE,sEAAsE;IACtE,iEAAiE;IACjE,IACE,iBAAiB;QAChB,iBAA4B,KAAK,QAAQ;QAC1C,CAAC,IAAA,yBAAiB,EAAC,iBAAiB,CAAC,EACrC;QACA,MAAM,sBAAS,CAAC,YAAY,EAAE,CAAC;KAChC;AACH,CAAC","sourcesContent":["import * as sigUtil from '@metamask/eth-sig-util';\nimport type {\n JsonRpcMiddleware,\n MiddlewareContext,\n MiddlewareParams,\n} from '@metamask/json-rpc-engine/v2';\nimport { createScaffoldMiddleware } from '@metamask/json-rpc-engine/v2';\nimport type { MessageRequest } from '@metamask/message-manager';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport { isValidHexAddress } from '@metamask/utils';\nimport type { JsonRpcRequest, Json, Hex } from '@metamask/utils';\n\nimport {\n createWalletRequestExecutionPermissionsHandler,\n type ProcessRequestExecutionPermissionsHook,\n} from './methods/wallet-request-execution-permissions';\nimport {\n type ProcessRevokeExecutionPermissionHook,\n createWalletRevokeExecutionPermissionHandler,\n} from './methods/wallet-revoke-execution-permission';\nimport { stripArrayTypeIfPresent } from './utils/common';\nimport { normalizeTypedMessage, parseTypedMessage } from './utils/normalize';\nimport {\n resemblesAddress,\n validateAndNormalizeKeyholder as validateKeyholder,\n} from './utils/validation';\n\nexport type TransactionParams = {\n from: string;\n};\n\nexport type MessageParams = TransactionParams & {\n data: string;\n signatureMethod?: string;\n};\n\nexport type TypedMessageParams = MessageParams & {\n version: string;\n};\n\nexport type TypedMessageV1Params = Omit<TypedMessageParams, 'data'> & {\n data: Record<string, unknown>[];\n};\n\nexport type WalletMiddlewareOptions = {\n getAccounts: (origin: string) => Promise<string[]>;\n processDecryptMessage?: (\n msgParams: MessageParams,\n req: MessageRequest,\n ) => Promise<string>;\n processEncryptionPublicKey?: (\n address: string,\n req: MessageRequest,\n ) => Promise<string>;\n processPersonalMessage?: (\n msgParams: MessageParams,\n req: JsonRpcRequest,\n context: WalletMiddlewareContext,\n ) => Promise<string>;\n processTransaction?: (\n txParams: TransactionParams,\n req: JsonRpcRequest,\n context: WalletMiddlewareContext,\n ) => Promise<string>;\n processSignTransaction?: (\n txParams: TransactionParams,\n req: JsonRpcRequest,\n context: WalletMiddlewareContext,\n ) => Promise<string>;\n processTypedMessage?: (\n msgParams: TypedMessageV1Params,\n req: JsonRpcRequest,\n context: WalletMiddlewareContext,\n version: string,\n ) => Promise<string>;\n processTypedMessageV3?: (\n msgParams: TypedMessageParams,\n req: JsonRpcRequest,\n context: WalletMiddlewareContext,\n version: string,\n ) => Promise<string>;\n processTypedMessageV4?: (\n msgParams: TypedMessageParams,\n req: JsonRpcRequest,\n context: WalletMiddlewareContext,\n version: string,\n ) => Promise<string>;\n processRequestExecutionPermissions?: ProcessRequestExecutionPermissionsHook;\n processRevokeExecutionPermission?: ProcessRevokeExecutionPermissionHook;\n};\n\nexport type WalletMiddlewareKeyValues = {\n networkClientId: string;\n origin: string;\n securityAlertResponse?: Record<string, Json>;\n traceContext?: unknown;\n};\n\nexport type WalletMiddlewareContext =\n MiddlewareContext<WalletMiddlewareKeyValues>;\n\nexport type WalletMiddlewareParams = MiddlewareParams<\n JsonRpcRequest,\n WalletMiddlewareContext\n>;\n\n/**\n * Creates a JSON-RPC middleware that handles \"wallet\"-related JSON-RPC methods.\n * \"Wallet\" may have had a specific meaning at some point in the distant past,\n * but at this point it's just an arbitrary label.\n *\n * @param options - The options for the middleware.\n * @param options.getAccounts - The function to get the accounts for the origin.\n * @param options.processDecryptMessage - The function to process the decrypt message request.\n * @param options.processEncryptionPublicKey - The function to process the encryption public key request.\n * @param options.processPersonalMessage - The function to process the personal message request.\n * @param options.processTransaction - The function to process the transaction request.\n * @param options.processSignTransaction - The function to process the sign transaction request.\n * @param options.processTypedMessage - The function to process the typed message request.\n * @param options.processTypedMessageV3 - The function to process the typed message v3 request.\n * @param options.processTypedMessageV4 - The function to process the typed message v4 request.\n * @param options.processRequestExecutionPermissions - The function to process the request execution permissions request.\n * @param options.processRevokeExecutionPermission - The function to process the revoke execution permission request.\n * @returns A JSON-RPC middleware that handles wallet-related JSON-RPC methods.\n */\nexport function createWalletMiddleware({\n getAccounts,\n processDecryptMessage,\n processEncryptionPublicKey,\n processPersonalMessage,\n processTransaction,\n processSignTransaction,\n processTypedMessage,\n processTypedMessageV3,\n processTypedMessageV4,\n processRequestExecutionPermissions,\n processRevokeExecutionPermission,\n}: WalletMiddlewareOptions): JsonRpcMiddleware<\n JsonRpcRequest,\n Json,\n WalletMiddlewareContext\n> {\n if (!getAccounts) {\n throw new Error('opts.getAccounts is required');\n }\n\n return createScaffoldMiddleware<WalletMiddlewareContext>({\n // account lookups\n eth_accounts: lookupAccounts,\n eth_coinbase: lookupDefaultAccount,\n\n // tx signatures\n eth_sendTransaction: sendTransaction,\n eth_signTransaction: signTransaction,\n\n // message signatures\n eth_signTypedData: signTypedData,\n eth_signTypedData_v3: signTypedDataV3,\n eth_signTypedData_v4: signTypedDataV4,\n personal_sign: personalSign,\n eth_getEncryptionPublicKey: encryptionPublicKey,\n eth_decrypt: decryptMessage,\n personal_ecRecover: personalRecover,\n\n // EIP-7715\n wallet_requestExecutionPermissions:\n createWalletRequestExecutionPermissionsHandler({\n processRequestExecutionPermissions,\n }),\n wallet_revokeExecutionPermission:\n createWalletRevokeExecutionPermissionHandler({\n processRevokeExecutionPermission,\n }),\n });\n\n //\n // account lookups\n //\n\n /**\n * Gets the accounts for the origin.\n *\n * @param options - Options bag.\n * @param options.context - The context of the request.\n * @returns The accounts for the origin.\n */\n async function lookupAccounts({\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n return await getAccounts(context.assertGet('origin'));\n }\n\n /**\n * Gets the default account (i.e. first in the list) for the origin.\n *\n * @param options - Options bag.\n * @param options.context - The context of the request.\n * @returns The default account for the origin.\n */\n async function lookupDefaultAccount({\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n const accounts = await getAccounts(context.assertGet('origin'));\n return accounts[0] || null;\n }\n\n //\n // transaction signatures\n //\n\n /**\n * Sends a transaction.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The transaction hash.\n */\n async function sendTransaction({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processTransaction) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 1)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params[0] as TransactionParams | undefined;\n const txParams: TransactionParams = {\n ...params,\n from: await validateAndNormalizeKeyholder(params?.from || '', context),\n };\n return await processTransaction(txParams, request, context);\n }\n\n /**\n * Signs a transaction.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The signed transaction.\n */\n async function signTransaction({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processSignTransaction) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 1)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params[0] as TransactionParams | undefined;\n const txParams: TransactionParams = {\n ...params,\n from: await validateAndNormalizeKeyholder(params?.from || '', context),\n };\n return await processSignTransaction(txParams, request, context);\n }\n\n //\n // message signatures\n //\n\n /**\n * Signs a `eth_signTypedData` message.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The signed message.\n */\n async function signTypedData({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processTypedMessage) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 2)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params as [\n Record<string, unknown>[],\n string,\n Record<string, string>?,\n ];\n const message = params[0];\n const address = await validateAndNormalizeKeyholder(params[1], context);\n const version = 'V1';\n const extraParams = params[2] || {};\n const msgParams: TypedMessageV1Params = {\n ...extraParams,\n from: address,\n data: message,\n signatureMethod: 'eth_signTypedData',\n version,\n };\n\n return await processTypedMessage(msgParams, request, context, version);\n }\n\n /**\n * Signs a `eth_signTypedData_v3` message.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The signed message.\n */\n async function signTypedDataV3({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processTypedMessageV3) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 2)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params as [string, string];\n\n const address = await validateAndNormalizeKeyholder(params[0], context);\n const message = normalizeTypedMessage(params[1]);\n validatePrimaryType(message);\n validateVerifyingContract(message);\n const version = 'V3';\n const msgParams: TypedMessageParams = {\n data: message,\n from: address,\n version,\n signatureMethod: 'eth_signTypedData_v3',\n };\n\n return await processTypedMessageV3(msgParams, request, context, version);\n }\n\n /**\n * Signs a `eth_signTypedData_v4` message.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The signed message.\n */\n async function signTypedDataV4({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processTypedMessageV4) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 2)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params as [string, string];\n\n const address = await validateAndNormalizeKeyholder(params[0], context);\n const message = normalizeTypedMessage(params[1]);\n validatePrimaryType(message);\n validateVerifyingContract(message);\n const version = 'V4';\n const msgParams: TypedMessageParams = {\n data: message,\n from: address,\n version,\n signatureMethod: 'eth_signTypedData_v4',\n };\n\n return await processTypedMessageV4(msgParams, request, context, version);\n }\n\n /**\n * Signs a `personal_sign` message.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The signed message.\n */\n async function personalSign({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processPersonalMessage) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 2)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params as [string, string, TransactionParams?];\n\n // process normally\n const firstParam = params[0];\n const secondParam = params[1];\n // non-standard \"extraParams\" to be appended to our \"msgParams\" obj\n const extraParams = params[2] || {};\n\n // We initially incorrectly ordered these parameters.\n // To gracefully respect users who adopted this API early,\n // we are currently gracefully recovering from the wrong param order\n // when it is clearly identifiable.\n //\n // That means when the first param is definitely an address,\n // and the second param is definitely not, but is hex.\n let address: string, message: string;\n if (resemblesAddress(firstParam) && !resemblesAddress(secondParam)) {\n address = firstParam;\n message = secondParam;\n } else {\n message = firstParam;\n address = secondParam;\n }\n address = await validateAndNormalizeKeyholder(address, context);\n\n const msgParams: MessageParams = {\n ...extraParams,\n from: address,\n data: message,\n signatureMethod: 'personal_sign',\n };\n\n return await processPersonalMessage(msgParams, request, context);\n }\n\n /**\n * Recovers the signer address from a `personal_sign` message.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @returns The recovered signer address.\n */\n async function personalRecover({\n request,\n }: WalletMiddlewareParams): Promise<Json> {\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 2)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params as [string, string];\n const message = params[0];\n const signature = params[1];\n const signerAddress = sigUtil.recoverPersonalSignature({\n data: message,\n signature,\n });\n\n return signerAddress;\n }\n\n /**\n * Gets the encryption public key for an address.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The encryption public key.\n */\n async function encryptionPublicKey({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processEncryptionPublicKey) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 1)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params as [string];\n\n const address = await validateAndNormalizeKeyholder(params[0], context);\n\n return await processEncryptionPublicKey(address, {\n id: request.id as string | number,\n origin: context.assertGet('origin'),\n securityAlertResponse: context.assertGet('securityAlertResponse'),\n });\n }\n\n /**\n * Decrypts a message.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The decrypted message.\n */\n async function decryptMessage({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processDecryptMessage) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 1)\n ) {\n throw rpcErrors.invalidInput();\n }\n const params = request.params as [string, string, Record<string, Json>?];\n\n const ciphertext: string = params[0];\n const address: string = await validateAndNormalizeKeyholder(\n params[1],\n context,\n );\n const extraParams = params[2] || {};\n const msgParams: MessageParams = {\n ...extraParams,\n from: address,\n data: ciphertext,\n };\n\n return await processDecryptMessage(msgParams, {\n id: request.id as string | number,\n origin: context.assertGet('origin'),\n securityAlertResponse: context.assertGet('securityAlertResponse'),\n });\n }\n\n //\n // utility\n //\n\n /**\n * Validates the keyholder address, and returns a normalized (i.e. lowercase)\n * copy of it.\n *\n * @param address - The address to validate and normalize.\n * @param context - The context of the request.\n * @returns The normalized address, if valid. Otherwise, throws\n * an error\n */\n async function validateAndNormalizeKeyholder(\n address: string,\n context: WalletMiddlewareContext,\n ): Promise<string> {\n return validateKeyholder(address as Hex, context, { getAccounts });\n }\n}\n\n/**\n * Validates primary of typedSignMessage, to ensure that it's type definition is present in message.\n *\n * @param data - The data passed in typedSign request.\n */\nfunction validatePrimaryType(data: string) {\n const { primaryType, types } = parseTypedMessage(data);\n if (!types) {\n throw rpcErrors.invalidInput();\n }\n\n // Primary type can be an array.\n const baseType = stripArrayTypeIfPresent(primaryType);\n\n // Return if the base type is not defined in the types\n const baseTypeDefinitions = types[baseType];\n if (!baseTypeDefinitions) {\n throw rpcErrors.invalidInput();\n }\n}\n\n/**\n * Validates verifyingContract of typedSignMessage.\n *\n * @param data - The data passed in typedSign request.\n * This function allows the verifyingContract to be either:\n * - A valid hex address\n * - The string \"cosmos\" (as it is hard-coded in some Cosmos ecosystem's EVM adapters)\n * - An empty string\n */\nfunction validateVerifyingContract(data: string) {\n const { domain: { verifyingContract } = {} } = parseTypedMessage(data);\n // Explicit check for cosmos here has been added to address this issue\n // https://github.com/MetaMask/eth-json-rpc-middleware/issues/337\n if (\n verifyingContract &&\n (verifyingContract as string) !== 'cosmos' &&\n !isValidHexAddress(verifyingContract)\n ) {\n throw rpcErrors.invalidInput();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"wallet.cjs","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gEAAkD;AAMlD,qDAAwE;AAExE,qDAAiD;AACjD,2CAAoD;AAGpD,6GAGwD;AACxD,yGAGsD;AACtD,+CAAyD;AACzD,qDAA6E;AAC7E,uDAG4B;AAiF5B;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,sBAAsB,CAAC,EACrC,WAAW,EACX,qBAAqB,EACrB,0BAA0B,EAC1B,sBAAsB,EACtB,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,kCAAkC,EAClC,gCAAgC,GACR;IAKxB,IAAI,CAAC,WAAW,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;KACjD;IAED,OAAO,IAAA,6BAAwB,EAA0B;QACvD,kBAAkB;QAClB,YAAY,EAAE,cAAc;QAC5B,YAAY,EAAE,oBAAoB;QAElC,gBAAgB;QAChB,mBAAmB,EAAE,eAAe;QACpC,mBAAmB,EAAE,eAAe;QAEpC,qBAAqB;QACrB,iBAAiB,EAAE,aAAa;QAChC,oBAAoB,EAAE,eAAe;QACrC,oBAAoB,EAAE,eAAe;QACrC,aAAa,EAAE,YAAY;QAC3B,0BAA0B,EAAE,mBAAmB;Q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C;AAzcD,wDAycC;AAED;;;;GAIG;AACH,SAAS,mBAAmB,CAAC,IAAY;IACvC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,IAAA,6BAAiB,EAAC,IAAI,CAAC,CAAC;IACvD,IAAI,CAAC,KAAK,EAAE;QACV,MAAM,sBAAS,CAAC,YAAY,EAAE,CAAC;KAChC;IAED,gCAAgC;IAChC,MAAM,QAAQ,GAAG,IAAA,gCAAuB,EAAC,WAAW,CAAC,CAAC;IAEtD,sDAAsD;IACtD,MAAM,mBAAmB,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC5C,IAAI,CAAC,mBAAmB,EAAE;QACxB,MAAM,sBAAS,CAAC,YAAY,EAAE,CAAC;KAChC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,yBAAyB,CAAC,IAAY;IAC7C,MAAM,EAAE,MAAM,EAAE,EAAE,iBAAiB,EAAE,GAAG,EAAE,EAAE,GAAG,IAAA,6BAAiB,EAAC,IAAI,CAAC,CAAC;IACvE,sEAAsE;IACtE,iEAAiE;IACjE,IACE,iBAAiB;QAChB,iBAA4B,KAAK,QAAQ;QAC1C,CAAC,IAAA,yBAAiB,EAAC,iBAAiB,CAAC,EACrC;QACA,MAAM,sBAAS,CAAC,YAAY,EAAE,CAAC;KAChC;AACH,CAAC","sourcesContent":["import * as sigUtil from '@metamask/eth-sig-util';\nimport type {\n JsonRpcMiddleware,\n MiddlewareContext,\n MiddlewareParams,\n} from '@metamask/json-rpc-engine/v2';\nimport { createScaffoldMiddleware } from '@metamask/json-rpc-engine/v2';\nimport type { MessageRequest } from '@metamask/message-manager';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport { isValidHexAddress } from '@metamask/utils';\nimport type { JsonRpcRequest, Json, Hex } from '@metamask/utils';\n\nimport {\n createWalletRequestExecutionPermissionsHandler,\n type ProcessRequestExecutionPermissionsHook,\n} from './methods/wallet-request-execution-permissions';\nimport {\n type ProcessRevokeExecutionPermissionHook,\n createWalletRevokeExecutionPermissionHandler,\n} from './methods/wallet-revoke-execution-permission';\nimport { stripArrayTypeIfPresent } from './utils/common';\nimport { normalizeTypedMessage, parseTypedMessage } from './utils/normalize';\nimport {\n resemblesAddress,\n validateAndNormalizeKeyholder as validateKeyholder,\n} from './utils/validation';\n\nexport type TransactionParams = {\n from: string;\n};\n\nexport type MessageParams = TransactionParams & {\n data: string;\n signatureMethod?: string;\n};\n\nexport type TypedMessageParams = MessageParams & {\n version: string;\n};\n\nexport type TypedMessageV1Params = Omit<TypedMessageParams, 'data'> & {\n data: Record<string, unknown>[];\n};\n\nexport type WalletMiddlewareOptions = {\n getAccounts: (origin: string) => Promise<string[]>;\n processDecryptMessage?: (\n msgParams: MessageParams,\n req: MessageRequest,\n ) => Promise<string>;\n processEncryptionPublicKey?: (\n address: string,\n req: MessageRequest,\n ) => Promise<string>;\n processPersonalMessage?: (\n msgParams: MessageParams,\n req: JsonRpcRequest,\n context: WalletMiddlewareContext,\n ) => Promise<string>;\n processTransaction?: (\n txParams: TransactionParams,\n req: JsonRpcRequest,\n context: WalletMiddlewareContext,\n ) => Promise<string>;\n processSignTransaction?: (\n txParams: TransactionParams,\n req: JsonRpcRequest,\n context: WalletMiddlewareContext,\n ) => Promise<string>;\n processTypedMessage?: (\n msgParams: TypedMessageV1Params,\n req: JsonRpcRequest,\n context: WalletMiddlewareContext,\n version: string,\n ) => Promise<string>;\n processTypedMessageV3?: (\n msgParams: TypedMessageParams,\n req: JsonRpcRequest,\n context: WalletMiddlewareContext,\n version: string,\n ) => Promise<string>;\n processTypedMessageV4?: (\n msgParams: TypedMessageParams,\n req: JsonRpcRequest,\n context: WalletMiddlewareContext,\n version: string,\n ) => Promise<string>;\n processRequestExecutionPermissions?: ProcessRequestExecutionPermissionsHook;\n processRevokeExecutionPermission?: ProcessRevokeExecutionPermissionHook;\n};\n\nexport type WalletMiddlewareKeyValues = {\n networkClientId: string;\n origin: string;\n securityAlertResponse?: Record<string, Json>;\n traceContext?: unknown;\n};\n\nexport type WalletMiddlewareContext =\n MiddlewareContext<WalletMiddlewareKeyValues>;\n\nexport type WalletMiddlewareParams = MiddlewareParams<\n JsonRpcRequest,\n WalletMiddlewareContext\n>;\n\n/**\n * Creates a JSON-RPC middleware that handles \"wallet\"-related JSON-RPC methods.\n * \"Wallet\" may have had a specific meaning at some point in the distant past,\n * but at this point it's just an arbitrary label.\n *\n * @param options - The options for the middleware.\n * @param options.getAccounts - The function to get the accounts for the origin.\n * @param options.processDecryptMessage - The function to process the decrypt message request.\n * @param options.processEncryptionPublicKey - The function to process the encryption public key request.\n * @param options.processPersonalMessage - The function to process the personal message request.\n * @param options.processTransaction - The function to process the transaction request.\n * @param options.processSignTransaction - The function to process the sign transaction request.\n * @param options.processTypedMessage - The function to process the typed message request.\n * @param options.processTypedMessageV3 - The function to process the typed message v3 request.\n * @param options.processTypedMessageV4 - The function to process the typed message v4 request.\n * @param options.processRequestExecutionPermissions - The function to process the request execution permissions request.\n * @param options.processRevokeExecutionPermission - The function to process the revoke execution permission request.\n * @returns A JSON-RPC middleware that handles wallet-related JSON-RPC methods.\n */\nexport function createWalletMiddleware({\n getAccounts,\n processDecryptMessage,\n processEncryptionPublicKey,\n processPersonalMessage,\n processTransaction,\n processSignTransaction,\n processTypedMessage,\n processTypedMessageV3,\n processTypedMessageV4,\n processRequestExecutionPermissions,\n processRevokeExecutionPermission,\n}: WalletMiddlewareOptions): JsonRpcMiddleware<\n JsonRpcRequest,\n Json,\n WalletMiddlewareContext\n> {\n if (!getAccounts) {\n throw new Error('opts.getAccounts is required');\n }\n\n return createScaffoldMiddleware<WalletMiddlewareContext>({\n // account lookups\n eth_accounts: lookupAccounts,\n eth_coinbase: lookupDefaultAccount,\n\n // tx signatures\n eth_sendTransaction: sendTransaction,\n eth_signTransaction: signTransaction,\n\n // message signatures\n eth_signTypedData: signTypedData,\n eth_signTypedData_v3: signTypedDataV3,\n eth_signTypedData_v4: signTypedDataV4,\n personal_sign: personalSign,\n eth_getEncryptionPublicKey: encryptionPublicKey,\n eth_decrypt: decryptMessage,\n personal_ecRecover: personalRecover,\n\n // EIP-7715\n wallet_requestExecutionPermissions:\n createWalletRequestExecutionPermissionsHandler({\n processRequestExecutionPermissions,\n }),\n wallet_revokeExecutionPermission:\n createWalletRevokeExecutionPermissionHandler({\n processRevokeExecutionPermission,\n }),\n });\n\n //\n // account lookups\n //\n\n /**\n * Gets the accounts for the origin.\n *\n * @param options - Options bag.\n * @param options.context - The context of the request.\n * @returns The accounts for the origin.\n */\n async function lookupAccounts({\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n return await getAccounts(context.assertGet('origin'));\n }\n\n /**\n * Gets the default account (i.e. first in the list) for the origin.\n *\n * @param options - Options bag.\n * @param options.context - The context of the request.\n * @returns The default account for the origin.\n */\n async function lookupDefaultAccount({\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n const accounts = await getAccounts(context.assertGet('origin'));\n return accounts[0] || null;\n }\n\n //\n // transaction signatures\n //\n\n /**\n * Sends a transaction.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The transaction hash.\n */\n async function sendTransaction({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processTransaction) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 1)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params[0] as TransactionParams | undefined;\n const txParams: TransactionParams = {\n ...params,\n from: await validateAndNormalizeKeyholder(params?.from || '', context),\n };\n return await processTransaction(txParams, request, context);\n }\n\n /**\n * Signs a transaction.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The signed transaction.\n */\n async function signTransaction({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processSignTransaction) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 1)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params[0] as TransactionParams | undefined;\n const txParams: TransactionParams = {\n ...params,\n from: await validateAndNormalizeKeyholder(params?.from || '', context),\n };\n return await processSignTransaction(txParams, request, context);\n }\n\n //\n // message signatures\n //\n\n /**\n * Signs a `eth_signTypedData` message.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The signed message.\n */\n async function signTypedData({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processTypedMessage) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 2)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params as [\n Record<string, unknown>[],\n string,\n Record<string, string>?,\n ];\n const message = params[0];\n const address = await validateAndNormalizeKeyholder(params[1], context);\n const version = 'V1';\n const extraParams = params[2] || {};\n const msgParams: TypedMessageV1Params = {\n ...extraParams,\n from: address,\n data: message,\n signatureMethod: 'eth_signTypedData',\n version,\n };\n\n return await processTypedMessage(msgParams, request, context, version);\n }\n\n /**\n * Signs a `eth_signTypedData_v3` message.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The signed message.\n */\n async function signTypedDataV3({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processTypedMessageV3) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 2)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params as [string, string];\n\n const address = await validateAndNormalizeKeyholder(params[0], context);\n const message = normalizeTypedMessage(params[1]);\n validatePrimaryType(message);\n validateVerifyingContract(message);\n const version = 'V3';\n const msgParams: TypedMessageParams = {\n data: message,\n from: address,\n version,\n signatureMethod: 'eth_signTypedData_v3',\n };\n\n return await processTypedMessageV3(msgParams, request, context, version);\n }\n\n /**\n * Signs a `eth_signTypedData_v4` message.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The signed message.\n */\n async function signTypedDataV4({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processTypedMessageV4) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 2)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params as [string, string];\n\n const address = await validateAndNormalizeKeyholder(params[0], context);\n const message = normalizeTypedMessage(params[1]);\n validatePrimaryType(message);\n validateVerifyingContract(message);\n const version = 'V4';\n const msgParams: TypedMessageParams = {\n data: message,\n from: address,\n version,\n signatureMethod: 'eth_signTypedData_v4',\n };\n\n return await processTypedMessageV4(msgParams, request, context, version);\n }\n\n /**\n * Signs a `personal_sign` message.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The signed message.\n */\n async function personalSign({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processPersonalMessage) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 2)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params as [string, string, TransactionParams?];\n\n // process normally\n const firstParam = params[0];\n const secondParam = params[1];\n // non-standard \"extraParams\" to be appended to our \"msgParams\" obj\n const extraParams = params[2] || {};\n\n // We initially incorrectly ordered these parameters.\n // To gracefully respect users who adopted this API early,\n // we are currently gracefully recovering from the wrong param order\n // when it is clearly identifiable.\n //\n // That means when the first param is definitely an address,\n // and the second param is definitely not, but is hex.\n let address: string, message: string;\n if (resemblesAddress(firstParam) && !resemblesAddress(secondParam)) {\n address = firstParam;\n message = secondParam;\n } else {\n message = firstParam;\n address = secondParam;\n }\n address = await validateAndNormalizeKeyholder(address, context);\n\n const msgParams: MessageParams = {\n ...extraParams,\n from: address,\n data: message,\n signatureMethod: 'personal_sign',\n };\n\n return await processPersonalMessage(msgParams, request, context);\n }\n\n /**\n * Recovers the signer address from a `personal_sign` message.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @returns The recovered signer address.\n */\n async function personalRecover({\n request,\n }: WalletMiddlewareParams): Promise<Json> {\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 2)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params as [string, string];\n const message = params[0];\n const signature = params[1];\n const signerAddress = sigUtil.recoverPersonalSignature({\n data: message,\n signature,\n });\n\n return signerAddress;\n }\n\n /**\n * Gets the encryption public key for an address.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The encryption public key.\n */\n async function encryptionPublicKey({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processEncryptionPublicKey) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 1)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params as [string];\n\n const address = await validateAndNormalizeKeyholder(params[0], context);\n\n return await processEncryptionPublicKey(address, {\n id: request.id as string | number,\n origin: context.assertGet('origin'),\n securityAlertResponse: context.get('securityAlertResponse'),\n });\n }\n\n /**\n * Decrypts a message.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The decrypted message.\n */\n async function decryptMessage({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processDecryptMessage) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 1)\n ) {\n throw rpcErrors.invalidInput();\n }\n const params = request.params as [string, string, Record<string, Json>?];\n\n const ciphertext: string = params[0];\n const address: string = await validateAndNormalizeKeyholder(\n params[1],\n context,\n );\n const extraParams = params[2] || {};\n const msgParams: MessageParams = {\n ...extraParams,\n from: address,\n data: ciphertext,\n };\n\n return await processDecryptMessage(msgParams, {\n id: request.id as string | number,\n origin: context.assertGet('origin'),\n securityAlertResponse: context.get('securityAlertResponse'),\n });\n }\n\n //\n // utility\n //\n\n /**\n * Validates the keyholder address, and returns a normalized (i.e. lowercase)\n * copy of it.\n *\n * @param address - The address to validate and normalize.\n * @param context - The context of the request.\n * @returns The normalized address, if valid. Otherwise, throws\n * an error\n */\n async function validateAndNormalizeKeyholder(\n address: string,\n context: WalletMiddlewareContext,\n ): Promise<string> {\n return validateKeyholder(address as Hex, context, { getAccounts });\n }\n}\n\n/**\n * Validates primary of typedSignMessage, to ensure that it's type definition is present in message.\n *\n * @param data - The data passed in typedSign request.\n */\nfunction validatePrimaryType(data: string) {\n const { primaryType, types } = parseTypedMessage(data);\n if (!types) {\n throw rpcErrors.invalidInput();\n }\n\n // Primary type can be an array.\n const baseType = stripArrayTypeIfPresent(primaryType);\n\n // Return if the base type is not defined in the types\n const baseTypeDefinitions = types[baseType];\n if (!baseTypeDefinitions) {\n throw rpcErrors.invalidInput();\n }\n}\n\n/**\n * Validates verifyingContract of typedSignMessage.\n *\n * @param data - The data passed in typedSign request.\n * This function allows the verifyingContract to be either:\n * - A valid hex address\n * - The string \"cosmos\" (as it is hard-coded in some Cosmos ecosystem's EVM adapters)\n * - An empty string\n */\nfunction validateVerifyingContract(data: string) {\n const { domain: { verifyingContract } = {} } = parseTypedMessage(data);\n // Explicit check for cosmos here has been added to address this issue\n // https://github.com/MetaMask/eth-json-rpc-middleware/issues/337\n if (\n verifyingContract &&\n (verifyingContract as string) !== 'cosmos' &&\n !isValidHexAddress(verifyingContract)\n ) {\n throw rpcErrors.invalidInput();\n }\n}\n"]}
|
package/dist/wallet.mjs
CHANGED
|
@@ -316,7 +316,7 @@ export function createWalletMiddleware({ getAccounts, processDecryptMessage, pro
|
|
|
316
316
|
return await processEncryptionPublicKey(address, {
|
|
317
317
|
id: request.id,
|
|
318
318
|
origin: context.assertGet('origin'),
|
|
319
|
-
securityAlertResponse: context.
|
|
319
|
+
securityAlertResponse: context.get('securityAlertResponse'),
|
|
320
320
|
});
|
|
321
321
|
}
|
|
322
322
|
/**
|
|
@@ -348,7 +348,7 @@ export function createWalletMiddleware({ getAccounts, processDecryptMessage, pro
|
|
|
348
348
|
return await processDecryptMessage(msgParams, {
|
|
349
349
|
id: request.id,
|
|
350
350
|
origin: context.assertGet('origin'),
|
|
351
|
-
securityAlertResponse: context.
|
|
351
|
+
securityAlertResponse: context.get('securityAlertResponse'),
|
|
352
352
|
});
|
|
353
353
|
}
|
|
354
354
|
//
|
package/dist/wallet.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.mjs","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,+BAA+B;AAMlD,OAAO,EAAE,wBAAwB,EAAE,qCAAqC;AAExE,OAAO,EAAE,SAAS,EAAE,6BAA6B;AACjD,OAAO,EAAE,iBAAiB,EAAE,wBAAwB;AAGpD,OAAO,EACL,8CAA8C,EAE/C,2DAAuD;AACxD,OAAO,EAEL,4CAA4C,EAC7C,yDAAqD;AACtD,OAAO,EAAE,uBAAuB,EAAE,2BAAuB;AACzD,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,8BAA0B;AAC7E,OAAO,EACL,gBAAgB,EAChB,6BAA6B,IAAI,iBAAiB,EACnD,+BAA2B;AAiF5B;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,sBAAsB,CAAC,EACrC,WAAW,EACX,qBAAqB,EACrB,0BAA0B,EAC1B,sBAAsB,EACtB,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,kCAAkC,EAClC,gCAAgC,GACR;IAKxB,IAAI,CAAC,WAAW,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;KACjD;IAED,OAAO,wBAAwB,CAA0B;QACvD,kBAAkB;QAClB,YAAY,EAAE,cAAc;QAC5B,YAAY,EAAE,oBAA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QG;IACH,KAAK,UAAU,6BAA6B,CAC1C,OAAe,EACf,OAAgC;QAEhC,OAAO,iBAAiB,CAAC,OAAc,EAAE,OAAO,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;IACrE,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,mBAAmB,CAAC,IAAY;IACvC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACvD,IAAI,CAAC,KAAK,EAAE;QACV,MAAM,SAAS,CAAC,YAAY,EAAE,CAAC;KAChC;IAED,gCAAgC;IAChC,MAAM,QAAQ,GAAG,uBAAuB,CAAC,WAAW,CAAC,CAAC;IAEtD,sDAAsD;IACtD,MAAM,mBAAmB,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC5C,IAAI,CAAC,mBAAmB,EAAE;QACxB,MAAM,SAAS,CAAC,YAAY,EAAE,CAAC;KAChC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,yBAAyB,CAAC,IAAY;IAC7C,MAAM,EAAE,MAAM,EAAE,EAAE,iBAAiB,EAAE,GAAG,EAAE,EAAE,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACvE,sEAAsE;IACtE,iEAAiE;IACjE,IACE,iBAAiB;QAChB,iBAA4B,KAAK,QAAQ;QAC1C,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,EACrC;QACA,MAAM,SAAS,CAAC,YAAY,EAAE,CAAC;KAChC;AACH,CAAC","sourcesContent":["import * as sigUtil from '@metamask/eth-sig-util';\nimport type {\n JsonRpcMiddleware,\n MiddlewareContext,\n MiddlewareParams,\n} from '@metamask/json-rpc-engine/v2';\nimport { createScaffoldMiddleware } from '@metamask/json-rpc-engine/v2';\nimport type { MessageRequest } from '@metamask/message-manager';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport { isValidHexAddress } from '@metamask/utils';\nimport type { JsonRpcRequest, Json, Hex } from '@metamask/utils';\n\nimport {\n createWalletRequestExecutionPermissionsHandler,\n type ProcessRequestExecutionPermissionsHook,\n} from './methods/wallet-request-execution-permissions';\nimport {\n type ProcessRevokeExecutionPermissionHook,\n createWalletRevokeExecutionPermissionHandler,\n} from './methods/wallet-revoke-execution-permission';\nimport { stripArrayTypeIfPresent } from './utils/common';\nimport { normalizeTypedMessage, parseTypedMessage } from './utils/normalize';\nimport {\n resemblesAddress,\n validateAndNormalizeKeyholder as validateKeyholder,\n} from './utils/validation';\n\nexport type TransactionParams = {\n from: string;\n};\n\nexport type MessageParams = TransactionParams & {\n data: string;\n signatureMethod?: string;\n};\n\nexport type TypedMessageParams = MessageParams & {\n version: string;\n};\n\nexport type TypedMessageV1Params = Omit<TypedMessageParams, 'data'> & {\n data: Record<string, unknown>[];\n};\n\nexport type WalletMiddlewareOptions = {\n getAccounts: (origin: string) => Promise<string[]>;\n processDecryptMessage?: (\n msgParams: MessageParams,\n req: MessageRequest,\n ) => Promise<string>;\n processEncryptionPublicKey?: (\n address: string,\n req: MessageRequest,\n ) => Promise<string>;\n processPersonalMessage?: (\n msgParams: MessageParams,\n req: JsonRpcRequest,\n context: WalletMiddlewareContext,\n ) => Promise<string>;\n processTransaction?: (\n txParams: TransactionParams,\n req: JsonRpcRequest,\n context: WalletMiddlewareContext,\n ) => Promise<string>;\n processSignTransaction?: (\n txParams: TransactionParams,\n req: JsonRpcRequest,\n context: WalletMiddlewareContext,\n ) => Promise<string>;\n processTypedMessage?: (\n msgParams: TypedMessageV1Params,\n req: JsonRpcRequest,\n context: WalletMiddlewareContext,\n version: string,\n ) => Promise<string>;\n processTypedMessageV3?: (\n msgParams: TypedMessageParams,\n req: JsonRpcRequest,\n context: WalletMiddlewareContext,\n version: string,\n ) => Promise<string>;\n processTypedMessageV4?: (\n msgParams: TypedMessageParams,\n req: JsonRpcRequest,\n context: WalletMiddlewareContext,\n version: string,\n ) => Promise<string>;\n processRequestExecutionPermissions?: ProcessRequestExecutionPermissionsHook;\n processRevokeExecutionPermission?: ProcessRevokeExecutionPermissionHook;\n};\n\nexport type WalletMiddlewareKeyValues = {\n networkClientId: string;\n origin: string;\n securityAlertResponse?: Record<string, Json>;\n traceContext?: unknown;\n};\n\nexport type WalletMiddlewareContext =\n MiddlewareContext<WalletMiddlewareKeyValues>;\n\nexport type WalletMiddlewareParams = MiddlewareParams<\n JsonRpcRequest,\n WalletMiddlewareContext\n>;\n\n/**\n * Creates a JSON-RPC middleware that handles \"wallet\"-related JSON-RPC methods.\n * \"Wallet\" may have had a specific meaning at some point in the distant past,\n * but at this point it's just an arbitrary label.\n *\n * @param options - The options for the middleware.\n * @param options.getAccounts - The function to get the accounts for the origin.\n * @param options.processDecryptMessage - The function to process the decrypt message request.\n * @param options.processEncryptionPublicKey - The function to process the encryption public key request.\n * @param options.processPersonalMessage - The function to process the personal message request.\n * @param options.processTransaction - The function to process the transaction request.\n * @param options.processSignTransaction - The function to process the sign transaction request.\n * @param options.processTypedMessage - The function to process the typed message request.\n * @param options.processTypedMessageV3 - The function to process the typed message v3 request.\n * @param options.processTypedMessageV4 - The function to process the typed message v4 request.\n * @param options.processRequestExecutionPermissions - The function to process the request execution permissions request.\n * @param options.processRevokeExecutionPermission - The function to process the revoke execution permission request.\n * @returns A JSON-RPC middleware that handles wallet-related JSON-RPC methods.\n */\nexport function createWalletMiddleware({\n getAccounts,\n processDecryptMessage,\n processEncryptionPublicKey,\n processPersonalMessage,\n processTransaction,\n processSignTransaction,\n processTypedMessage,\n processTypedMessageV3,\n processTypedMessageV4,\n processRequestExecutionPermissions,\n processRevokeExecutionPermission,\n}: WalletMiddlewareOptions): JsonRpcMiddleware<\n JsonRpcRequest,\n Json,\n WalletMiddlewareContext\n> {\n if (!getAccounts) {\n throw new Error('opts.getAccounts is required');\n }\n\n return createScaffoldMiddleware<WalletMiddlewareContext>({\n // account lookups\n eth_accounts: lookupAccounts,\n eth_coinbase: lookupDefaultAccount,\n\n // tx signatures\n eth_sendTransaction: sendTransaction,\n eth_signTransaction: signTransaction,\n\n // message signatures\n eth_signTypedData: signTypedData,\n eth_signTypedData_v3: signTypedDataV3,\n eth_signTypedData_v4: signTypedDataV4,\n personal_sign: personalSign,\n eth_getEncryptionPublicKey: encryptionPublicKey,\n eth_decrypt: decryptMessage,\n personal_ecRecover: personalRecover,\n\n // EIP-7715\n wallet_requestExecutionPermissions:\n createWalletRequestExecutionPermissionsHandler({\n processRequestExecutionPermissions,\n }),\n wallet_revokeExecutionPermission:\n createWalletRevokeExecutionPermissionHandler({\n processRevokeExecutionPermission,\n }),\n });\n\n //\n // account lookups\n //\n\n /**\n * Gets the accounts for the origin.\n *\n * @param options - Options bag.\n * @param options.context - The context of the request.\n * @returns The accounts for the origin.\n */\n async function lookupAccounts({\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n return await getAccounts(context.assertGet('origin'));\n }\n\n /**\n * Gets the default account (i.e. first in the list) for the origin.\n *\n * @param options - Options bag.\n * @param options.context - The context of the request.\n * @returns The default account for the origin.\n */\n async function lookupDefaultAccount({\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n const accounts = await getAccounts(context.assertGet('origin'));\n return accounts[0] || null;\n }\n\n //\n // transaction signatures\n //\n\n /**\n * Sends a transaction.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The transaction hash.\n */\n async function sendTransaction({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processTransaction) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 1)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params[0] as TransactionParams | undefined;\n const txParams: TransactionParams = {\n ...params,\n from: await validateAndNormalizeKeyholder(params?.from || '', context),\n };\n return await processTransaction(txParams, request, context);\n }\n\n /**\n * Signs a transaction.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The signed transaction.\n */\n async function signTransaction({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processSignTransaction) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 1)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params[0] as TransactionParams | undefined;\n const txParams: TransactionParams = {\n ...params,\n from: await validateAndNormalizeKeyholder(params?.from || '', context),\n };\n return await processSignTransaction(txParams, request, context);\n }\n\n //\n // message signatures\n //\n\n /**\n * Signs a `eth_signTypedData` message.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The signed message.\n */\n async function signTypedData({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processTypedMessage) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 2)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params as [\n Record<string, unknown>[],\n string,\n Record<string, string>?,\n ];\n const message = params[0];\n const address = await validateAndNormalizeKeyholder(params[1], context);\n const version = 'V1';\n const extraParams = params[2] || {};\n const msgParams: TypedMessageV1Params = {\n ...extraParams,\n from: address,\n data: message,\n signatureMethod: 'eth_signTypedData',\n version,\n };\n\n return await processTypedMessage(msgParams, request, context, version);\n }\n\n /**\n * Signs a `eth_signTypedData_v3` message.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The signed message.\n */\n async function signTypedDataV3({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processTypedMessageV3) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 2)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params as [string, string];\n\n const address = await validateAndNormalizeKeyholder(params[0], context);\n const message = normalizeTypedMessage(params[1]);\n validatePrimaryType(message);\n validateVerifyingContract(message);\n const version = 'V3';\n const msgParams: TypedMessageParams = {\n data: message,\n from: address,\n version,\n signatureMethod: 'eth_signTypedData_v3',\n };\n\n return await processTypedMessageV3(msgParams, request, context, version);\n }\n\n /**\n * Signs a `eth_signTypedData_v4` message.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The signed message.\n */\n async function signTypedDataV4({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processTypedMessageV4) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 2)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params as [string, string];\n\n const address = await validateAndNormalizeKeyholder(params[0], context);\n const message = normalizeTypedMessage(params[1]);\n validatePrimaryType(message);\n validateVerifyingContract(message);\n const version = 'V4';\n const msgParams: TypedMessageParams = {\n data: message,\n from: address,\n version,\n signatureMethod: 'eth_signTypedData_v4',\n };\n\n return await processTypedMessageV4(msgParams, request, context, version);\n }\n\n /**\n * Signs a `personal_sign` message.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The signed message.\n */\n async function personalSign({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processPersonalMessage) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 2)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params as [string, string, TransactionParams?];\n\n // process normally\n const firstParam = params[0];\n const secondParam = params[1];\n // non-standard \"extraParams\" to be appended to our \"msgParams\" obj\n const extraParams = params[2] || {};\n\n // We initially incorrectly ordered these parameters.\n // To gracefully respect users who adopted this API early,\n // we are currently gracefully recovering from the wrong param order\n // when it is clearly identifiable.\n //\n // That means when the first param is definitely an address,\n // and the second param is definitely not, but is hex.\n let address: string, message: string;\n if (resemblesAddress(firstParam) && !resemblesAddress(secondParam)) {\n address = firstParam;\n message = secondParam;\n } else {\n message = firstParam;\n address = secondParam;\n }\n address = await validateAndNormalizeKeyholder(address, context);\n\n const msgParams: MessageParams = {\n ...extraParams,\n from: address,\n data: message,\n signatureMethod: 'personal_sign',\n };\n\n return await processPersonalMessage(msgParams, request, context);\n }\n\n /**\n * Recovers the signer address from a `personal_sign` message.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @returns The recovered signer address.\n */\n async function personalRecover({\n request,\n }: WalletMiddlewareParams): Promise<Json> {\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 2)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params as [string, string];\n const message = params[0];\n const signature = params[1];\n const signerAddress = sigUtil.recoverPersonalSignature({\n data: message,\n signature,\n });\n\n return signerAddress;\n }\n\n /**\n * Gets the encryption public key for an address.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The encryption public key.\n */\n async function encryptionPublicKey({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processEncryptionPublicKey) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 1)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params as [string];\n\n const address = await validateAndNormalizeKeyholder(params[0], context);\n\n return await processEncryptionPublicKey(address, {\n id: request.id as string | number,\n origin: context.assertGet('origin'),\n securityAlertResponse: context.assertGet('securityAlertResponse'),\n });\n }\n\n /**\n * Decrypts a message.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The decrypted message.\n */\n async function decryptMessage({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processDecryptMessage) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 1)\n ) {\n throw rpcErrors.invalidInput();\n }\n const params = request.params as [string, string, Record<string, Json>?];\n\n const ciphertext: string = params[0];\n const address: string = await validateAndNormalizeKeyholder(\n params[1],\n context,\n );\n const extraParams = params[2] || {};\n const msgParams: MessageParams = {\n ...extraParams,\n from: address,\n data: ciphertext,\n };\n\n return await processDecryptMessage(msgParams, {\n id: request.id as string | number,\n origin: context.assertGet('origin'),\n securityAlertResponse: context.assertGet('securityAlertResponse'),\n });\n }\n\n //\n // utility\n //\n\n /**\n * Validates the keyholder address, and returns a normalized (i.e. lowercase)\n * copy of it.\n *\n * @param address - The address to validate and normalize.\n * @param context - The context of the request.\n * @returns The normalized address, if valid. Otherwise, throws\n * an error\n */\n async function validateAndNormalizeKeyholder(\n address: string,\n context: WalletMiddlewareContext,\n ): Promise<string> {\n return validateKeyholder(address as Hex, context, { getAccounts });\n }\n}\n\n/**\n * Validates primary of typedSignMessage, to ensure that it's type definition is present in message.\n *\n * @param data - The data passed in typedSign request.\n */\nfunction validatePrimaryType(data: string) {\n const { primaryType, types } = parseTypedMessage(data);\n if (!types) {\n throw rpcErrors.invalidInput();\n }\n\n // Primary type can be an array.\n const baseType = stripArrayTypeIfPresent(primaryType);\n\n // Return if the base type is not defined in the types\n const baseTypeDefinitions = types[baseType];\n if (!baseTypeDefinitions) {\n throw rpcErrors.invalidInput();\n }\n}\n\n/**\n * Validates verifyingContract of typedSignMessage.\n *\n * @param data - The data passed in typedSign request.\n * This function allows the verifyingContract to be either:\n * - A valid hex address\n * - The string \"cosmos\" (as it is hard-coded in some Cosmos ecosystem's EVM adapters)\n * - An empty string\n */\nfunction validateVerifyingContract(data: string) {\n const { domain: { verifyingContract } = {} } = parseTypedMessage(data);\n // Explicit check for cosmos here has been added to address this issue\n // https://github.com/MetaMask/eth-json-rpc-middleware/issues/337\n if (\n verifyingContract &&\n (verifyingContract as string) !== 'cosmos' &&\n !isValidHexAddress(verifyingContract)\n ) {\n throw rpcErrors.invalidInput();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"wallet.mjs","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,+BAA+B;AAMlD,OAAO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AmB,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC5C,IAAI,CAAC,mBAAmB,EAAE;QACxB,MAAM,SAAS,CAAC,YAAY,EAAE,CAAC;KAChC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,yBAAyB,CAAC,IAAY;IAC7C,MAAM,EAAE,MAAM,EAAE,EAAE,iBAAiB,EAAE,GAAG,EAAE,EAAE,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACvE,sEAAsE;IACtE,iEAAiE;IACjE,IACE,iBAAiB;QAChB,iBAA4B,KAAK,QAAQ;QAC1C,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,EACrC;QACA,MAAM,SAAS,CAAC,YAAY,EAAE,CAAC;KAChC;AACH,CAAC","sourcesContent":["import * as sigUtil from '@metamask/eth-sig-util';\nimport type {\n JsonRpcMiddleware,\n MiddlewareContext,\n MiddlewareParams,\n} from '@metamask/json-rpc-engine/v2';\nimport { createScaffoldMiddleware } from '@metamask/json-rpc-engine/v2';\nimport type { MessageRequest } from '@metamask/message-manager';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport { isValidHexAddress } from '@metamask/utils';\nimport type { JsonRpcRequest, Json, Hex } from '@metamask/utils';\n\nimport {\n createWalletRequestExecutionPermissionsHandler,\n type ProcessRequestExecutionPermissionsHook,\n} from './methods/wallet-request-execution-permissions';\nimport {\n type ProcessRevokeExecutionPermissionHook,\n createWalletRevokeExecutionPermissionHandler,\n} from './methods/wallet-revoke-execution-permission';\nimport { stripArrayTypeIfPresent } from './utils/common';\nimport { normalizeTypedMessage, parseTypedMessage } from './utils/normalize';\nimport {\n resemblesAddress,\n validateAndNormalizeKeyholder as validateKeyholder,\n} from './utils/validation';\n\nexport type TransactionParams = {\n from: string;\n};\n\nexport type MessageParams = TransactionParams & {\n data: string;\n signatureMethod?: string;\n};\n\nexport type TypedMessageParams = MessageParams & {\n version: string;\n};\n\nexport type TypedMessageV1Params = Omit<TypedMessageParams, 'data'> & {\n data: Record<string, unknown>[];\n};\n\nexport type WalletMiddlewareOptions = {\n getAccounts: (origin: string) => Promise<string[]>;\n processDecryptMessage?: (\n msgParams: MessageParams,\n req: MessageRequest,\n ) => Promise<string>;\n processEncryptionPublicKey?: (\n address: string,\n req: MessageRequest,\n ) => Promise<string>;\n processPersonalMessage?: (\n msgParams: MessageParams,\n req: JsonRpcRequest,\n context: WalletMiddlewareContext,\n ) => Promise<string>;\n processTransaction?: (\n txParams: TransactionParams,\n req: JsonRpcRequest,\n context: WalletMiddlewareContext,\n ) => Promise<string>;\n processSignTransaction?: (\n txParams: TransactionParams,\n req: JsonRpcRequest,\n context: WalletMiddlewareContext,\n ) => Promise<string>;\n processTypedMessage?: (\n msgParams: TypedMessageV1Params,\n req: JsonRpcRequest,\n context: WalletMiddlewareContext,\n version: string,\n ) => Promise<string>;\n processTypedMessageV3?: (\n msgParams: TypedMessageParams,\n req: JsonRpcRequest,\n context: WalletMiddlewareContext,\n version: string,\n ) => Promise<string>;\n processTypedMessageV4?: (\n msgParams: TypedMessageParams,\n req: JsonRpcRequest,\n context: WalletMiddlewareContext,\n version: string,\n ) => Promise<string>;\n processRequestExecutionPermissions?: ProcessRequestExecutionPermissionsHook;\n processRevokeExecutionPermission?: ProcessRevokeExecutionPermissionHook;\n};\n\nexport type WalletMiddlewareKeyValues = {\n networkClientId: string;\n origin: string;\n securityAlertResponse?: Record<string, Json>;\n traceContext?: unknown;\n};\n\nexport type WalletMiddlewareContext =\n MiddlewareContext<WalletMiddlewareKeyValues>;\n\nexport type WalletMiddlewareParams = MiddlewareParams<\n JsonRpcRequest,\n WalletMiddlewareContext\n>;\n\n/**\n * Creates a JSON-RPC middleware that handles \"wallet\"-related JSON-RPC methods.\n * \"Wallet\" may have had a specific meaning at some point in the distant past,\n * but at this point it's just an arbitrary label.\n *\n * @param options - The options for the middleware.\n * @param options.getAccounts - The function to get the accounts for the origin.\n * @param options.processDecryptMessage - The function to process the decrypt message request.\n * @param options.processEncryptionPublicKey - The function to process the encryption public key request.\n * @param options.processPersonalMessage - The function to process the personal message request.\n * @param options.processTransaction - The function to process the transaction request.\n * @param options.processSignTransaction - The function to process the sign transaction request.\n * @param options.processTypedMessage - The function to process the typed message request.\n * @param options.processTypedMessageV3 - The function to process the typed message v3 request.\n * @param options.processTypedMessageV4 - The function to process the typed message v4 request.\n * @param options.processRequestExecutionPermissions - The function to process the request execution permissions request.\n * @param options.processRevokeExecutionPermission - The function to process the revoke execution permission request.\n * @returns A JSON-RPC middleware that handles wallet-related JSON-RPC methods.\n */\nexport function createWalletMiddleware({\n getAccounts,\n processDecryptMessage,\n processEncryptionPublicKey,\n processPersonalMessage,\n processTransaction,\n processSignTransaction,\n processTypedMessage,\n processTypedMessageV3,\n processTypedMessageV4,\n processRequestExecutionPermissions,\n processRevokeExecutionPermission,\n}: WalletMiddlewareOptions): JsonRpcMiddleware<\n JsonRpcRequest,\n Json,\n WalletMiddlewareContext\n> {\n if (!getAccounts) {\n throw new Error('opts.getAccounts is required');\n }\n\n return createScaffoldMiddleware<WalletMiddlewareContext>({\n // account lookups\n eth_accounts: lookupAccounts,\n eth_coinbase: lookupDefaultAccount,\n\n // tx signatures\n eth_sendTransaction: sendTransaction,\n eth_signTransaction: signTransaction,\n\n // message signatures\n eth_signTypedData: signTypedData,\n eth_signTypedData_v3: signTypedDataV3,\n eth_signTypedData_v4: signTypedDataV4,\n personal_sign: personalSign,\n eth_getEncryptionPublicKey: encryptionPublicKey,\n eth_decrypt: decryptMessage,\n personal_ecRecover: personalRecover,\n\n // EIP-7715\n wallet_requestExecutionPermissions:\n createWalletRequestExecutionPermissionsHandler({\n processRequestExecutionPermissions,\n }),\n wallet_revokeExecutionPermission:\n createWalletRevokeExecutionPermissionHandler({\n processRevokeExecutionPermission,\n }),\n });\n\n //\n // account lookups\n //\n\n /**\n * Gets the accounts for the origin.\n *\n * @param options - Options bag.\n * @param options.context - The context of the request.\n * @returns The accounts for the origin.\n */\n async function lookupAccounts({\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n return await getAccounts(context.assertGet('origin'));\n }\n\n /**\n * Gets the default account (i.e. first in the list) for the origin.\n *\n * @param options - Options bag.\n * @param options.context - The context of the request.\n * @returns The default account for the origin.\n */\n async function lookupDefaultAccount({\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n const accounts = await getAccounts(context.assertGet('origin'));\n return accounts[0] || null;\n }\n\n //\n // transaction signatures\n //\n\n /**\n * Sends a transaction.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The transaction hash.\n */\n async function sendTransaction({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processTransaction) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 1)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params[0] as TransactionParams | undefined;\n const txParams: TransactionParams = {\n ...params,\n from: await validateAndNormalizeKeyholder(params?.from || '', context),\n };\n return await processTransaction(txParams, request, context);\n }\n\n /**\n * Signs a transaction.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The signed transaction.\n */\n async function signTransaction({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processSignTransaction) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 1)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params[0] as TransactionParams | undefined;\n const txParams: TransactionParams = {\n ...params,\n from: await validateAndNormalizeKeyholder(params?.from || '', context),\n };\n return await processSignTransaction(txParams, request, context);\n }\n\n //\n // message signatures\n //\n\n /**\n * Signs a `eth_signTypedData` message.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The signed message.\n */\n async function signTypedData({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processTypedMessage) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 2)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params as [\n Record<string, unknown>[],\n string,\n Record<string, string>?,\n ];\n const message = params[0];\n const address = await validateAndNormalizeKeyholder(params[1], context);\n const version = 'V1';\n const extraParams = params[2] || {};\n const msgParams: TypedMessageV1Params = {\n ...extraParams,\n from: address,\n data: message,\n signatureMethod: 'eth_signTypedData',\n version,\n };\n\n return await processTypedMessage(msgParams, request, context, version);\n }\n\n /**\n * Signs a `eth_signTypedData_v3` message.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The signed message.\n */\n async function signTypedDataV3({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processTypedMessageV3) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 2)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params as [string, string];\n\n const address = await validateAndNormalizeKeyholder(params[0], context);\n const message = normalizeTypedMessage(params[1]);\n validatePrimaryType(message);\n validateVerifyingContract(message);\n const version = 'V3';\n const msgParams: TypedMessageParams = {\n data: message,\n from: address,\n version,\n signatureMethod: 'eth_signTypedData_v3',\n };\n\n return await processTypedMessageV3(msgParams, request, context, version);\n }\n\n /**\n * Signs a `eth_signTypedData_v4` message.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The signed message.\n */\n async function signTypedDataV4({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processTypedMessageV4) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 2)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params as [string, string];\n\n const address = await validateAndNormalizeKeyholder(params[0], context);\n const message = normalizeTypedMessage(params[1]);\n validatePrimaryType(message);\n validateVerifyingContract(message);\n const version = 'V4';\n const msgParams: TypedMessageParams = {\n data: message,\n from: address,\n version,\n signatureMethod: 'eth_signTypedData_v4',\n };\n\n return await processTypedMessageV4(msgParams, request, context, version);\n }\n\n /**\n * Signs a `personal_sign` message.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The signed message.\n */\n async function personalSign({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processPersonalMessage) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 2)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params as [string, string, TransactionParams?];\n\n // process normally\n const firstParam = params[0];\n const secondParam = params[1];\n // non-standard \"extraParams\" to be appended to our \"msgParams\" obj\n const extraParams = params[2] || {};\n\n // We initially incorrectly ordered these parameters.\n // To gracefully respect users who adopted this API early,\n // we are currently gracefully recovering from the wrong param order\n // when it is clearly identifiable.\n //\n // That means when the first param is definitely an address,\n // and the second param is definitely not, but is hex.\n let address: string, message: string;\n if (resemblesAddress(firstParam) && !resemblesAddress(secondParam)) {\n address = firstParam;\n message = secondParam;\n } else {\n message = firstParam;\n address = secondParam;\n }\n address = await validateAndNormalizeKeyholder(address, context);\n\n const msgParams: MessageParams = {\n ...extraParams,\n from: address,\n data: message,\n signatureMethod: 'personal_sign',\n };\n\n return await processPersonalMessage(msgParams, request, context);\n }\n\n /**\n * Recovers the signer address from a `personal_sign` message.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @returns The recovered signer address.\n */\n async function personalRecover({\n request,\n }: WalletMiddlewareParams): Promise<Json> {\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 2)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params as [string, string];\n const message = params[0];\n const signature = params[1];\n const signerAddress = sigUtil.recoverPersonalSignature({\n data: message,\n signature,\n });\n\n return signerAddress;\n }\n\n /**\n * Gets the encryption public key for an address.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The encryption public key.\n */\n async function encryptionPublicKey({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processEncryptionPublicKey) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 1)\n ) {\n throw rpcErrors.invalidInput();\n }\n\n const params = request.params as [string];\n\n const address = await validateAndNormalizeKeyholder(params[0], context);\n\n return await processEncryptionPublicKey(address, {\n id: request.id as string | number,\n origin: context.assertGet('origin'),\n securityAlertResponse: context.get('securityAlertResponse'),\n });\n }\n\n /**\n * Decrypts a message.\n *\n * @param options - Options bag.\n * @param options.request - The request.\n * @param options.context - The context of the request.\n * @returns The decrypted message.\n */\n async function decryptMessage({\n request,\n context,\n }: WalletMiddlewareParams): Promise<Json> {\n if (!processDecryptMessage) {\n throw rpcErrors.methodNotSupported();\n }\n if (\n !request.params ||\n !Array.isArray(request.params) ||\n !(request.params.length >= 1)\n ) {\n throw rpcErrors.invalidInput();\n }\n const params = request.params as [string, string, Record<string, Json>?];\n\n const ciphertext: string = params[0];\n const address: string = await validateAndNormalizeKeyholder(\n params[1],\n context,\n );\n const extraParams = params[2] || {};\n const msgParams: MessageParams = {\n ...extraParams,\n from: address,\n data: ciphertext,\n };\n\n return await processDecryptMessage(msgParams, {\n id: request.id as string | number,\n origin: context.assertGet('origin'),\n securityAlertResponse: context.get('securityAlertResponse'),\n });\n }\n\n //\n // utility\n //\n\n /**\n * Validates the keyholder address, and returns a normalized (i.e. lowercase)\n * copy of it.\n *\n * @param address - The address to validate and normalize.\n * @param context - The context of the request.\n * @returns The normalized address, if valid. Otherwise, throws\n * an error\n */\n async function validateAndNormalizeKeyholder(\n address: string,\n context: WalletMiddlewareContext,\n ): Promise<string> {\n return validateKeyholder(address as Hex, context, { getAccounts });\n }\n}\n\n/**\n * Validates primary of typedSignMessage, to ensure that it's type definition is present in message.\n *\n * @param data - The data passed in typedSign request.\n */\nfunction validatePrimaryType(data: string) {\n const { primaryType, types } = parseTypedMessage(data);\n if (!types) {\n throw rpcErrors.invalidInput();\n }\n\n // Primary type can be an array.\n const baseType = stripArrayTypeIfPresent(primaryType);\n\n // Return if the base type is not defined in the types\n const baseTypeDefinitions = types[baseType];\n if (!baseTypeDefinitions) {\n throw rpcErrors.invalidInput();\n }\n}\n\n/**\n * Validates verifyingContract of typedSignMessage.\n *\n * @param data - The data passed in typedSign request.\n * This function allows the verifyingContract to be either:\n * - A valid hex address\n * - The string \"cosmos\" (as it is hard-coded in some Cosmos ecosystem's EVM adapters)\n * - An empty string\n */\nfunction validateVerifyingContract(data: string) {\n const { domain: { verifyingContract } = {} } = parseTypedMessage(data);\n // Explicit check for cosmos here has been added to address this issue\n // https://github.com/MetaMask/eth-json-rpc-middleware/issues/337\n if (\n verifyingContract &&\n (verifyingContract as string) !== 'cosmos' &&\n !isValidHexAddress(verifyingContract)\n ) {\n throw rpcErrors.invalidInput();\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/eth-json-rpc-middleware",
|
|
3
|
-
"version": "21.0.0-preview-
|
|
3
|
+
"version": "21.0.0-preview-5a558267",
|
|
4
4
|
"description": "Ethereum-related json-rpc-engine middleware",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -72,8 +72,10 @@
|
|
|
72
72
|
"@metamask/error-reporting-service": "^3.0.0",
|
|
73
73
|
"@metamask/network-controller": "^25.0.0",
|
|
74
74
|
"@ts-bridge/cli": "^0.6.4",
|
|
75
|
+
"@types/deep-freeze-strict": "^1.1.0",
|
|
75
76
|
"@types/jest": "^27.4.1",
|
|
76
77
|
"@types/pify": "^5.0.2",
|
|
78
|
+
"deep-freeze-strict": "^1.1.1",
|
|
77
79
|
"deepmerge": "^4.2.2",
|
|
78
80
|
"jest": "^27.5.1",
|
|
79
81
|
"tsd": "^0.31.2",
|