-
-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update chain ID format #1367
Update chain ID format #1367
Conversation
3bf31ba
to
362dea8
Compare
362dea8
to
eea0f1b
Compare
Suggestions for the changelog:
|
@@ -93,7 +94,7 @@ export function validateTypedSignMessageDataV1( | |||
*/ | |||
export function validateTypedSignMessageDataV3V4( | |||
messageData: TypedMessageParams, | |||
currentChainId: string | undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this still be undefined
? I see this in TypedMessageManager.addUnapprovedMessageAsync
:
const currentChainId = this.getCurrentChainId?.();
validateTypedSignMessageDataV3V4(messageParams, currentChainId);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep! It's declared here as optional though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Undefined and optional are the same now, but I'm wondering whether they will be the same when we enable exactOptionalPropertyTypes
(assuming we want to revive this PR).
That said, maybe it's the caller's responsibility to not pass this argument if it doesn't need to, so your change makes sense. Never mind!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. yeah OK, I can switch it back to | undefined
instead to make that switch easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in 4407595
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That said, maybe it's the caller's responsibility to not pass this argument if it doesn't need to, so your change makes sense. Never mind!
This was my first thought as well, but in this case it seems more ergonomic to always expect this to be passed in IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, other than the suggestions I made for the changelog.
Great catch on the address book/ens entries, I have updated the changelog accordingly.
Yes, it's affected via the fourth parameter, which contains a chain ID
I thought the same thing at first, but it's not affected. That accepts a That type has always accepted a 0x-prefixed hex string, so no change was needed. |
The chain ID is now formatted internally as a `0x`-prefixed hex string. This was chosen as the internal format for these reasons: * It allows arbitrarily large chain IDs, unlike `number` * It can be validated at runtime, unlike decimal strings * It can be disambiguated from decimal strings and numbers at compile- time using the `Hex` type, unlike decimal strings * It is serializable as JSON, unlike BigInt However, to improve readability we will use the `toHex` helper function rather than string literals, letting us read chain IDs in the source code as decimal numbers or strings. Closes #1209
Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
6e565ab
to
e9d6530
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
The `chainId` parameter is now `Hex | undefined` rather than an optional `Hex`, to make it more compatible with the `exactOptionalPropertyTypes` option (which we plan on enabling in the future).
The chain ID is now formatted internally as a `0x`-prefixed hex string. This was chosen as the internal format for these reasons: * It allows arbitrarily large chain IDs, unlike `number` * It can be validated at runtime, unlike decimal strings * It can be disambiguated from decimal strings and numbers at compile- time using the `Hex` type, unlike decimal strings * It is serializable as JSON, unlike BigInt However, to improve readability we will use the `toHex` helper function rather than string literals, letting us read chain IDs in the source code as decimal numbers or strings. Closes MetaMask#1209 --------- Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
The chain ID is now formatted internally as a `0x`-prefixed hex string. This was chosen as the internal format for these reasons: * It allows arbitrarily large chain IDs, unlike `number` * It can be validated at runtime, unlike decimal strings * It can be disambiguated from decimal strings and numbers at compile- time using the `Hex` type, unlike decimal strings * It is serializable as JSON, unlike BigInt However, to improve readability we will use the `toHex` helper function rather than string literals, letting us read chain IDs in the source code as decimal numbers or strings. Closes #1209 --------- Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
The chain ID is now formatted internally as a `0x`-prefixed hex string. This was chosen as the internal format for these reasons: * It allows arbitrarily large chain IDs, unlike `number` * It can be validated at runtime, unlike decimal strings * It can be disambiguated from decimal strings and numbers at compile- time using the `Hex` type, unlike decimal strings * It is serializable as JSON, unlike BigInt However, to improve readability we will use the `toHex` helper function rather than string literals, letting us read chain IDs in the source code as decimal numbers or strings. Closes #1209 --------- Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
Description
The chain ID is now formatted internally as a
0x
-prefixed hex string. This was chosen as the internal format for these reasons:number
Hex
type, unlike decimal stringsHowever, to improve readability we will use the
toHex
helper function rather than string literals, letting us read chain IDs in the source code as decimal numbers or strings.Changes
@metamask/address-book-controller
addressBook
state property is now keyed byHex
chain ID rather thanstring
, and thechainId
property of each address book entry is alsoHex
rather thanstring
.delete
andset
now except the chain ID asHex
rather than as a decimal string@metamask/utils
dependency@metamask/assets-controllers
@metamask/network-controller
peerDependencyisTokenDetectionSupportedForNetwork
andformatIconUrlWithProxy
now expect a chain ID as typeHex
rather than as a decimalstring
chainId
configuration entry and constructor parameter as typeHex
rather than decimalstring
chainId
configuration entry and constructor parameter as typeHex
rather than decimalstring
addNft
,checkAndUpdateSingleNftOwnershipStatus
,findNftByAddressAndTokenId
,updateNft
, andresetNftTransactionStatusByTransactionId
now expect the chain ID to be typeHex
rather than a decimalstring
allNftContracts
andallNfts
are now keyed by address andHex
chain ID, rather than by address and decimalstring
chain IDchainId
configuration entry and constructor parameter as typeHex
rather than decimalstring
chainId
configuration entry as typeHex
rather than decimalstring
chainId
constructor parameter as typeHex
rather than decimalstring
tokensChainsCache
is now keyed byHex
chain ID rather than by decimalstring
chain ID.chainId
configuration entry and constructor parameter as typeHex
rather than decimalstring
chainId
setter now expects the chain ID asHex
rather than as a decimal stringchainId
configuration entry and constructor parameter as typeHex
rather than decimalstring
addDetectedTokens
method now accepts thechainId
property of thedetectionDetails
parameter to be of typeHex
rather than decimalstring
.allTokens
,allIgnoredTokens
, andallDetectedTokens
are now keyed by chain ID inHex
format rather than decimalstring
.@metamask/controller-utils
isSafeChainId
parameterchainId
is now typeHex
rather thannumber
ChainId
enum and theGANACHE_CHAIN_ID
constant are now formatted as 0x-prefixed hex strings rather than as decimal strings.@metamask/ens-controller
@metamask/network-controller
peerDependencyensEntries
state property is now keyed byHex
chain ID rather thanstring
, and thechainId
property of each ENS entry is alsoHex
rather thanstring
.get
,set
, anddelete
have been updated to accept and return chain IDs as 0x-prefixed hex strings, rather than decimal strings.@metamask/gas-fee-controller
@metamask/network-controller
peerDependencygetChainId
constructor parameter now expects aHex
return type rather than a decimal string@metamask/utils
dependency@metamask/message-manager
getCurrentChainId
constructor parameter for each message manager now expects aHex
return type rather than a decimal stringTypedMessageManager
at the moment.@metamask/network-controller
providerConfig
type and state property have changed. ThechainId
property is now a 0x-prefixed hex string rather than a decimal string.NetworkController:getProviderConfig
andNetworkController:getState
actions.NetworkConfiguration
type and thenetworkConfigurations
state property have changed. ThechainId
property on each configuration is now a 0x-prefixed hex string rather than a decimal string.upsertNetworkConfiguration
method, which takes a network configuration as the first parameterNetworkController:getState
action@metamask/signature-controller
getCurrentChainId
now expects aHex
return value rather thanstring
@metamask/utils
dependency@metamask/transaction-controller
@metamask/network-controller
dependencygetNetworkState
andonNetworkStateChange
constructor parameterschainId
property of theTransaction
type has been changed from a number to a 0x-prefixed hex stringchainId
property of theTransactionMeta
type has been changed from a decimal string to a 0x-prefixed hex string, and thetransaction
property has been updated along with theTransaction
type (as described above).transactions
is an array ofTransactionMeta
objects, so it has changed according to the description above.chainId
property converted from a decimal string to a 0x-prefixed hex string, and thetransaction.chainId
property changed from a number to a 0x-prefixed hex string.addTransaction
andestimateGas
methods now expect the first parameter (transaction
) to use the 0x-prefixed hex string format for thechainId
property.updateTransaction
method now expects thetransactionMeta
parameter to use the 0x-prefixed hex string format for thechainId
property (and for the nestedtransaction.chainId
property)@metamask/utils
dependencyReferences
Closes #1209
Checklist