@0xsequence/account 2.2.13 → 2.2.15

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.
@@ -72,6 +72,25 @@ class AccountSigner {
72
72
  async getAddress() {
73
73
  return this.account.address;
74
74
  }
75
+
76
+ /**
77
+ * Signs a message.
78
+ *
79
+ * This method will sign the message using the account associated with this signer
80
+ * and the specified chain ID. The message is already being prefixed with the EIP-191 prefix.
81
+ *
82
+ * @param message - The message to sign. Can be a string or BytesLike.
83
+ * @returns A Promise that resolves to the signature as a hexadecimal string
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * const signer = account.getSigner(chainId)
88
+ *
89
+ * const message = "Hello, Sequence!";
90
+ * const signature = await signer.signMessage(message);
91
+ * console.log(signature);
92
+ * // => "0x123abc..." (hexadecimal signature)
93
+ */
75
94
  signMessage(message) {
76
95
  var _this$options$cantVal, _this$options;
77
96
  return this.account.signMessage(message, this.chainId, (_this$options$cantVal = (_this$options = this.options) == null ? void 0 : _this$options.cantValidateBehavior) != null ? _this$options$cantVal : 'throw');
@@ -781,8 +800,32 @@ class Account {
781
800
  chainId
782
801
  }), feeQuote);
783
802
  }
803
+
804
+ /**
805
+ * Signs a message.
806
+ *
807
+ * This method will sign the message using the account associated with this signer
808
+ * and the specified chain ID. If the message is already prefixed with the EIP-191
809
+ * prefix, it will be hashed directly. Otherwise, it will be prefixed before hashing.
810
+ *
811
+ * @param message - The message to sign. Can be a string or BytesLike.
812
+ * @param chainId - The chain ID to use for signing
813
+ * @param cantValidateBehavior - Behavior when the wallet cannot validate on-chain
814
+ * @returns A Promise that resolves to the signature as a hexadecimal string
815
+ */
784
816
  signMessage(message, chainId, cantValidateBehavior = 'ignore') {
785
- return this.signDigest(ethers.ethers.keccak256(message), chainId, true, cantValidateBehavior);
817
+ const messageHex = ethers.ethers.hexlify(message);
818
+ const prefixHex = ethers.ethers.hexlify(ethers.ethers.toUtf8Bytes(ethers.MessagePrefix));
819
+ let digest;
820
+
821
+ // We check if the message is already prefixed with EIP-191
822
+ // This will avoid breaking changes for codebases where the message is already prefixed
823
+ if (messageHex.substring(2).startsWith(prefixHex.substring(2))) {
824
+ digest = ethers.ethers.keccak256(message);
825
+ } else {
826
+ digest = ethers.ethers.hashMessage(message);
827
+ }
828
+ return this.signDigest(digest, chainId, true, cantValidateBehavior);
786
829
  }
787
830
  async signTransactions(txs, chainId, pstatus, options) {
788
831
  const status = pstatus || (await this.status(chainId));
@@ -72,6 +72,25 @@ class AccountSigner {
72
72
  async getAddress() {
73
73
  return this.account.address;
74
74
  }
75
+
76
+ /**
77
+ * Signs a message.
78
+ *
79
+ * This method will sign the message using the account associated with this signer
80
+ * and the specified chain ID. The message is already being prefixed with the EIP-191 prefix.
81
+ *
82
+ * @param message - The message to sign. Can be a string or BytesLike.
83
+ * @returns A Promise that resolves to the signature as a hexadecimal string
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * const signer = account.getSigner(chainId)
88
+ *
89
+ * const message = "Hello, Sequence!";
90
+ * const signature = await signer.signMessage(message);
91
+ * console.log(signature);
92
+ * // => "0x123abc..." (hexadecimal signature)
93
+ */
75
94
  signMessage(message) {
76
95
  var _this$options$cantVal, _this$options;
77
96
  return this.account.signMessage(message, this.chainId, (_this$options$cantVal = (_this$options = this.options) == null ? void 0 : _this$options.cantValidateBehavior) != null ? _this$options$cantVal : 'throw');
@@ -781,8 +800,32 @@ class Account {
781
800
  chainId
782
801
  }), feeQuote);
783
802
  }
803
+
804
+ /**
805
+ * Signs a message.
806
+ *
807
+ * This method will sign the message using the account associated with this signer
808
+ * and the specified chain ID. If the message is already prefixed with the EIP-191
809
+ * prefix, it will be hashed directly. Otherwise, it will be prefixed before hashing.
810
+ *
811
+ * @param message - The message to sign. Can be a string or BytesLike.
812
+ * @param chainId - The chain ID to use for signing
813
+ * @param cantValidateBehavior - Behavior when the wallet cannot validate on-chain
814
+ * @returns A Promise that resolves to the signature as a hexadecimal string
815
+ */
784
816
  signMessage(message, chainId, cantValidateBehavior = 'ignore') {
785
- return this.signDigest(ethers.ethers.keccak256(message), chainId, true, cantValidateBehavior);
817
+ const messageHex = ethers.ethers.hexlify(message);
818
+ const prefixHex = ethers.ethers.hexlify(ethers.ethers.toUtf8Bytes(ethers.MessagePrefix));
819
+ let digest;
820
+
821
+ // We check if the message is already prefixed with EIP-191
822
+ // This will avoid breaking changes for codebases where the message is already prefixed
823
+ if (messageHex.substring(2).startsWith(prefixHex.substring(2))) {
824
+ digest = ethers.ethers.keccak256(message);
825
+ } else {
826
+ digest = ethers.ethers.hashMessage(message);
827
+ }
828
+ return this.signDigest(digest, chainId, true, cantValidateBehavior);
786
829
  }
787
830
  async signTransactions(txs, chainId, pstatus, options) {
788
831
  const status = pstatus || (await this.status(chainId));
@@ -5,7 +5,7 @@ import { ChainId } from '@0xsequence/network';
5
5
  import { proto, isRelayer, RpcRelayer } from '@0xsequence/relayer';
6
6
  import { toHexString, getFetchRequest, encodeTypedDataDigest } from '@0xsequence/utils';
7
7
  import { Wallet } from '@0xsequence/wallet';
8
- import { ethers } from 'ethers';
8
+ import { ethers, MessagePrefix } from 'ethers';
9
9
 
10
10
  function _extends() {
11
11
  return _extends = Object.assign ? Object.assign.bind() : function (n) {
@@ -68,6 +68,25 @@ class AccountSigner {
68
68
  async getAddress() {
69
69
  return this.account.address;
70
70
  }
71
+
72
+ /**
73
+ * Signs a message.
74
+ *
75
+ * This method will sign the message using the account associated with this signer
76
+ * and the specified chain ID. The message is already being prefixed with the EIP-191 prefix.
77
+ *
78
+ * @param message - The message to sign. Can be a string or BytesLike.
79
+ * @returns A Promise that resolves to the signature as a hexadecimal string
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * const signer = account.getSigner(chainId)
84
+ *
85
+ * const message = "Hello, Sequence!";
86
+ * const signature = await signer.signMessage(message);
87
+ * console.log(signature);
88
+ * // => "0x123abc..." (hexadecimal signature)
89
+ */
71
90
  signMessage(message) {
72
91
  var _this$options$cantVal, _this$options;
73
92
  return this.account.signMessage(message, this.chainId, (_this$options$cantVal = (_this$options = this.options) == null ? void 0 : _this$options.cantValidateBehavior) != null ? _this$options$cantVal : 'throw');
@@ -777,8 +796,32 @@ class Account {
777
796
  chainId
778
797
  }), feeQuote);
779
798
  }
799
+
800
+ /**
801
+ * Signs a message.
802
+ *
803
+ * This method will sign the message using the account associated with this signer
804
+ * and the specified chain ID. If the message is already prefixed with the EIP-191
805
+ * prefix, it will be hashed directly. Otherwise, it will be prefixed before hashing.
806
+ *
807
+ * @param message - The message to sign. Can be a string or BytesLike.
808
+ * @param chainId - The chain ID to use for signing
809
+ * @param cantValidateBehavior - Behavior when the wallet cannot validate on-chain
810
+ * @returns A Promise that resolves to the signature as a hexadecimal string
811
+ */
780
812
  signMessage(message, chainId, cantValidateBehavior = 'ignore') {
781
- return this.signDigest(ethers.keccak256(message), chainId, true, cantValidateBehavior);
813
+ const messageHex = ethers.hexlify(message);
814
+ const prefixHex = ethers.hexlify(ethers.toUtf8Bytes(MessagePrefix));
815
+ let digest;
816
+
817
+ // We check if the message is already prefixed with EIP-191
818
+ // This will avoid breaking changes for codebases where the message is already prefixed
819
+ if (messageHex.substring(2).startsWith(prefixHex.substring(2))) {
820
+ digest = ethers.keccak256(message);
821
+ } else {
822
+ digest = ethers.hashMessage(message);
823
+ }
824
+ return this.signDigest(digest, chainId, true, cantValidateBehavior);
782
825
  }
783
826
  async signTransactions(txs, chainId, pstatus, options) {
784
827
  const status = pstatus || (await this.status(chainId));
@@ -1,9 +1,9 @@
1
1
  import { commons } from '@0xsequence/core';
2
2
  import { migrator } from '@0xsequence/migration';
3
3
  import { ChainId, NetworkConfig } from '@0xsequence/network';
4
- import { FeeOption, FeeQuote, Relayer } from '@0xsequence/relayer';
5
- import { tracker } from '@0xsequence/sessions';
6
- import { SignatureOrchestrator } from '@0xsequence/signhub';
4
+ import { type FeeOption, type FeeQuote, type Relayer } from '@0xsequence/relayer';
5
+ import type { tracker } from '@0xsequence/sessions';
6
+ import type { SignatureOrchestrator } from '@0xsequence/signhub';
7
7
  import { Wallet } from '@0xsequence/wallet';
8
8
  import { ethers } from 'ethers';
9
9
  import { AccountSigner, AccountSignerOptions } from "./signer.js";
@@ -114,6 +114,18 @@ export declare class Account {
114
114
  buildBootstrapTransactions(status: AccountStatus, chainId: ethers.BigNumberish): Promise<commons.transaction.IntendedTransactionBundle>;
115
115
  bootstrapTransactions(chainId: ethers.BigNumberish, prestatus?: AccountStatus): Promise<Omit<commons.transaction.IntendedTransactionBundle, 'chainId'>>;
116
116
  doBootstrap(chainId: ethers.BigNumberish, feeQuote?: FeeQuote, prestatus?: AccountStatus): Promise<commons.transaction.TransactionResponse<any>>;
117
+ /**
118
+ * Signs a message.
119
+ *
120
+ * This method will sign the message using the account associated with this signer
121
+ * and the specified chain ID. If the message is already prefixed with the EIP-191
122
+ * prefix, it will be hashed directly. Otherwise, it will be prefixed before hashing.
123
+ *
124
+ * @param message - The message to sign. Can be a string or BytesLike.
125
+ * @param chainId - The chain ID to use for signing
126
+ * @param cantValidateBehavior - Behavior when the wallet cannot validate on-chain
127
+ * @returns A Promise that resolves to the signature as a hexadecimal string
128
+ */
117
129
  signMessage(message: ethers.BytesLike, chainId: ethers.BigNumberish, cantValidateBehavior?: 'ignore' | 'eip6492' | 'throw'): Promise<string>;
118
130
  signTransactions(txs: commons.transaction.Transactionish, chainId: ethers.BigNumberish, pstatus?: AccountStatus, options?: {
119
131
  nonceSpace?: ethers.BigNumberish;
@@ -16,6 +16,24 @@ export declare class AccountSigner implements ethers.AbstractSigner<ethers.Provi
16
16
  constructor(account: Account, chainId: ChainId, options?: AccountSignerOptions | undefined);
17
17
  get provider(): ethers.Provider;
18
18
  getAddress(): Promise<string>;
19
+ /**
20
+ * Signs a message.
21
+ *
22
+ * This method will sign the message using the account associated with this signer
23
+ * and the specified chain ID. The message is already being prefixed with the EIP-191 prefix.
24
+ *
25
+ * @param message - The message to sign. Can be a string or BytesLike.
26
+ * @returns A Promise that resolves to the signature as a hexadecimal string
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * const signer = account.getSigner(chainId)
31
+ *
32
+ * const message = "Hello, Sequence!";
33
+ * const signature = await signer.signMessage(message);
34
+ * console.log(signature);
35
+ * // => "0x123abc..." (hexadecimal signature)
36
+ */
19
37
  signMessage(message: string | ethers.BytesLike): Promise<string>;
20
38
  signTypedData(domain: ethers.TypedDataDomain, types: Record<string, Array<ethers.TypedDataField>>, value: Record<string, any>): Promise<string>;
21
39
  private defaultSelectFee;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xsequence/account",
3
- "version": "2.2.13",
3
+ "version": "2.2.15",
4
4
  "description": "tools for migrating sequence wallets to new versions",
5
5
  "repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/account",
6
6
  "source": "src/index.ts",
@@ -12,21 +12,21 @@
12
12
  "ethers": ">=6"
13
13
  },
14
14
  "dependencies": {
15
- "@0xsequence/core": "2.2.13",
16
- "@0xsequence/abi": "2.2.13",
17
- "@0xsequence/migration": "2.2.13",
18
- "@0xsequence/relayer": "2.2.13",
19
- "@0xsequence/network": "2.2.13",
20
- "@0xsequence/sessions": "2.2.13",
21
- "@0xsequence/utils": "2.2.13",
22
- "@0xsequence/wallet": "2.2.13"
15
+ "@0xsequence/abi": "2.2.15",
16
+ "@0xsequence/core": "2.2.15",
17
+ "@0xsequence/relayer": "2.2.15",
18
+ "@0xsequence/migration": "2.2.15",
19
+ "@0xsequence/network": "2.2.15",
20
+ "@0xsequence/sessions": "2.2.15",
21
+ "@0xsequence/utils": "2.2.15",
22
+ "@0xsequence/wallet": "2.2.15"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@istanbuljs/nyc-config-typescript": "^1.0.2",
26
26
  "ethers": "6.13.4",
27
27
  "nyc": "^15.1.0",
28
- "@0xsequence/signhub": "2.2.13",
29
- "@0xsequence/tests": "2.2.13"
28
+ "@0xsequence/signhub": "2.2.15",
29
+ "@0xsequence/tests": "2.2.15"
30
30
  },
31
31
  "files": [
32
32
  "src",
package/src/account.ts CHANGED
@@ -2,12 +2,12 @@ import { walletContracts } from '@0xsequence/abi'
2
2
  import { commons, universal } from '@0xsequence/core'
3
3
  import { migrator, defaults, version } from '@0xsequence/migration'
4
4
  import { ChainId, NetworkConfig } from '@0xsequence/network'
5
- import { FeeOption, FeeQuote, isRelayer, Relayer, RpcRelayer } from '@0xsequence/relayer'
6
- import { tracker } from '@0xsequence/sessions'
7
- import { SignatureOrchestrator } from '@0xsequence/signhub'
5
+ import { type FeeOption, type FeeQuote, isRelayer, type Relayer, RpcRelayer } from '@0xsequence/relayer'
6
+ import type { tracker } from '@0xsequence/sessions'
7
+ import type { SignatureOrchestrator } from '@0xsequence/signhub'
8
8
  import { encodeTypedDataDigest, getFetchRequest } from '@0xsequence/utils'
9
9
  import { Wallet } from '@0xsequence/wallet'
10
- import { ethers } from 'ethers'
10
+ import { ethers, MessagePrefix } from 'ethers'
11
11
  import { AccountSigner, AccountSignerOptions } from './signer'
12
12
 
13
13
  export type AccountStatus = {
@@ -788,12 +788,37 @@ export class Account {
788
788
  return this.relayer(chainId).relay({ ...bootstrapTxs, chainId }, feeQuote)
789
789
  }
790
790
 
791
+ /**
792
+ * Signs a message.
793
+ *
794
+ * This method will sign the message using the account associated with this signer
795
+ * and the specified chain ID. If the message is already prefixed with the EIP-191
796
+ * prefix, it will be hashed directly. Otherwise, it will be prefixed before hashing.
797
+ *
798
+ * @param message - The message to sign. Can be a string or BytesLike.
799
+ * @param chainId - The chain ID to use for signing
800
+ * @param cantValidateBehavior - Behavior when the wallet cannot validate on-chain
801
+ * @returns A Promise that resolves to the signature as a hexadecimal string
802
+ */
791
803
  signMessage(
792
804
  message: ethers.BytesLike,
793
805
  chainId: ethers.BigNumberish,
794
806
  cantValidateBehavior: 'ignore' | 'eip6492' | 'throw' = 'ignore'
795
807
  ): Promise<string> {
796
- return this.signDigest(ethers.keccak256(message), chainId, true, cantValidateBehavior)
808
+ const messageHex = ethers.hexlify(message);
809
+ const prefixHex = ethers.hexlify(ethers.toUtf8Bytes(MessagePrefix));
810
+
811
+ let digest: string;
812
+
813
+ // We check if the message is already prefixed with EIP-191
814
+ // This will avoid breaking changes for codebases where the message is already prefixed
815
+ if (messageHex.substring(2).startsWith(prefixHex.substring(2))) {
816
+ digest = ethers.keccak256(message);
817
+ } else {
818
+ digest = ethers.hashMessage(message);
819
+ }
820
+
821
+ return this.signDigest(digest, chainId, true, cantValidateBehavior);
797
822
  }
798
823
 
799
824
  async signTransactions(
package/src/signer.ts CHANGED
@@ -77,6 +77,24 @@ export class AccountSigner implements ethers.AbstractSigner<ethers.Provider> {
77
77
  return this.account.address
78
78
  }
79
79
 
80
+ /**
81
+ * Signs a message.
82
+ *
83
+ * This method will sign the message using the account associated with this signer
84
+ * and the specified chain ID. The message is already being prefixed with the EIP-191 prefix.
85
+ *
86
+ * @param message - The message to sign. Can be a string or BytesLike.
87
+ * @returns A Promise that resolves to the signature as a hexadecimal string
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * const signer = account.getSigner(chainId)
92
+ *
93
+ * const message = "Hello, Sequence!";
94
+ * const signature = await signer.signMessage(message);
95
+ * console.log(signature);
96
+ * // => "0x123abc..." (hexadecimal signature)
97
+ */
80
98
  signMessage(message: string | ethers.BytesLike): Promise<string> {
81
99
  return this.account.signMessage(message, this.chainId, this.options?.cantValidateBehavior ?? 'throw')
82
100
  }