@dynamic-labs-wallet/evm 1.0.18 → 1.0.19

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/index.cjs CHANGED
@@ -36,7 +36,32 @@ const formatEVMMessage = (message_, logger)=>{
36
36
  }
37
37
  };
38
38
  const formatTypedData = (typedData)=>{
39
- return viem.hashTypedData(typedData).slice(2);
39
+ try {
40
+ return viem.hashTypedData(typedData).slice(2);
41
+ } catch (error) {
42
+ // hashTypedData throws opaque errors (e.g. "Cannot read properties of
43
+ // undefined (reading 'length')") when `message` doesn't match `types`.
44
+ // Re-throw with a clear, actionable message identifying the typedData as
45
+ // the cause. Two cases:
46
+ // 1) format issues (bad address, int out of range, wrong bytes size,
47
+ // invalid primaryType/struct) -> viem's validateTypedData pinpoints it.
48
+ // 2) a field declared in `types` is missing/undefined in `message`
49
+ // (incl. primitive `string`/`bytes`) -> validateTypedData does NOT
50
+ // flag this, so we surface it explicitly here.
51
+ const primaryType = typedData.primaryType;
52
+ try {
53
+ viem.validateTypedData(typedData);
54
+ } catch (validationError) {
55
+ throw Object.assign(new Error(`Invalid EIP-712 typedData: ${validationError.message}`), {
56
+ cause: error
57
+ });
58
+ }
59
+ const primaryTypeSuffix = primaryType ? ` (primaryType "${primaryType}")` : '';
60
+ const message = `Invalid EIP-712 typedData: a field declared in \`types\` is missing or ` + `undefined in \`message\`${primaryTypeSuffix}. ` + `Every field declared in \`types\` must be present in \`message\`. ` + `Underlying error: ${error.message}`;
61
+ throw Object.assign(new Error(message), {
62
+ cause: error
63
+ });
64
+ }
40
65
  };
41
66
  const serializeECDSASignature = (signature, logger)=>{
42
67
  try {
package/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { EcdsaPublicKey, DynamicWalletClient, getMPCChainConfig, ERROR_CREATE_WALLET_ACCOUNT, ERROR_KEYGEN_FAILED, ERROR_PASSWORD_MISMATCH, ERROR_ACCOUNT_ADDRESS_REQUIRED, ERROR_SIGN_MESSAGE, ERROR_VERIFY_MESSAGE_SIGNATURE, ERROR_SIGN_TYPED_DATA, MessageHash, ERROR_IMPORT_PRIVATE_KEY, AuthMode } from '@dynamic-labs-wallet/browser';
2
- import { stringToHex, bytesToHex, size, concat, serializeSignature, hashTypedData, createPublicClient, http, getAddress, serializeTransaction } from 'viem';
2
+ import { stringToHex, bytesToHex, size, concat, serializeSignature, hashTypedData, validateTypedData, createPublicClient, http, getAddress, serializeTransaction } from 'viem';
3
3
  import { privateKeyToAccount } from 'viem/accounts';
4
4
  import { mainnet } from 'viem/chains';
5
5
 
@@ -34,7 +34,32 @@ const formatEVMMessage = (message_, logger)=>{
34
34
  }
35
35
  };
36
36
  const formatTypedData = (typedData)=>{
37
- return hashTypedData(typedData).slice(2);
37
+ try {
38
+ return hashTypedData(typedData).slice(2);
39
+ } catch (error) {
40
+ // hashTypedData throws opaque errors (e.g. "Cannot read properties of
41
+ // undefined (reading 'length')") when `message` doesn't match `types`.
42
+ // Re-throw with a clear, actionable message identifying the typedData as
43
+ // the cause. Two cases:
44
+ // 1) format issues (bad address, int out of range, wrong bytes size,
45
+ // invalid primaryType/struct) -> viem's validateTypedData pinpoints it.
46
+ // 2) a field declared in `types` is missing/undefined in `message`
47
+ // (incl. primitive `string`/`bytes`) -> validateTypedData does NOT
48
+ // flag this, so we surface it explicitly here.
49
+ const primaryType = typedData.primaryType;
50
+ try {
51
+ validateTypedData(typedData);
52
+ } catch (validationError) {
53
+ throw Object.assign(new Error(`Invalid EIP-712 typedData: ${validationError.message}`), {
54
+ cause: error
55
+ });
56
+ }
57
+ const primaryTypeSuffix = primaryType ? ` (primaryType "${primaryType}")` : '';
58
+ const message = `Invalid EIP-712 typedData: a field declared in \`types\` is missing or ` + `undefined in \`message\`${primaryTypeSuffix}. ` + `Every field declared in \`types\` must be present in \`message\`. ` + `Underlying error: ${error.message}`;
59
+ throw Object.assign(new Error(message), {
60
+ cause: error
61
+ });
62
+ }
38
63
  };
39
64
  const serializeECDSASignature = (signature, logger)=>{
40
65
  try {
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@dynamic-labs-wallet/evm",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "dependencies": {
7
- "@dynamic-labs-wallet/browser": "1.0.18",
8
- "@dynamic-labs-wallet/core": "1.0.18",
7
+ "@dynamic-labs-wallet/browser": "1.0.19",
8
+ "@dynamic-labs-wallet/core": "1.0.19",
9
9
  "@dynamic-labs/sdk-api-core": "^0.0.984",
10
10
  "@faker-js/faker": "^9.5.0"
11
11
  },
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../packages/src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EAA2B,SAAS,EAAE,MAAM,MAAM,CAAC;AAI/D,eAAO,MAAM,gBAAgB,aAAc,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;CAAE,UAAU,OAAO,kBAahG,CAAC;AAEF,eAAO,MAAM,eAAe,cAAe,SAAS,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,WAEhF,CAAC;AAEF,eAAO,MAAM,uBAAuB,cAAe,cAAc,UAAU,OAAO,kBAWjF,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../packages/src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EAA2B,SAAS,EAAE,MAAM,MAAM,CAAC;AAI/D,eAAO,MAAM,gBAAgB,aAAc,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;CAAE,UAAU,OAAO,kBAahG,CAAC;AAEF,eAAO,MAAM,eAAe,cAAe,SAAS,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,WA6BhF,CAAC;AAEF,eAAO,MAAM,uBAAuB,cAAe,cAAc,UAAU,OAAO,kBAWjF,CAAC"}