viem 2.9.25 → 2.9.27
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/CHANGELOG.md +26 -0
- package/_cjs/actions/public/verifyHash.js +12 -3
- package/_cjs/actions/public/verifyHash.js.map +1 -1
- package/_cjs/actions/public/verifyMessage.js.map +1 -1
- package/_cjs/actions/wallet/prepareTransactionRequest.js +1 -1
- package/_cjs/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_cjs/chains/definitions/bxnTestnet.js +1 -0
- package/_cjs/chains/definitions/bxnTestnet.js.map +1 -1
- package/_cjs/chains/definitions/cyber.js +28 -0
- package/_cjs/chains/definitions/cyber.js.map +1 -0
- package/_cjs/chains/definitions/cyberTestnet.js +2 -2
- package/_cjs/chains/definitions/cyberTestnet.js.map +1 -1
- package/_cjs/chains/definitions/polygonAmoy.js +3 -2
- package/_cjs/chains/definitions/polygonAmoy.js.map +1 -1
- package/_cjs/chains/definitions/skale/cryptoColosseum.js +1 -1
- package/_cjs/chains/definitions/yooldoVerse.js +21 -0
- package/_cjs/chains/definitions/yooldoVerse.js.map +1 -0
- package/_cjs/chains/definitions/yooldoVerseTestnet.js +22 -0
- package/_cjs/chains/definitions/yooldoVerseTestnet.js.map +1 -0
- package/_cjs/chains/index.js +11 -5
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/experimental/eip3074/actions/signAuthMessage.js +13 -2
- package/_cjs/experimental/eip3074/actions/signAuthMessage.js.map +1 -1
- package/_cjs/experimental/eip3074/decorators/eip3074.js.map +1 -1
- package/_cjs/utils/rpc/http.js +3 -1
- package/_cjs/utils/rpc/http.js.map +1 -1
- package/_cjs/utils/rpc/socket.js +5 -5
- package/_cjs/utils/rpc/socket.js.map +1 -1
- package/_cjs/utils/signature/hexToSignature.js +18 -3
- package/_cjs/utils/signature/hexToSignature.js.map +1 -1
- package/_cjs/utils/signature/recoverMessageAddress.js.map +1 -1
- package/_cjs/utils/signature/recoverPublicKey.js +22 -6
- package/_cjs/utils/signature/recoverPublicKey.js.map +1 -1
- package/_cjs/utils/signature/recoverTransactionAddress.js +1 -0
- package/_cjs/utils/signature/recoverTransactionAddress.js.map +1 -1
- package/_cjs/utils/signature/verifyMessage.js.map +1 -1
- package/_cjs/zksync/actions/sendEip712Transaction.js +1 -1
- package/_cjs/zksync/actions/sendEip712Transaction.js.map +1 -1
- package/_cjs/zksync/constants/number.js +2 -1
- package/_cjs/zksync/constants/number.js.map +1 -1
- package/_cjs/zksync/formatters.js +2 -1
- package/_cjs/zksync/formatters.js.map +1 -1
- package/_cjs/zksync/serializers.js +2 -1
- package/_cjs/zksync/serializers.js.map +1 -1
- package/_cjs/zksync/utils/getEip712Domain.js +2 -1
- package/_cjs/zksync/utils/getEip712Domain.js.map +1 -1
- package/_esm/actions/public/verifyHash.js +11 -2
- package/_esm/actions/public/verifyHash.js.map +1 -1
- package/_esm/actions/public/verifyMessage.js.map +1 -1
- package/_esm/actions/wallet/prepareTransactionRequest.js +1 -1
- package/_esm/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_esm/chains/definitions/bxnTestnet.js +1 -0
- package/_esm/chains/definitions/bxnTestnet.js.map +1 -1
- package/_esm/chains/definitions/cyber.js +25 -0
- package/_esm/chains/definitions/cyber.js.map +1 -0
- package/_esm/chains/definitions/cyberTestnet.js +2 -2
- package/_esm/chains/definitions/cyberTestnet.js.map +1 -1
- package/_esm/chains/definitions/polygonAmoy.js +3 -2
- package/_esm/chains/definitions/polygonAmoy.js.map +1 -1
- package/_esm/chains/definitions/skale/cryptoColosseum.js +1 -1
- package/_esm/chains/definitions/yooldoVerse.js +18 -0
- package/_esm/chains/definitions/yooldoVerse.js.map +1 -0
- package/_esm/chains/definitions/yooldoVerseTestnet.js +19 -0
- package/_esm/chains/definitions/yooldoVerseTestnet.js.map +1 -0
- package/_esm/chains/index.js +3 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/experimental/eip3074/actions/signAuthMessage.js +13 -4
- package/_esm/experimental/eip3074/actions/signAuthMessage.js.map +1 -1
- package/_esm/experimental/eip3074/decorators/eip3074.js.map +1 -1
- package/_esm/utils/rpc/http.js +3 -1
- package/_esm/utils/rpc/http.js.map +1 -1
- package/_esm/utils/rpc/socket.js +5 -5
- package/_esm/utils/rpc/socket.js.map +1 -1
- package/_esm/utils/signature/hexToSignature.js +18 -3
- package/_esm/utils/signature/hexToSignature.js.map +1 -1
- package/_esm/utils/signature/recoverMessageAddress.js.map +1 -1
- package/_esm/utils/signature/recoverPublicKey.js +25 -9
- package/_esm/utils/signature/recoverPublicKey.js.map +1 -1
- package/_esm/utils/signature/recoverTransactionAddress.js +1 -0
- package/_esm/utils/signature/recoverTransactionAddress.js.map +1 -1
- package/_esm/utils/signature/verifyMessage.js.map +1 -1
- package/_esm/zksync/actions/sendEip712Transaction.js +1 -1
- package/_esm/zksync/actions/sendEip712Transaction.js.map +1 -1
- package/_esm/zksync/constants/number.js +1 -0
- package/_esm/zksync/constants/number.js.map +1 -1
- package/_esm/zksync/formatters.js +2 -1
- package/_esm/zksync/formatters.js.map +1 -1
- package/_esm/zksync/serializers.js +2 -1
- package/_esm/zksync/serializers.js.map +1 -1
- package/_esm/zksync/utils/getEip712Domain.js +2 -1
- package/_esm/zksync/utils/getEip712Domain.js.map +1 -1
- package/_types/actions/public/verifyHash.d.ts +5 -5
- package/_types/actions/public/verifyHash.d.ts.map +1 -1
- package/_types/actions/public/verifyMessage.d.ts +2 -2
- package/_types/actions/public/verifyMessage.d.ts.map +1 -1
- package/_types/actions/public/verifyTypedData.d.ts +2 -2
- package/_types/actions/public/verifyTypedData.d.ts.map +1 -1
- package/_types/chains/definitions/bxnTestnet.d.ts +1 -1
- package/_types/chains/definitions/bxnTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/cyber.d.ts +34 -0
- package/_types/chains/definitions/cyber.d.ts.map +1 -0
- package/_types/chains/definitions/cyberTestnet.d.ts +2 -2
- package/_types/chains/definitions/polygonAmoy.d.ts +3 -2
- package/_types/chains/definitions/polygonAmoy.d.ts.map +1 -1
- package/_types/chains/definitions/skale/cryptoColosseum.d.ts +1 -1
- package/_types/chains/definitions/yooldoVerse.d.ts +35 -0
- package/_types/chains/definitions/yooldoVerse.d.ts.map +1 -0
- package/_types/chains/definitions/yooldoVerseTestnet.d.ts +35 -0
- package/_types/chains/definitions/yooldoVerseTestnet.d.ts.map +1 -0
- package/_types/chains/index.d.ts +3 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/experimental/eip3074/actions/signAuthMessage.d.ts +20 -10
- package/_types/experimental/eip3074/actions/signAuthMessage.d.ts.map +1 -1
- package/_types/experimental/eip3074/decorators/eip3074.d.ts +4 -4
- package/_types/experimental/eip3074/decorators/eip3074.d.ts.map +1 -1
- package/_types/experimental/eip3074/utils/recoverAuthMessageAddress.d.ts +2 -2
- package/_types/experimental/eip3074/utils/recoverAuthMessageAddress.d.ts.map +1 -1
- package/_types/utils/rpc/http.d.ts.map +1 -1
- package/_types/utils/rpc/socket.d.ts +1 -0
- package/_types/utils/rpc/socket.d.ts.map +1 -1
- package/_types/utils/signature/hexToSignature.d.ts +5 -0
- package/_types/utils/signature/hexToSignature.d.ts.map +1 -1
- package/_types/utils/signature/recoverAddress.d.ts +2 -2
- package/_types/utils/signature/recoverAddress.d.ts.map +1 -1
- package/_types/utils/signature/recoverMessageAddress.d.ts +2 -2
- package/_types/utils/signature/recoverMessageAddress.d.ts.map +1 -1
- package/_types/utils/signature/recoverPublicKey.d.ts +2 -2
- package/_types/utils/signature/recoverPublicKey.d.ts.map +1 -1
- package/_types/utils/signature/recoverTransactionAddress.d.ts +2 -2
- package/_types/utils/signature/recoverTransactionAddress.d.ts.map +1 -1
- package/_types/utils/signature/recoverTypedDataAddress.d.ts +2 -2
- package/_types/utils/signature/recoverTypedDataAddress.d.ts.map +1 -1
- package/_types/utils/signature/verifyMessage.d.ts +2 -2
- package/_types/utils/signature/verifyMessage.d.ts.map +1 -1
- package/_types/utils/signature/verifyTypedData.d.ts +2 -2
- package/_types/utils/signature/verifyTypedData.d.ts.map +1 -1
- package/_types/zksync/constants/number.d.ts +1 -0
- package/_types/zksync/constants/number.d.ts.map +1 -1
- package/_types/zksync/formatters.d.ts.map +1 -1
- package/_types/zksync/serializers.d.ts.map +1 -1
- package/_types/zksync/utils/getEip712Domain.d.ts.map +1 -1
- package/actions/public/verifyHash.ts +15 -7
- package/actions/public/verifyMessage.ts +7 -2
- package/actions/public/verifyTypedData.ts +2 -2
- package/actions/wallet/prepareTransactionRequest.ts +1 -1
- package/chains/definitions/bxnTestnet.ts +1 -0
- package/chains/definitions/cyber.ts +25 -0
- package/chains/definitions/cyberTestnet.ts +2 -2
- package/chains/definitions/polygonAmoy.ts +3 -2
- package/chains/definitions/skale/cryptoColosseum.ts +1 -1
- package/chains/definitions/yooldoVerse.ts +18 -0
- package/chains/definitions/yooldoVerseTestnet.ts +19 -0
- package/chains/index.ts +3 -0
- package/errors/version.ts +1 -1
- package/experimental/eip3074/actions/signAuthMessage.ts +68 -20
- package/experimental/eip3074/decorators/eip3074.ts +11 -4
- package/experimental/eip3074/utils/recoverAuthMessageAddress.ts +2 -2
- package/package.json +1 -1
- package/utils/rpc/http.ts +4 -1
- package/utils/rpc/socket.ts +6 -5
- package/utils/signature/hexToSignature.ts +16 -3
- package/utils/signature/recoverAddress.ts +2 -2
- package/utils/signature/recoverMessageAddress.ts +7 -2
- package/utils/signature/recoverPublicKey.ts +36 -13
- package/utils/signature/recoverTransactionAddress.ts +3 -2
- package/utils/signature/recoverTypedDataAddress.ts +2 -2
- package/utils/signature/verifyMessage.ts +7 -2
- package/utils/signature/verifyTypedData.ts +2 -2
- package/zksync/actions/sendEip712Transaction.ts +1 -1
- package/zksync/constants/number.ts +1 -0
- package/zksync/formatters.ts +2 -1
- package/zksync/serializers.ts +2 -1
- package/zksync/utils/getEip712Domain.ts +2 -1
@@ -1,7 +1,7 @@
|
|
1
1
|
import { defineChain } from '../../../utils/chain/defineChain.js'
|
2
2
|
|
3
3
|
export const skaleCryptoColosseum = /*#__PURE__*/ defineChain({
|
4
|
-
id:
|
4
|
+
id: 1_032_942_172,
|
5
5
|
name: 'SKALE | Crypto Colosseum',
|
6
6
|
nativeCurrency: { name: 'sFUEL', symbol: 'sFUEL', decimals: 18 },
|
7
7
|
rpcUrls: {
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { defineChain } from '../../utils/chain/defineChain.js'
|
2
|
+
|
3
|
+
export const yooldoVerse = /*#__PURE__*/ defineChain({
|
4
|
+
id: 50_005,
|
5
|
+
name: 'Yooldo Verse',
|
6
|
+
nativeCurrency: { name: 'OAS', symbol: 'OAS', decimals: 18 },
|
7
|
+
rpcUrls: {
|
8
|
+
default: {
|
9
|
+
http: ['https://rpc.yooldo-verse.xyz'],
|
10
|
+
},
|
11
|
+
},
|
12
|
+
blockExplorers: {
|
13
|
+
default: {
|
14
|
+
name: 'Yooldo Verse Explorer',
|
15
|
+
url: 'https://explorer.yooldo-verse.xyz',
|
16
|
+
},
|
17
|
+
},
|
18
|
+
})
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { defineChain } from '../../utils/chain/defineChain.js'
|
2
|
+
|
3
|
+
export const yooldoVerseTestnet = /*#__PURE__*/ defineChain({
|
4
|
+
id: 50_006,
|
5
|
+
name: 'Yooldo Verse Testnet',
|
6
|
+
nativeCurrency: { name: 'OAS', symbol: 'OAS', decimals: 18 },
|
7
|
+
rpcUrls: {
|
8
|
+
default: {
|
9
|
+
http: ['https://rpc.testnet.yooldo-verse.xyz'],
|
10
|
+
},
|
11
|
+
},
|
12
|
+
blockExplorers: {
|
13
|
+
default: {
|
14
|
+
name: 'Yooldo Verse Testnet Explorer',
|
15
|
+
url: 'https://explorer.testnet.yooldo-verse.xyz',
|
16
|
+
},
|
17
|
+
},
|
18
|
+
testnet: true,
|
19
|
+
})
|
package/chains/index.ts
CHANGED
@@ -52,6 +52,7 @@ export { coreDao } from './definitions/coreDao.js'
|
|
52
52
|
export { cronos } from './definitions/cronos.js'
|
53
53
|
export { cronosTestnet } from './definitions/cronosTestnet.js'
|
54
54
|
export { crossbell } from './definitions/crossbell.js'
|
55
|
+
export { cyber } from './definitions/cyber.js'
|
55
56
|
export { cyberTestnet } from './definitions/cyberTestnet.js'
|
56
57
|
export { darwinia } from './definitions/darwinia.js'
|
57
58
|
export { defichainEvm } from './definitions/defichainEvm.js'
|
@@ -246,6 +247,8 @@ export {
|
|
246
247
|
export { xLayer } from './definitions/xLayer.js'
|
247
248
|
export { xdc } from './definitions/xdc.js'
|
248
249
|
export { xdcTestnet } from './definitions/xdcTestnet.js'
|
250
|
+
export { yooldoVerse } from './definitions/yooldoVerse.js'
|
251
|
+
export { yooldoVerseTestnet } from './definitions/yooldoVerseTestnet.js'
|
249
252
|
export { zetachain } from './definitions/zetachain.js'
|
250
253
|
export { zetachainAthensTestnet } from './definitions/zetachainAthensTestnet.js'
|
251
254
|
export { zhejiang } from './definitions/zhejiang.js'
|
package/errors/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = '2.9.
|
1
|
+
export const version = '2.9.27'
|
@@ -1,22 +1,51 @@
|
|
1
|
+
import type { Address } from 'abitype'
|
2
|
+
import { getTransactionCount } from '../../../actions/public/getTransactionCount.js'
|
1
3
|
import type { Client } from '../../../clients/createClient.js'
|
2
4
|
import type { Transport } from '../../../clients/transports/createTransport.js'
|
3
5
|
import { AccountNotFoundError } from '../../../errors/account.js'
|
4
6
|
import type { ErrorType } from '../../../errors/utils.js'
|
5
|
-
import type {
|
6
|
-
|
7
|
-
|
7
|
+
import type {
|
8
|
+
Account,
|
9
|
+
DeriveAccount,
|
10
|
+
PrivateKeyAccount,
|
11
|
+
} from '../../../types/account.js'
|
12
|
+
import type { Chain, GetChainParameter } from '../../../types/chain.js'
|
13
|
+
import type { Hash, Hex } from '../../../types/misc.js'
|
8
14
|
import type { IsUndefined } from '../../../types/utils.js'
|
9
|
-
import
|
15
|
+
import { getAction } from '../../../utils/getAction.js'
|
16
|
+
|
17
|
+
// TODO: Use `GetAccountParameter` from `types/utils.ts` when JSON-RPC method for sign auth message exists.
|
18
|
+
type GetAccountParameter<
|
19
|
+
account extends Account | undefined = Account | undefined,
|
20
|
+
accountOverride extends Account | Address | undefined = Account | Address,
|
21
|
+
> = IsUndefined<account> extends true
|
22
|
+
? { account: accountOverride | PrivateKeyAccount }
|
23
|
+
: account extends PrivateKeyAccount
|
24
|
+
? {
|
25
|
+
account?: accountOverride | PrivateKeyAccount | undefined
|
26
|
+
}
|
27
|
+
: { account: accountOverride | PrivateKeyAccount }
|
28
|
+
|
29
|
+
type GetNonceParameter<account extends Account | Address | undefined> =
|
30
|
+
account extends Address | Account
|
31
|
+
? {
|
32
|
+
nonce?: number | undefined
|
33
|
+
}
|
34
|
+
: {
|
35
|
+
nonce: number
|
36
|
+
}
|
10
37
|
|
11
38
|
export type SignAuthMessageParameters<
|
39
|
+
chain extends Chain | undefined = Chain | undefined,
|
12
40
|
account extends Account | undefined = Account | undefined,
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
41
|
+
chainOverride extends Chain | undefined = Chain | undefined,
|
42
|
+
accountOverride extends Account | Address | undefined = Account | Address,
|
43
|
+
> = {
|
44
|
+
commit: Hash
|
45
|
+
invokerAddress: Address
|
46
|
+
} & GetAccountParameter<account, accountOverride> &
|
47
|
+
GetChainParameter<chain, chainOverride> &
|
48
|
+
GetNonceParameter<DeriveAccount<account, accountOverride>>
|
20
49
|
|
21
50
|
export type SignAuthMessageReturnType = Hex
|
22
51
|
|
@@ -77,25 +106,44 @@ export type SignAuthMessageErrorType = ErrorType
|
|
77
106
|
*/
|
78
107
|
export async function signAuthMessage<
|
79
108
|
chain extends Chain | undefined,
|
80
|
-
// TODO: Use `Account` when JSON-RPC method for sign auth message exists.
|
81
109
|
account extends Account | undefined,
|
110
|
+
chainOverride extends Chain | undefined = undefined,
|
111
|
+
accountOverride extends Account | undefined = undefined,
|
82
112
|
>(
|
83
113
|
client: Client<Transport, chain, account>,
|
84
|
-
|
85
|
-
|
114
|
+
parameters: SignAuthMessageParameters<
|
115
|
+
chain,
|
116
|
+
account,
|
117
|
+
chainOverride,
|
118
|
+
accountOverride
|
119
|
+
>,
|
120
|
+
): Promise<SignAuthMessageReturnType> {
|
121
|
+
const {
|
86
122
|
account = client.account,
|
87
|
-
|
123
|
+
chain = client.chain,
|
88
124
|
commit,
|
89
125
|
invokerAddress,
|
90
|
-
|
91
|
-
|
92
|
-
): Promise<SignAuthMessageReturnType> {
|
126
|
+
} = parameters
|
127
|
+
|
93
128
|
if (!account)
|
94
129
|
throw new AccountNotFoundError({
|
95
130
|
docsPath: '/experimental/eip5792/signAuthMessage',
|
96
131
|
})
|
97
|
-
|
98
|
-
|
132
|
+
|
133
|
+
const nonce = await (() => {
|
134
|
+
if (typeof parameters.nonce === 'number') return parameters.nonce
|
135
|
+
return getAction(
|
136
|
+
client,
|
137
|
+
getTransactionCount,
|
138
|
+
'getTransactionCount',
|
139
|
+
)({
|
140
|
+
address: account.address,
|
141
|
+
blockTag: 'pending',
|
142
|
+
})
|
143
|
+
})()
|
144
|
+
|
145
|
+
return account.experimental_signAuthMessage!({
|
146
|
+
chainId: chain!.id,
|
99
147
|
commit,
|
100
148
|
invokerAddress,
|
101
149
|
nonce,
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { Client } from '../../../clients/createClient.js'
|
2
2
|
import type { Transport } from '../../../clients/transports/createTransport.js'
|
3
|
-
import type { Account
|
3
|
+
import type { Account } from '../../../types/account.js'
|
4
4
|
import type { Chain } from '../../../types/chain.js'
|
5
5
|
import {
|
6
6
|
type SignAuthMessageParameters,
|
@@ -9,11 +9,18 @@ import {
|
|
9
9
|
} from '../actions/signAuthMessage.js'
|
10
10
|
|
11
11
|
export type WalletActionsEip3074<
|
12
|
+
chain extends Chain | undefined = Chain | undefined,
|
12
13
|
account extends Account | undefined = Account | undefined,
|
13
14
|
> = {
|
14
|
-
signAuthMessage:
|
15
|
+
signAuthMessage: <
|
16
|
+
chainOverride extends Chain | undefined = undefined,
|
17
|
+
accountOverride extends Account | undefined = undefined,
|
18
|
+
>(
|
15
19
|
parameters: SignAuthMessageParameters<
|
16
|
-
|
20
|
+
chain,
|
21
|
+
account,
|
22
|
+
chainOverride,
|
23
|
+
accountOverride
|
17
24
|
>,
|
18
25
|
) => Promise<SignAuthMessageReturnType>
|
19
26
|
}
|
@@ -42,7 +49,7 @@ export function walletActionsEip3074() {
|
|
42
49
|
account extends Account | undefined = Account | undefined,
|
43
50
|
>(
|
44
51
|
client: Client<transport, chain, account>,
|
45
|
-
): WalletActionsEip3074<account> => {
|
52
|
+
): WalletActionsEip3074<chain, account> => {
|
46
53
|
return {
|
47
54
|
signAuthMessage: (parameters) =>
|
48
55
|
signAuthMessage(client as any, parameters),
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { Address } from 'abitype'
|
2
2
|
|
3
|
-
import type { ByteArray, Hex } from '../../../types/misc.js'
|
3
|
+
import type { ByteArray, Hex, Signature } from '../../../types/misc.js'
|
4
4
|
|
5
5
|
import type { ErrorType } from '../../../errors/utils.js'
|
6
6
|
import { keccak256 } from '../../../utils/hash/keccak256.js'
|
@@ -11,7 +11,7 @@ import {
|
|
11
11
|
import { type ToAuthMessageParameters, toAuthMessage } from './toAuthMessage.js'
|
12
12
|
|
13
13
|
export type RecoverAuthMessageAddressParameters = ToAuthMessageParameters & {
|
14
|
-
signature: Hex | ByteArray
|
14
|
+
signature: Hex | ByteArray | Signature
|
15
15
|
}
|
16
16
|
|
17
17
|
export type RecoverAuthMessageAddressReturnType = Address
|
package/package.json
CHANGED
package/utils/rpc/http.ts
CHANGED
@@ -118,7 +118,10 @@ export function getHttpRpcClient(
|
|
118
118
|
response.headers.get('Content-Type')?.startsWith('application/json')
|
119
119
|
)
|
120
120
|
data = await response.json()
|
121
|
-
else
|
121
|
+
else {
|
122
|
+
data = await response.text()
|
123
|
+
data = JSON.parse(data || '{}')
|
124
|
+
}
|
122
125
|
|
123
126
|
if (!response.ok) {
|
124
127
|
throw new HttpRequestError({
|
package/utils/rpc/socket.ts
CHANGED
@@ -47,6 +47,7 @@ export type SocketRpcClient<socket extends {}> = {
|
|
47
47
|
|
48
48
|
export type GetSocketRpcClientParameters<socket extends {} = {}> = {
|
49
49
|
getSocket(params: GetSocketParameters): Promise<Socket<socket>>
|
50
|
+
key?: string
|
50
51
|
/**
|
51
52
|
* Whether or not to attempt to reconnect on socket failure.
|
52
53
|
* @default true
|
@@ -81,11 +82,11 @@ export const socketClientCache = /*#__PURE__*/ new Map<
|
|
81
82
|
export async function getSocketRpcClient<socket extends {}>(
|
82
83
|
params: GetSocketRpcClientParameters<socket>,
|
83
84
|
): Promise<SocketRpcClient<socket>> {
|
84
|
-
const { getSocket, reconnect = true, url } = params
|
85
|
+
const { getSocket, key = 'socket', reconnect = true, url } = params
|
85
86
|
const { attempts = 5, delay = 2_000 } =
|
86
87
|
typeof reconnect === 'object' ? reconnect : {}
|
87
88
|
|
88
|
-
let socketClient = socketClientCache.get(url)
|
89
|
+
let socketClient = socketClientCache.get(`${key}:${url}`)
|
89
90
|
|
90
91
|
// If the socket already exists, return it.
|
91
92
|
if (socketClient) return socketClient as {} as SocketRpcClient<socket>
|
@@ -95,7 +96,7 @@ export async function getSocketRpcClient<socket extends {}>(
|
|
95
96
|
undefined,
|
96
97
|
[SocketRpcClient<socket>]
|
97
98
|
>({
|
98
|
-
id: url
|
99
|
+
id: `${key}:${url}`,
|
99
100
|
fn: async () => {
|
100
101
|
// Set up a cache for incoming "synchronous" requests.
|
101
102
|
const requests = new Map<Id, CallbackFn>()
|
@@ -148,7 +149,7 @@ export async function getSocketRpcClient<socket extends {}>(
|
|
148
149
|
socketClient = {
|
149
150
|
close() {
|
150
151
|
socket.close()
|
151
|
-
socketClientCache.delete(url)
|
152
|
+
socketClientCache.delete(`${key}:${url}`)
|
152
153
|
},
|
153
154
|
socket,
|
154
155
|
request({ body, onError, onResponse }) {
|
@@ -210,7 +211,7 @@ export async function getSocketRpcClient<socket extends {}>(
|
|
210
211
|
subscriptions,
|
211
212
|
url,
|
212
213
|
}
|
213
|
-
socketClientCache.set(url
|
214
|
+
socketClientCache.set(`${key}:${url}`, socketClient)
|
214
215
|
|
215
216
|
return [socketClient as {} as SocketRpcClient<socket>]
|
216
217
|
},
|
@@ -21,11 +21,24 @@ export type HexToSignatureErrorType = NumberToHexErrorType | ErrorType
|
|
21
21
|
*/
|
22
22
|
export function hexToSignature(signatureHex: Hex) {
|
23
23
|
const { r, s } = secp256k1.Signature.fromCompact(signatureHex.slice(2, 130))
|
24
|
-
const
|
24
|
+
const yParityOrV = Number(`0x${signatureHex.slice(130)}`)
|
25
|
+
const [v, yParity] = (() => {
|
26
|
+
if (yParityOrV === 0 || yParityOrV === 1) return [undefined, yParityOrV]
|
27
|
+
if (yParityOrV === 27) return [BigInt(yParityOrV), 0]
|
28
|
+
if (yParityOrV === 28) return [BigInt(yParityOrV), 1]
|
29
|
+
throw new Error('Invalid yParityOrV value')
|
30
|
+
})()
|
31
|
+
|
32
|
+
if (typeof v !== 'undefined')
|
33
|
+
return {
|
34
|
+
r: numberToHex(r, { size: 32 }),
|
35
|
+
s: numberToHex(s, { size: 32 }),
|
36
|
+
v,
|
37
|
+
yParity,
|
38
|
+
} satisfies Signature
|
25
39
|
return {
|
26
40
|
r: numberToHex(r, { size: 32 }),
|
27
41
|
s: numberToHex(s, { size: 32 }),
|
28
|
-
|
29
|
-
yParity: v === 28n ? 1 : 0,
|
42
|
+
yParity,
|
30
43
|
} satisfies Signature
|
31
44
|
}
|
@@ -1,14 +1,14 @@
|
|
1
1
|
import type { Address } from 'abitype'
|
2
2
|
|
3
3
|
import { publicKeyToAddress } from '../../accounts/utils/publicKeyToAddress.js'
|
4
|
-
import type { ByteArray, Hex } from '../../types/misc.js'
|
4
|
+
import type { ByteArray, Hex, Signature } from '../../types/misc.js'
|
5
5
|
|
6
6
|
import type { ErrorType } from '../../errors/utils.js'
|
7
7
|
import { recoverPublicKey } from './recoverPublicKey.js'
|
8
8
|
|
9
9
|
export type RecoverAddressParameters = {
|
10
10
|
hash: Hex | ByteArray
|
11
|
-
signature: Hex | ByteArray
|
11
|
+
signature: Hex | ByteArray | Signature
|
12
12
|
}
|
13
13
|
|
14
14
|
export type RecoverAddressReturnType = Address
|
@@ -1,6 +1,11 @@
|
|
1
1
|
import type { Address } from 'abitype'
|
2
2
|
|
3
|
-
import type {
|
3
|
+
import type {
|
4
|
+
ByteArray,
|
5
|
+
Hex,
|
6
|
+
SignableMessage,
|
7
|
+
Signature,
|
8
|
+
} from '../../types/misc.js'
|
4
9
|
|
5
10
|
import type { ErrorType } from '../../errors/utils.js'
|
6
11
|
import { type HashMessageErrorType, hashMessage } from './hashMessage.js'
|
@@ -11,7 +16,7 @@ import {
|
|
11
16
|
|
12
17
|
export type RecoverMessageAddressParameters = {
|
13
18
|
message: SignableMessage
|
14
|
-
signature: Hex | ByteArray
|
19
|
+
signature: Hex | ByteArray | Signature
|
15
20
|
}
|
16
21
|
|
17
22
|
export type RecoverMessageAddressReturnType = Address
|
@@ -1,12 +1,16 @@
|
|
1
1
|
import type { ErrorType } from '../../errors/utils.js'
|
2
|
-
import type { ByteArray, Hex } from '../../types/misc.js'
|
2
|
+
import type { ByteArray, Hex, Signature } from '../../types/misc.js'
|
3
3
|
import { type IsHexErrorType, isHex } from '../data/isHex.js'
|
4
|
-
import {
|
4
|
+
import {
|
5
|
+
type HexToNumberErrorType,
|
6
|
+
hexToBigInt,
|
7
|
+
hexToNumber,
|
8
|
+
} from '../encoding/fromHex.js'
|
5
9
|
import { toHex } from '../encoding/toHex.js'
|
6
10
|
|
7
11
|
export type RecoverPublicKeyParameters = {
|
8
12
|
hash: Hex | ByteArray
|
9
|
-
signature: Hex | ByteArray
|
13
|
+
signature: Hex | ByteArray | Signature
|
10
14
|
}
|
11
15
|
|
12
16
|
export type RecoverPublicKeyReturnType = Hex
|
@@ -20,20 +24,39 @@ export async function recoverPublicKey({
|
|
20
24
|
hash,
|
21
25
|
signature,
|
22
26
|
}: RecoverPublicKeyParameters): Promise<RecoverPublicKeyReturnType> {
|
23
|
-
const signatureHex = isHex(signature) ? signature : toHex(signature)
|
24
27
|
const hashHex = isHex(hash) ? hash : toHex(hash)
|
25
28
|
|
26
|
-
// Derive v = recoveryId + 27 from end of the signature (27 is added when signing the message)
|
27
|
-
// The recoveryId represents the y-coordinate on the secp256k1 elliptic curve and can have a value [0, 1].
|
28
|
-
let v = hexToNumber(`0x${signatureHex.slice(130)}`)
|
29
|
-
if (v === 0 || v === 1) v += 27
|
30
|
-
|
31
29
|
const { secp256k1 } = await import('@noble/curves/secp256k1')
|
32
|
-
const
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
const signature_ = (() => {
|
31
|
+
// typeof signature: `Signature`
|
32
|
+
if (typeof signature === 'object' && 'r' in signature && 's' in signature) {
|
33
|
+
const { r, s, v, yParity } = signature
|
34
|
+
const yParityOrV = Number(yParity ?? v)!
|
35
|
+
const recoveryBit = toRecoveryBit(yParityOrV)
|
36
|
+
return new secp256k1.Signature(
|
37
|
+
hexToBigInt(r),
|
38
|
+
hexToBigInt(s),
|
39
|
+
).addRecoveryBit(recoveryBit)
|
40
|
+
}
|
41
|
+
|
42
|
+
// typeof signature: `Hex | ByteArray`
|
43
|
+
const signatureHex = isHex(signature) ? signature : toHex(signature)
|
44
|
+
const yParityOrV = hexToNumber(`0x${signatureHex.slice(130)}`)
|
45
|
+
const recoveryBit = toRecoveryBit(yParityOrV)
|
46
|
+
return secp256k1.Signature.fromCompact(
|
47
|
+
signatureHex.substring(2, 130),
|
48
|
+
).addRecoveryBit(recoveryBit)
|
49
|
+
})()
|
50
|
+
|
51
|
+
const publicKey = signature_
|
36
52
|
.recoverPublicKey(hashHex.substring(2))
|
37
53
|
.toHex(false)
|
38
54
|
return `0x${publicKey}`
|
39
55
|
}
|
56
|
+
|
57
|
+
function toRecoveryBit(yParityOrV: number) {
|
58
|
+
if (yParityOrV === 0 || yParityOrV === 1) return yParityOrV
|
59
|
+
if (yParityOrV === 27) return 0
|
60
|
+
if (yParityOrV === 28) return 1
|
61
|
+
throw new Error('Invalid yParityOrV value')
|
62
|
+
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { Address } from 'abitype'
|
2
2
|
import type { ErrorType } from '../../errors/utils.js'
|
3
|
-
import type { ByteArray, Hex } from '../../types/misc.js'
|
3
|
+
import type { ByteArray, Hex, Signature } from '../../types/misc.js'
|
4
4
|
import type { TransactionSerialized } from '../../types/transaction.js'
|
5
5
|
import { type Keccak256ErrorType, keccak256 } from '../hash/keccak256.js'
|
6
6
|
import { parseTransaction } from '../transaction/parseTransaction.js'
|
@@ -19,7 +19,7 @@ import {
|
|
19
19
|
|
20
20
|
export type RecoverTransactionAddressParameters = {
|
21
21
|
serializedTransaction: TransactionSerialized
|
22
|
-
signature?: Hex | ByteArray
|
22
|
+
signature?: Hex | ByteArray | Signature
|
23
23
|
}
|
24
24
|
|
25
25
|
export type RecoverTransactionAddressReturnType = Address
|
@@ -53,6 +53,7 @@ export async function recoverTransactionAddress(
|
|
53
53
|
s: undefined,
|
54
54
|
v: undefined,
|
55
55
|
yParity: undefined,
|
56
|
+
sidecars: undefined,
|
56
57
|
})
|
57
58
|
|
58
59
|
return await recoverAddress({
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { Address, TypedData } from 'abitype'
|
2
2
|
|
3
|
-
import type { ByteArray, Hex } from '../../types/misc.js'
|
3
|
+
import type { ByteArray, Hex, Signature } from '../../types/misc.js'
|
4
4
|
import type { TypedDataDefinition } from '../../types/typedData.js'
|
5
5
|
|
6
6
|
import type { ErrorType } from '../../errors/utils.js'
|
@@ -14,7 +14,7 @@ export type RecoverTypedDataAddressParameters<
|
|
14
14
|
typedData extends TypedData | Record<string, unknown> = TypedData,
|
15
15
|
primaryType extends keyof typedData | 'EIP712Domain' = keyof typedData,
|
16
16
|
> = TypedDataDefinition<typedData, primaryType> & {
|
17
|
-
signature: Hex | ByteArray
|
17
|
+
signature: Hex | ByteArray | Signature
|
18
18
|
}
|
19
19
|
|
20
20
|
export type RecoverTypedDataAddressReturnType = Address
|
@@ -1,6 +1,11 @@
|
|
1
1
|
import type { Address } from 'abitype'
|
2
2
|
|
3
|
-
import type {
|
3
|
+
import type {
|
4
|
+
ByteArray,
|
5
|
+
Hex,
|
6
|
+
SignableMessage,
|
7
|
+
Signature,
|
8
|
+
} from '../../types/misc.js'
|
4
9
|
import { type GetAddressErrorType, getAddress } from '../address/getAddress.js'
|
5
10
|
import {
|
6
11
|
type IsAddressEqualErrorType,
|
@@ -19,7 +24,7 @@ export type VerifyMessageParameters = {
|
|
19
24
|
/** The message to be verified. */
|
20
25
|
message: SignableMessage
|
21
26
|
/** The signature that was generated by signing the message with the address's private key. */
|
22
|
-
signature: Hex | ByteArray
|
27
|
+
signature: Hex | ByteArray | Signature
|
23
28
|
}
|
24
29
|
|
25
30
|
export type VerifyMessageReturnType = boolean
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { Address, TypedData } from 'abitype'
|
2
2
|
|
3
|
-
import type { ByteArray, Hex } from '../../types/misc.js'
|
3
|
+
import type { ByteArray, Hex, Signature } from '../../types/misc.js'
|
4
4
|
import type { TypedDataDefinition } from '../../types/typedData.js'
|
5
5
|
import { type GetAddressErrorType, getAddress } from '../address/getAddress.js'
|
6
6
|
import {
|
@@ -21,7 +21,7 @@ export type VerifyTypedDataParameters<
|
|
21
21
|
/** The address to verify the typed data for. */
|
22
22
|
address: Address
|
23
23
|
/** The signature to verify */
|
24
|
-
signature: Hex | ByteArray
|
24
|
+
signature: Hex | ByteArray | Signature
|
25
25
|
}
|
26
26
|
|
27
27
|
export type VerifyTypedDataReturnType = boolean
|
@@ -95,7 +95,7 @@ export async function sendEip712Transaction<
|
|
95
95
|
// Prepare the request for signing (assign appropriate fees, etc.)
|
96
96
|
const request = await prepareTransactionRequest(client, {
|
97
97
|
...args,
|
98
|
-
parameters: ['gas', 'nonce'],
|
98
|
+
parameters: ['gas', 'nonce', 'fees'],
|
99
99
|
} as any)
|
100
100
|
|
101
101
|
let chainId: number | undefined
|
package/zksync/formatters.ts
CHANGED
@@ -8,6 +8,7 @@ import { formatLog } from '../utils/formatters/log.js'
|
|
8
8
|
import { defineTransaction } from '../utils/formatters/transaction.js'
|
9
9
|
import { defineTransactionReceipt } from '../utils/formatters/transactionReceipt.js'
|
10
10
|
import { defineTransactionRequest } from '../utils/formatters/transactionRequest.js'
|
11
|
+
import { gasPerPubdataDefault } from './constants/number.js'
|
11
12
|
import type {
|
12
13
|
ZkSyncBlockOverrides,
|
13
14
|
ZkSyncRpcBlockOverrides,
|
@@ -125,7 +126,7 @@ export const formatters = {
|
|
125
126
|
eip712Meta: {
|
126
127
|
...(args.gasPerPubdata
|
127
128
|
? { gasPerPubdata: toHex(args.gasPerPubdata) }
|
128
|
-
: {}),
|
129
|
+
: { gasPerPubdata: toHex(gasPerPubdataDefault) }),
|
129
130
|
...(args.paymaster && args.paymasterInput
|
130
131
|
? {
|
131
132
|
paymasterParams: {
|
package/zksync/serializers.ts
CHANGED
@@ -5,6 +5,7 @@ import { concatHex } from '../utils/data/concat.js'
|
|
5
5
|
import { toHex } from '../utils/encoding/toHex.js'
|
6
6
|
import { toRlp } from '../utils/encoding/toRlp.js'
|
7
7
|
import { serializeTransaction as serializeTransaction_ } from '../utils/transaction/serializeTransaction.js'
|
8
|
+
import { gasPerPubdataDefault } from './constants/number.js'
|
8
9
|
import type {
|
9
10
|
ZkSyncTransactionSerializable,
|
10
11
|
ZkSyncTransactionSerializableEIP712,
|
@@ -69,7 +70,7 @@ function serializeTransactionEIP712(
|
|
69
70
|
toHex(''),
|
70
71
|
toHex(chainId),
|
71
72
|
from ?? '0x',
|
72
|
-
gasPerPubdata ? toHex(gasPerPubdata) :
|
73
|
+
gasPerPubdata ? toHex(gasPerPubdata) : toHex(gasPerPubdataDefault),
|
73
74
|
factoryDeps ?? [],
|
74
75
|
customSignature ?? '0x', // EIP712 signature
|
75
76
|
paymaster && paymasterInput ? [paymaster, paymasterInput] : [],
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { toHex } from '../../utils/encoding/toHex.js'
|
2
|
+
import { gasPerPubdataDefault } from '../constants/number.js'
|
2
3
|
import type { EIP712DomainFn } from '../types/eip712.js'
|
3
4
|
import type {
|
4
5
|
ZkSyncEIP712TransactionSignable,
|
@@ -72,7 +73,7 @@ function transactionToMessage(
|
|
72
73
|
from: BigInt(from),
|
73
74
|
to: to ? BigInt(to) : 0n,
|
74
75
|
gasLimit: gas ?? 0n,
|
75
|
-
gasPerPubdataByteLimit: gasPerPubdata ??
|
76
|
+
gasPerPubdataByteLimit: gasPerPubdata ?? gasPerPubdataDefault,
|
76
77
|
maxFeePerGas: maxFeePerGas ?? 0n,
|
77
78
|
maxPriorityFeePerGas: maxPriorityFeePerGas ?? 0n,
|
78
79
|
paymaster: paymaster ? BigInt(paymaster) : 0n,
|