@dynamic-labs-wallet/evm 1.1.23 → 1.1.24

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
@@ -4,6 +4,7 @@ var browser = require('@dynamic-labs-wallet/browser');
4
4
  var viem = require('viem');
5
5
  var accounts = require('viem/accounts');
6
6
  var chains = require('viem/chains');
7
+ var utils = require('viem/utils');
7
8
 
8
9
  function _extends() {
9
10
  _extends = Object.assign || function assign(target) {
@@ -465,8 +466,11 @@ const prepareEvmTransactionSigningOperation = ({ transaction, accountAddress, re
465
466
  if (parsed.type !== 'eip1559' || ((_parsed_accessList_length = (_parsed_accessList = parsed.accessList) == null ? void 0 : _parsed_accessList.length) != null ? _parsed_accessList_length : 0) !== 0) {
466
467
  throw new Error('Signing intent supports only EIP-1559 transactions with an empty access list');
467
468
  }
468
- const { chainId, nonce, gas, maxFeePerGas, maxPriorityFeePerGas } = parsed;
469
- if (nonce === undefined || gas === undefined || maxFeePerGas === undefined || maxPriorityFeePerGas === undefined || parsed.yParity !== undefined || parsed.r !== undefined || parsed.s !== undefined) {
469
+ const { chainId, nonce, gas, maxFeePerGas } = parsed;
470
+ var _parsed_maxPriorityFeePerGas;
471
+ // viem drops zero-valued fee fields when parsing, so an absent tip is a valid zero tip.
472
+ const maxPriorityFeePerGas = (_parsed_maxPriorityFeePerGas = parsed.maxPriorityFeePerGas) != null ? _parsed_maxPriorityFeePerGas : 0n;
473
+ if (nonce === undefined || gas === undefined || maxFeePerGas === undefined || parsed.yParity !== undefined || parsed.r !== undefined || parsed.s !== undefined) {
470
474
  throw new Error('Signing intent requires a complete unsigned EIP-1559 transaction');
471
475
  }
472
476
  if (gas === 0n || maxFeePerGas === 0n) {
@@ -502,6 +506,42 @@ const safeNumber = (value, name)=>{
502
506
  if (parsed > BigInt(Number.MAX_SAFE_INTEGER)) throw new Error(`Invalid ${name} signing value`);
503
507
  return Number(parsed);
504
508
  };
509
+ /** The authorization is hashed from JS numbers, so a chain id or nonce must be an exact, in-range integer. */ const assertValidEip7702Auth = (eip7702Auth)=>{
510
+ if (!Number.isSafeInteger(eip7702Auth.chainId) || eip7702Auth.chainId <= 0) {
511
+ throw new Error('Invalid chainId signing value');
512
+ }
513
+ if (!Number.isSafeInteger(eip7702Auth.nonce) || eip7702Auth.nonce < 0) {
514
+ throw new Error('Invalid nonce signing value');
515
+ }
516
+ viem.getAddress(eip7702Auth.address);
517
+ };
518
+ /**
519
+ * Builds the intent operation for an EIP-7702 authorization; `payload` is the hash the wallet signs.
520
+ * The authorization is carried unchanged so it can be compared with the sign request's context.
521
+ */ const prepareEip7702AuthSigningOperation = ({ eip7702Auth })=>{
522
+ assertValidEip7702Auth(eip7702Auth);
523
+ const { address, chainId, nonce } = eip7702Auth;
524
+ return {
525
+ operation: {
526
+ kind: 'eip7702Auth',
527
+ chainName: 'EVM',
528
+ eip7702Auth: {
529
+ address,
530
+ chainId,
531
+ nonce
532
+ },
533
+ payload: utils.hashAuthorization({
534
+ chainId,
535
+ contractAddress: address,
536
+ nonce
537
+ }).slice(2)
538
+ }
539
+ };
540
+ };
541
+ /** Reads an approved operation's authorization, rejecting a zero, negative or unsafe chain id or nonce. */ const eip7702AuthorizationFromOperation = ({ operation })=>{
542
+ assertValidEip7702Auth(operation.eip7702Auth);
543
+ return operation.eip7702Auth;
544
+ };
505
545
  /**
506
546
  * Reconstructs an unsigned EIP-1559 transaction from an approved intent.
507
547
  * Only gas and fee values may change, within the approved limits.
@@ -545,6 +585,8 @@ const safeNumber = (value, name)=>{
545
585
  };
546
586
 
547
587
  exports.DynamicEvmWalletClient = DynamicEvmWalletClient;
588
+ exports.eip7702AuthorizationFromOperation = eip7702AuthorizationFromOperation;
589
+ exports.prepareEip7702AuthSigningOperation = prepareEip7702AuthSigningOperation;
548
590
  exports.prepareEvmTransactionSigningOperation = prepareEvmTransactionSigningOperation;
549
591
  exports.resumeEvmTransactionSigningIntent = resumeEvmTransactionSigningIntent;
550
592
  exports.serializeEcdsaSignature = serializeEcdsaSignature;
package/index.esm.js CHANGED
@@ -2,6 +2,7 @@ import { EcdsaPublicKey, DynamicWalletClient, getMPCChainConfig, ERROR_CREATE_WA
2
2
  import { serializeSignature, stringToHex, bytesToHex, size, concat, hashTypedData, validateTypedData, createPublicClient, http, getAddress, serializeTransaction, parseTransaction } from 'viem';
3
3
  import { privateKeyToAccount } from 'viem/accounts';
4
4
  import { mainnet } from 'viem/chains';
5
+ import { hashAuthorization } from 'viem/utils';
5
6
 
6
7
  function _extends() {
7
8
  _extends = Object.assign || function assign(target) {
@@ -463,8 +464,11 @@ const prepareEvmTransactionSigningOperation = ({ transaction, accountAddress, re
463
464
  if (parsed.type !== 'eip1559' || ((_parsed_accessList_length = (_parsed_accessList = parsed.accessList) == null ? void 0 : _parsed_accessList.length) != null ? _parsed_accessList_length : 0) !== 0) {
464
465
  throw new Error('Signing intent supports only EIP-1559 transactions with an empty access list');
465
466
  }
466
- const { chainId, nonce, gas, maxFeePerGas, maxPriorityFeePerGas } = parsed;
467
- if (nonce === undefined || gas === undefined || maxFeePerGas === undefined || maxPriorityFeePerGas === undefined || parsed.yParity !== undefined || parsed.r !== undefined || parsed.s !== undefined) {
467
+ const { chainId, nonce, gas, maxFeePerGas } = parsed;
468
+ var _parsed_maxPriorityFeePerGas;
469
+ // viem drops zero-valued fee fields when parsing, so an absent tip is a valid zero tip.
470
+ const maxPriorityFeePerGas = (_parsed_maxPriorityFeePerGas = parsed.maxPriorityFeePerGas) != null ? _parsed_maxPriorityFeePerGas : 0n;
471
+ if (nonce === undefined || gas === undefined || maxFeePerGas === undefined || parsed.yParity !== undefined || parsed.r !== undefined || parsed.s !== undefined) {
468
472
  throw new Error('Signing intent requires a complete unsigned EIP-1559 transaction');
469
473
  }
470
474
  if (gas === 0n || maxFeePerGas === 0n) {
@@ -500,6 +504,42 @@ const safeNumber = (value, name)=>{
500
504
  if (parsed > BigInt(Number.MAX_SAFE_INTEGER)) throw new Error(`Invalid ${name} signing value`);
501
505
  return Number(parsed);
502
506
  };
507
+ /** The authorization is hashed from JS numbers, so a chain id or nonce must be an exact, in-range integer. */ const assertValidEip7702Auth = (eip7702Auth)=>{
508
+ if (!Number.isSafeInteger(eip7702Auth.chainId) || eip7702Auth.chainId <= 0) {
509
+ throw new Error('Invalid chainId signing value');
510
+ }
511
+ if (!Number.isSafeInteger(eip7702Auth.nonce) || eip7702Auth.nonce < 0) {
512
+ throw new Error('Invalid nonce signing value');
513
+ }
514
+ getAddress(eip7702Auth.address);
515
+ };
516
+ /**
517
+ * Builds the intent operation for an EIP-7702 authorization; `payload` is the hash the wallet signs.
518
+ * The authorization is carried unchanged so it can be compared with the sign request's context.
519
+ */ const prepareEip7702AuthSigningOperation = ({ eip7702Auth })=>{
520
+ assertValidEip7702Auth(eip7702Auth);
521
+ const { address, chainId, nonce } = eip7702Auth;
522
+ return {
523
+ operation: {
524
+ kind: 'eip7702Auth',
525
+ chainName: 'EVM',
526
+ eip7702Auth: {
527
+ address,
528
+ chainId,
529
+ nonce
530
+ },
531
+ payload: hashAuthorization({
532
+ chainId,
533
+ contractAddress: address,
534
+ nonce
535
+ }).slice(2)
536
+ }
537
+ };
538
+ };
539
+ /** Reads an approved operation's authorization, rejecting a zero, negative or unsafe chain id or nonce. */ const eip7702AuthorizationFromOperation = ({ operation })=>{
540
+ assertValidEip7702Auth(operation.eip7702Auth);
541
+ return operation.eip7702Auth;
542
+ };
503
543
  /**
504
544
  * Reconstructs an unsigned EIP-1559 transaction from an approved intent.
505
545
  * Only gas and fee values may change, within the approved limits.
@@ -542,4 +582,4 @@ const safeNumber = (value, name)=>{
542
582
  return transaction;
543
583
  };
544
584
 
545
- export { DynamicEvmWalletClient, prepareEvmTransactionSigningOperation, resumeEvmTransactionSigningIntent, serializeEcdsaSignature };
585
+ export { DynamicEvmWalletClient, eip7702AuthorizationFromOperation, prepareEip7702AuthSigningOperation, prepareEvmTransactionSigningOperation, resumeEvmTransactionSigningIntent, serializeEcdsaSignature };
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@dynamic-labs-wallet/evm",
3
- "version": "1.1.23",
3
+ "version": "1.1.24",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "dependencies": {
7
- "@dynamic-labs-wallet/browser": "1.1.23",
8
- "@dynamic-labs-wallet/core": "1.1.23",
7
+ "@dynamic-labs-wallet/browser": "1.1.24",
8
+ "@dynamic-labs-wallet/core": "1.1.24",
9
9
  "@dynamic-labs/sdk-api-core": "0.50.0"
10
10
  },
11
11
  "peerDependencies": {
package/src/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './client/index.js';
2
- export { prepareEvmTransactionSigningOperation, resumeEvmTransactionSigningIntent } from './signingIntent.js';
2
+ export { eip7702AuthorizationFromOperation, prepareEip7702AuthSigningOperation, prepareEvmTransactionSigningOperation, resumeEvmTransactionSigningIntent, } from './signingIntent.js';
3
3
  export { serializeEcdsaSignature } from './utils.js';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,qCAAqC,EAAE,iCAAiC,EAAE,MAAM,oBAAoB,CAAC;AAC9G,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,OAAO,EACL,iCAAiC,EACjC,kCAAkC,EAClC,qCAAqC,EACrC,iCAAiC,GAClC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC"}
@@ -4,6 +4,23 @@ export declare const prepareEvmTransactionSigningOperation: ({ transaction, acco
4
4
  accountAddress: string;
5
5
  refreshLimits?: EvmSigningIntentLimits;
6
6
  }) => PreparedTransactionSigningIntent;
7
+ type Eip7702AuthOperation = Extract<SigningIntent['operation'], {
8
+ kind: 'eip7702Auth';
9
+ }>;
10
+ type Eip7702Auth = Eip7702AuthOperation['eip7702Auth'];
11
+ /**
12
+ * Builds the intent operation for an EIP-7702 authorization; `payload` is the hash the wallet signs.
13
+ * The authorization is carried unchanged so it can be compared with the sign request's context.
14
+ */
15
+ export declare const prepareEip7702AuthSigningOperation: ({ eip7702Auth, }: {
16
+ eip7702Auth: Eip7702Auth;
17
+ }) => {
18
+ operation: Eip7702AuthOperation;
19
+ };
20
+ /** Reads an approved operation's authorization, rejecting a zero, negative or unsafe chain id or nonce. */
21
+ export declare const eip7702AuthorizationFromOperation: ({ operation }: {
22
+ operation: Eip7702AuthOperation;
23
+ }) => Eip7702Auth;
7
24
  /**
8
25
  * Reconstructs an unsigned EIP-1559 transaction from an approved intent.
9
26
  * Only gas and fee values may change, within the approved limits.
@@ -11,4 +28,5 @@ export declare const prepareEvmTransactionSigningOperation: ({ transaction, acco
11
28
  export declare const resumeEvmTransactionSigningIntent: ({ intent }: {
12
29
  intent: SigningIntent;
13
30
  }) => string;
31
+ export {};
14
32
  //# sourceMappingURL=signingIntent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"signingIntent.d.ts","sourceRoot":"","sources":["../../packages/src/signingIntent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,gCAAgC,EAChC,aAAa,EACd,MAAM,2BAA2B,CAAC;AAiBnC,eAAO,MAAM,qCAAqC,oDAI/C;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,sBAAsB,CAAC;CACxC,KAAG,gCAmDH,CAAC;AAQF;;;GAGG;AACH,eAAO,MAAM,iCAAiC,eAAgB;IAAE,MAAM,EAAE,aAAa,CAAA;CAAE,KAAG,MAmDzF,CAAC"}
1
+ {"version":3,"file":"signingIntent.d.ts","sourceRoot":"","sources":["../../packages/src/signingIntent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,gCAAgC,EAChC,aAAa,EACd,MAAM,2BAA2B,CAAC;AAkBnC,eAAO,MAAM,qCAAqC,oDAI/C;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,sBAAsB,CAAC;CACxC,KAAG,gCAoDH,CAAC;AAQF,KAAK,oBAAoB,GAAG,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,EAAE;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,CAAC,CAAC;AACzF,KAAK,WAAW,GAAG,oBAAoB,CAAC,aAAa,CAAC,CAAC;AAavD;;;GAGG;AACH,eAAO,MAAM,kCAAkC,qBAE5C;IACD,WAAW,EAAE,WAAW,CAAC;CAC1B,KAAG;IAAE,SAAS,EAAE,oBAAoB,CAAA;CAYpC,CAAC;AAEF,2GAA2G;AAC3G,eAAO,MAAM,iCAAiC,kBAAmB;IAAE,SAAS,EAAE,oBAAoB,CAAA;CAAE,KAAG,WAItG,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iCAAiC,eAAgB;IAAE,MAAM,EAAE,aAAa,CAAA;CAAE,KAAG,MAmDzF,CAAC"}