diff --git a/docs.wrm/api-keys.wrm b/docs.wrm/api-keys.wrm index e8ba12248..350ec35cb 100644 --- a/docs.wrm/api-keys.wrm +++ b/docs.wrm/api-keys.wrm @@ -10,7 +10,7 @@ permissions. The ethers library offers default API keys for each service, so that each [[Provider]] works out-of-the-box. -These API keys are a provided as a community resource by the backend services +These API keys are provided as a community resource by the backend services for low-traffic projects and for early prototyping. Since these API keys are shared by all users (that have not acquired their @@ -43,7 +43,7 @@ operations required to interact with the Ethereum Blockchain. _subsection: INFURA @ The INFURA service has been around for quite some time and is very robust -and reliable and highly recommend. +and reliable and highly recommended. They offer a standard JSON-RPC interface and a WebSocket interface, which makes interaction with standard tools versatile, simple and straight forward. @@ -74,6 +74,18 @@ with debugging. - access to advanced token balance and metadata APIs - access to advanced debugging trace and revert reason APIs +_subsection: Pocket Gateway@ + + +[Sign up for a free API key on Pocket](link-pocket-signup) + +**Benefits:** + +- customer usage metrics +- decentralized Access to Blockchain Infrastructure +- Stake as opposed to paying a monthly fee +- Highly redundant global set of nodes incentivized by cryptoeconomic incentives + _subsection: Creating a Default Provider @ @@ -99,5 +111,16 @@ const network = "homestead"; const provider = ethers.getDefaultProvider(network, { etherscan: YOUR_ETHERSCAN_API_KEY, infura: YOUR_INFURA_PROJECT_ID, - alchemy: YOUR_ALCHEMY_API_KEY + // Or if using a project secret: + // infura: { + // projectId: YOUR_INFURA_PROJECT_ID, + // projectSecret: YOUR_INFURA_PROJECT_SECRET, + // }, + alchemy: YOUR_ALCHEMY_API_KEY, + pocket: YOUR_POCKET_APPLICATION_KEY + // Or if using an application secret key: + // pocket: { + // applicationId: , + // applicationSecretKey: + // } }); diff --git a/docs.wrm/api/contract/contract-factory.wrm b/docs.wrm/api/contract/contract-factory.wrm index df16a86ce..af7ae895b 100644 --- a/docs.wrm/api/contract/contract-factory.wrm +++ b/docs.wrm/api/contract/contract-factory.wrm @@ -26,7 +26,7 @@ _property: contractFactory.attach(address) => [[Contract]] @ [[UnsignedTransaction]] diff --git a/docs.wrm/api/experimental.wrm b/docs.wrm/api/experimental.wrm index c0eca3c05..448b24101 100644 --- a/docs.wrm/api/experimental.wrm +++ b/docs.wrm/api/experimental.wrm @@ -55,11 +55,11 @@ The provider associated with the signer. _property: nonceManager.setTransactionCount(count) => void Set the current transaction count (nonce) for the signer. -This may be useful it interacting with the signer outside of using +This may be useful in interacting with the signer outside of using this class. _property: nonceManager.increaseTransactionCount( [ count = 1 ]) => void Bump the current transaction count (nonce) by //count//. -This may be useful it interacting with the signer outside of using +This may be useful in interacting with the signer outside of using this class. diff --git a/docs.wrm/api/other/assembly/ast.wrm b/docs.wrm/api/other/assembly/ast.wrm index a9ed91096..eb462bfb2 100644 --- a/docs.wrm/api/other/assembly/ast.wrm +++ b/docs.wrm/api/other/assembly/ast.wrm @@ -57,7 +57,7 @@ _heading: PopNode @ @INHERIT<[[asm-valuenode]]> @SRC number @@ -72,7 +72,7 @@ A **LinkNode** represents a link to another [[asm-node]]'s data, for example ``$foo`` or ``#bar``. _property: linkNode.label => string -Te name of the target node. +The name of the target node. _property: linkNode.type => "offset" | "length" Whether this node is for an offset or a length value of the @@ -115,7 +115,7 @@ The code to execute. Any result is ignored. _heading: LabelledNode @ @INHERIT<[[asm-node]]> @SRC A **LabelledNode** is used for any Node that has a name, and can therefore -be targetted by a [[asm-linknode]]. +be targeted by a [[asm-linknode]]. _property: labelledNode.name => string The name of this node. diff --git a/docs.wrm/api/other/assembly/dialect.wrm b/docs.wrm/api/other/assembly/dialect.wrm index b19baf8e6..5e7d706aa 100644 --- a/docs.wrm/api/other/assembly/dialect.wrm +++ b/docs.wrm/api/other/assembly/dialect.wrm @@ -76,7 +76,7 @@ A scope may access the offset of any child [[asm-dialect-datasegment]] or child [[asm-dialect-scope]] (with respect to itself) and may access the length of any [[asm-dialect-datasegment]] or [[asm-dialect-scope]] anywhere in the program. -Every program in the **Ethers ASM Dialect** has a top-leve scope named ``_``. +Every program in the **Ethers ASM Dialect** has a top-level scope named ``_``. _subsection: Data Segment @ diff --git a/docs.wrm/api/providers/api-providers.wrm b/docs.wrm/api/providers/api-providers.wrm index 921ac743c..6ac4d70cb 100644 --- a/docs.wrm/api/providers/api-providers.wrm +++ b/docs.wrm/api/providers/api-providers.wrm @@ -6,7 +6,7 @@ to them, which simplifies development, since you do not need to run your own instance or cluster of Ethereum nodes. However, this reliance on third-party services can reduce -resiliance, security and increase the amount of required trust. +resilience, security and increase the amount of required trust. To mitigate these issues, it is recommended you use a [Default Provider](providers-getDefaultProvider). @@ -20,7 +20,7 @@ _property: new ethers.providers.EtherscanProvider([ network = "homestead", [ api Create a new **EtherscanProvider** connected to //network// with the optional //apiKey//. -The //network// may be specified as **string** for a common +The //network// may be specified as a **string** for a common network name, a **number** for a common chain ID or a [Network Object]provider-(network). @@ -86,7 +86,7 @@ _property: new ethers.providers.InfuraProvider([ network = "homestead", [ apiKey Create a new **InfuraProvider** connected to //network// with the optional //apiKey//. -The //network// may be specified as **string** for a common +The //network// may be specified as a **string** for a common network name, a **number** for a common chain ID or a [Network Object]provider-(network). @@ -157,7 +157,7 @@ _property: new ethers.providers.AlchemyProvider([ network = "homestead", [ apiKe Create a new **AlchemyProvider** connected to //network// with the optional //apiKey//. -The //network// may be specified as **string** for a common +The //network// may be specified as a **string** for a common network name, a **number** for a common chain ID or a [Network Object](providers-Network). diff --git a/docs.wrm/api/providers/index.wrm b/docs.wrm/api/providers/index.wrm index 5c401e206..caf1d4039 100644 --- a/docs.wrm/api/providers/index.wrm +++ b/docs.wrm/api/providers/index.wrm @@ -20,7 +20,7 @@ for use in production. It creates a [[FallbackProvider]] connected to as many backend services as possible. When a request is made, it is sent to -multiple backends simulatenously. As responses from each backend +multiple backends simultaneously. As responses from each backend are returned, they are checked that they agree. Once a quorum has been reached (i.e. enough of the backends agree), the response is provided to your application. @@ -31,7 +31,7 @@ responses that match the majority. _property: ethers.getDefaultProvider([ network, [ options ] ]) => [[Provider]] Returns a new Provider, backed by multiple services, connected -to //network//. Is no //network// is provided, **homestead** +to //network//. If no //network// is provided, **homestead** (i.e. mainnet) is used. The //network// may also be a URL to connect to, such as ``http:/\/localhost:8545`` @@ -43,20 +43,22 @@ _table: Option Properties $Alchemy: [[link-alchemy]] API Token $Etherscan: [[link-etherscan]] API Token -$Infura: [[link-infura]] Project ID or ProjectID and Project Secret +$Infura: [[link-infura]] Project ID or ``{ projectId, projectSecret }`` +$Pocket: [[link-pocket]] Application ID or ``{ applicationId, applicationSecretKey }`` $Quorum: The number of backends that must agree //(default: 2 for mainnet, 1 for testnets)// - + | **Property** | **Description** | | //alchemy// | $Alchemy | | //etherscan// | $Etherscan | | //infura// | $Infura | +| //pocket// | $Pocket | | //quorum// | $Quorum | _note: Note: API Keys -It is highly recommended for production services that to acquire -and specify an API Key for each sercice. +It is highly recommended for production services to acquire +and specify an API Key for each service. The default API Keys used by ethers are shared across all users, so services may throttle all services that are using the default diff --git a/docs.wrm/api/providers/other.wrm b/docs.wrm/api/providers/other.wrm index 89fdb311c..c659439ae 100644 --- a/docs.wrm/api/providers/other.wrm +++ b/docs.wrm/api/providers/other.wrm @@ -41,7 +41,7 @@ The provider for this configuration. _property: fallbackProviderConfig.priority => number The priority used for the provider. Higher priorities are favoured over lower -priorities. If multiple providers share the same prioirty, they are chosen +priorities. If multiple providers share the same priority, they are chosen at random. _property: fallbackProviderConfig.stallTimeout => number @@ -152,7 +152,7 @@ which allows for a persistent connection, multiplexing requests and pub-sub events for a more immediate event dispatching. The WebSocket API is newer, and if running your own infrastructure, note that -WebSockets are much more intensive on your server resourses, as they must manage +WebSockets are much more intensive on your server resources, as they must manage and maintain the state for each client. For this reason, many services may also charge additional fees for using their WebSocket endpoints. diff --git a/docs.wrm/api/providers/provider.wrm b/docs.wrm/api/providers/provider.wrm index 997e155a5..fc728100a 100644 --- a/docs.wrm/api/providers/provider.wrm +++ b/docs.wrm/api/providers/provider.wrm @@ -146,7 +146,7 @@ _subsection: Transactions Methods @ _property: provider.call(transaction [ , blockTag = latest ]) => Promise> @ @SRC Returns the result of executing the //transaction//, using //call//. A call does not require any ether, but cannot change any state. This is useful -for calling gettings on Contracts. +for calling getters on Contracts. _property: provider.estimateGas(transaction) => Promise<[[BigNumber]]> @ @SRC Returns an estimate of the amount of gas that would be required to submit //transaction// @@ -174,7 +174,7 @@ Add a //listener// to be triggered for each //eventName//. _property: provider.once(eventName, listener) => this @ @SRC Add a //listener// to be triggered for only the next //eventName//, -at which time it be removed. +at which time it will be removed. _property: provider.emit(eventName, ...args) => boolean @ @SRC Notify all listeners of //eventName//, passing //args// to each listener. This diff --git a/docs.wrm/api/providers/types.wrm b/docs.wrm/api/providers/types.wrm index cfada06ac..d42a5ab51 100644 --- a/docs.wrm/api/providers/types.wrm +++ b/docs.wrm/api/providers/types.wrm @@ -59,19 +59,19 @@ The timestamp of this block. _property: block.nonce => string<[[DataHexString]]> The nonce used as part of the proof-of-work to mine this block. -This property is generally of little interest developers. +This property is generally of little interest to developers. _property: block.difficulty => number The difficulty target required to be met by the miner of the block. -This property is generally of little interest developers. +This property is generally of little interest to developers. _property: block.gasLimit => [[BigNumber]] The maximum amount of gas that this block was permitted to use. This is a value that can be voted up or voted down by miners and is used to automatically adjust the bandwidth requirements of the network. -This property is generally of little interest developers. +This property is generally of little interest to developers. _property: block.gasUsed => [[BigNumber]] The total amount of gas used by all transactions in this block. @@ -83,7 +83,7 @@ miner that mined this block would like the subsidy reward to go to. _property: block.extraData => string This is extra data a miner may choose to include when mining a block. -This property is generally of little interest developers. +This property is generally of little interest to developers. _heading: Block (with transaction hashes) @@ -238,7 +238,7 @@ Wait for //confirmations//. If 0, and the transaction has not been mined, _heading: TransactionReceipt @ _property: receipt.to => string<[[address]]> -The address this transaction is to. This is ``null`` if the the +The address this transaction is to. This is ``null`` if the transaction was an **init transaction**, used to deploy a contract. _property: receipt.from => string<[[address]]> @@ -295,7 +295,7 @@ including the actual block it was mined in. _property: receipt.cumulativeGasUsed => [[BigNumber]] For the block this transaction was included in, this is the sum of the -gas used used by each transaction in the ordered list of transactions +gas used by each transaction in the ordered list of transactions up to (and including) this transaction. This is generally of little interest to developers. diff --git a/docs.wrm/api/signer.wrm b/docs.wrm/api/signer.wrm index 6d02cffe4..44286eeae 100644 --- a/docs.wrm/api/signer.wrm +++ b/docs.wrm/api/signer.wrm @@ -6,7 +6,7 @@ which can be used to sign messages and transactions and send signed transactions to the Ethereum Network to execute state changing operations. -The available operations depends largely on the sub-class used. +The available operations depend largely on the sub-class used. For example, a Signer from MetaMask can send transactions and sign messages but cannot sign a transaction (without broadcasting it). @@ -20,9 +20,9 @@ The most common Signers you will encounter are: _subsection: Signer @ @SRC -The **Signer** class is abstract and cannot be directly instaniated. +The **Signer** class is abstract and cannot be directly instantiated. -Instead use one of the concreate sub-classes, such as the [[Wallet]], +Instead use one of the concrete sub-classes, such as the [[Wallet]], [[VoidSigner]] or [[JsonRpcSigner]]. _property: signer.connect(provider) => [[Signer]] @ @@ -112,6 +112,63 @@ Sub-classes **must** implement this, however they may throw if sending a transaction is not supported, such as the [[VoidSigner]] or if the Wallet is offline and not connected to a [[Provider]]. +_property: signer._signTypedData(domain, types, value) => Promise> @ + +Signs the typed data //value// with //types// data structure for //domain// using +the [[link-eip-712]] specification. + +_warning: Experimental feature (this method name will change) + +This is still an experimental feature. If using it, please specify the **exact** +version of ethers you are using (e.g. spcify ``"5.0.18"``, **not** ``"^5.0.18"``) as +the method name will be renamed from ``_signTypedData`` to ``signTypedData`` once +it has been used in the field a bit. + +_code: Typed Data Example @lang + +// +signer = new Wallet("0x1234567890123456789012345678901234567890123456789012345678901234"); +// + +// All properties on a domain are optional +const domain = { + name: 'Ether Mail', + version: '1', + chainId: 1, + verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC' +}; + +// The named list of all type definitions +const types = { + Person: [ + { name: 'name', type: 'string' }, + { name: 'wallet', type: 'address' } + ], + Mail: [ + { name: 'from', type: 'Person' }, + { name: 'to', type: 'Person' }, + { name: 'contents', type: 'string' } + ] +}; + +// The data to sign +const value = { + from: { + name: 'Cow', + wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826' + }, + to: { + name: 'Bob', + wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB' + }, + contents: 'Hello, Bob!' +}; + + +const signature = await signer._signTypedData(domain, types, value); +//! async signature + + _heading: Sub-Classes @ It is very important that all important properties of a **Signer** are @@ -124,20 +181,20 @@ and libraries make this assumption. A sub-class **must** extend Signer and **must** call ``super()``. _property: signer.checkTransaction(transactionRequest) => [[providers-TransactionRequest]] @ @SRC -This is generally not required to be overridden, but may needed to provide +This is generally not required to be overridden, but may be needed to provide custom behaviour in sub-classes. This should return a **copy** of the //transactionRequest//, with any properties needed by ``call``, ``estimateGas`` and ``populateTransaction`` (which is used by sendTransaction). It should also throw an error if any unknown key is specified. -The default implementation checks only valid [[providers-TransactionRequest]] properties +The default implementation checks only if valid [[providers-TransactionRequest]] properties exist and adds ``from`` to the transaction if it does not exist. If there is a ``from`` field it **must** be verified to be equal to the Signer's address. _property: signer.populateTransaction(transactionRequest) => Promise<[[providers-TransactionRequest]]> @ @SRC -This is generally not required to be overridden, but may needed to provide +This is generally not required to be overridden, but may be needed to provide custom behaviour in sub-classes. This should return a **copy** of //transactionRequest//, follow the same procedure @@ -193,7 +250,7 @@ _property: wallet.address => string<[[address]]> The address for the account this Wallet represents. _property: wallet.provider => [[Provider]] -The provider this wallet is connected to, which will ge used for any [[Signer--blockchain-methods]] +The provider this wallet is connected to, which will be used for any [[Signer--blockchain-methods]] methods. This can be null. _note: Note @@ -352,5 +409,5 @@ The privateKey of this EOA _property: eoa.mnemonic => [[Mnemonic]] //Optional//. The account HD mnemonic, if it has one and can be -determined. Some sources do not encode the mnemonic, such as an +determined. Some sources do not encode the mnemonic, such as HD extended keys. diff --git a/docs.wrm/api/utils/abi/coder.wrm b/docs.wrm/api/utils/abi/coder.wrm index c08087b55..6863f71d5 100644 --- a/docs.wrm/api/utils/abi/coder.wrm +++ b/docs.wrm/api/utils/abi/coder.wrm @@ -39,7 +39,7 @@ _subsection: Coding Methods @ _property: abiCoder.encode(types, values) => string<[[DataHexString]]> @ @SRC -Encode the array //values// according the array of //types//, each of which may be a +Encode the array //values// according to the array of //types//, each of which may be a string or a [[ParamType]]. _property: abiCoder.decode(types, data) => [[Result]] @ @SRC diff --git a/docs.wrm/api/utils/abi/fragments.wrm b/docs.wrm/api/utils/abi/fragments.wrm index 046fe2823..aa9498745 100644 --- a/docs.wrm/api/utils/abi/fragments.wrm +++ b/docs.wrm/api/utils/abi/fragments.wrm @@ -31,7 +31,7 @@ _property: ethers.utils.FragmentTypes.full => string This is a full human-readable string, including all parameter names, any optional modifiers (e.g. ``indexed``, ``public``, etc) and white-space -to aid in human readabiliy. +to aid in human readability. _property: ethers.utils.FragmentTypes.minimal => string @@ -81,7 +81,7 @@ will be one of: _property: fragment.inputs => Array<[[ParamType]]> -This is an array of of each [[ParamType]] for the input parameters to +This is an array of each [[ParamType]] for the input parameters to the Constructor, Event of Function. _heading: Methods @@ -211,13 +211,13 @@ to parameters which are part of an [[EventFragment]]. _property: paramType.arrayChildren => [[ParamType]] @ -The type of children of the array. This is null for for any parameter +The type of children of the array. This is null for any parameter which is not an array. _property: paramType.arrayLength => number @ The length of the array, or ``-1`` for dynamic-length arrays. This is -null for parameters which is not arrays. +null for parameters which are not arrays. _property: paramType.components => Array<[[ParamType]]> @ diff --git a/docs.wrm/api/utils/bignumber.wrm b/docs.wrm/api/utils/bignumber.wrm index 2b448cbbc..a820802ea 100644 --- a/docs.wrm/api/utils/bignumber.wrm +++ b/docs.wrm/api/utils/bignumber.wrm @@ -4,7 +4,7 @@ Many operations in Ethereum operation on numbers which are [outside the range of safe values](BigNumber--notes-safenumbers) to use in JavaScript. -A **BigNumber** is an object which safely allows mathematic operations +A **BigNumber** is an object which safely allows mathematical operations on numbers of any magnitude. Most operations which need to return a value will return a **BigNumber** @@ -126,7 +126,7 @@ _heading: Two's Complement [Two's Complement](link-wiki-twoscomplement) is an elegant method used to encode and decode fixed-width signed values -while efficiently preserving mathematic operations. +while efficiently preserving mathematical operations. Most users will not need to interact with these. _property: BigNumber.fromTwos(bitwidth) => [[BigNumber]] @SRC @@ -270,7 +270,7 @@ various purposes. _heading: Allow us to set a global Big Number library? -Another comment that comes up frequently is tha desire to specify a +Another comment that comes up frequently is the desire to specify a global user-defined Big Number library, which all functions would return. diff --git a/docs.wrm/api/utils/display-logic.wrm b/docs.wrm/api/utils/display-logic.wrm index 26b4f12c9..ab5757601 100644 --- a/docs.wrm/api/utils/display-logic.wrm +++ b/docs.wrm/api/utils/display-logic.wrm @@ -1,4 +1,4 @@ -_section: Display Logic and Input +_section: Display Logic and Input @ When creating an Application, it is useful to convert between user-friendly strings (usually displaying **ether**) and the @@ -17,11 +17,11 @@ The [formatUnits](unit-conversion) will format a [BigNumberish](BigNumberish) into a string, which is useful when displaying a balance. -_subsection: Units +_subsection: Units @ _heading: Decimal Count -A **Unit** can be specified as an number, which indicates the +A **Unit** can be specified as a number, which indicates the number of decimal places that should be used. **Examples:** @@ -29,7 +29,7 @@ number of decimal places that should be used. - 1 ether in wei, has **18** decimal places (i.e. 1 ether represents 10^^18^^ wei) - 1 bitcoin in Satoshi, has **8** decimal places (i.e. 1 bitcoin represents 10^^8^^ satoshi) -_heading: Named Units +_heading: Named Units @ There are also several common **Named Units**, in which case their name (as a string) may be used. @@ -46,9 +46,9 @@ _table: @STYLE | //ether// | 18 | -_subsection: Functions +_subsection: Functions @ -_heading: Formatting +_heading: Formatting @ _property: ethers.utils.commify(value) => string @ @SRC Returns a string with value grouped by 3 digits, separated by ``,``. diff --git a/docs.wrm/api/utils/encoding.wrm b/docs.wrm/api/utils/encoding.wrm index 3293adcb7..0b852eedf 100644 --- a/docs.wrm/api/utils/encoding.wrm +++ b/docs.wrm/api/utils/encoding.wrm @@ -28,7 +28,7 @@ structures of Arrays and data. _property: ethers.utils.RLP.encode(dataObject) => string<[[DataHexString]]> @ @SRC Encode a structured Data Object into its RLP-encoded representation. -Each Data component may be an valid [[BytesLike]]. +Each Data component may be a valid [[BytesLike]]. _property: ethers.utils.RLP.decode(aBytesLike) => [DataObject](rlp--dataobject) @ @SRC Decode an RLP-encoded //aBytesLike// into its structured Data Object. diff --git a/docs.wrm/api/utils/fixednumber.wrm b/docs.wrm/api/utils/fixednumber.wrm index fbd7f28ff..b922b7aef 100644 --- a/docs.wrm/api/utils/fixednumber.wrm +++ b/docs.wrm/api/utils/fixednumber.wrm @@ -81,7 +81,7 @@ _subsection: FixedFormat @ A **FixedFormat** is a simple object which represents a decimal (base-10) Fixed-Point data representation. Usually using this -class directly is uneccessary, as passing in a [[FixedFormat--strings]] +class directly is unnecessary, as passing in a [[FixedFormat--strings]] directly into the [[FixedNumber]] will automatically create this. _heading: Format Strings @ diff --git a/docs.wrm/api/utils/hashing.wrm b/docs.wrm/api/utils/hashing.wrm index 4dd1a644e..fd1663db2 100644 --- a/docs.wrm/api/utils/hashing.wrm +++ b/docs.wrm/api/utils/hashing.wrm @@ -1,6 +1,8 @@ _section: Hashing Algorithms @ -Explain what hash functions are? +There are many hashing algorithms used throughout the blockchain +space as well as some more complex usages which require utilities +to facilitate these common operations. _subsection: Cryptographic Hash Functions @ @@ -66,7 +68,7 @@ utils.keccak256("0x1234") utils.keccak256([ 0x12, 0x34 ]) //! -const bytes = utils.toUtf8Bytes("0x1234"); +const bytes = utils.toUtf8Bytes("0x1234") // bytes // @@ -119,8 +121,8 @@ Use the [SHA2-512](link-wiki-sha2) hash algorithm. _code: HMAC @lang -const key = "0x0102"; -const data = "0x1234"; +const key = "0x0102" +const data = "0x1234" utils.computeHmac("sha256", key, data) //! @@ -132,13 +134,39 @@ Computes the [[link-eip-191]] personal message digest of //message//. Personal m converted to UTF-8 bytes and prefixed with ``\\x19Ethereum Signed Message:`` and the length of //message//. -_property: ethers.utils.namehash(name) => string<[[DataHexString]]<32>> @ @SRC -Returns the [ENS Namehash](link-namehash) of //name//. - _code: Hashing Messages @lang -// @TODO: include examples of hashMessage; it can be complex. :) +// Hashing a string message +utils.hashMessage("Hello World") +//! +// Hashing binary data (also "Hello World", but as bytes) +utils.hashMessage( [ 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100 ]) +//! + +// NOTE: It is important to understand how strings and binary +// data is handled differently. A string is ALWAYS processed +// as the bytes of the string, so a hexstring MUST be +// converted to an ArrayLike object first. + +// Hashing a hex string is the same as hashing a STRING +// Note: this is the hash of the 4 characters [ '0', 'x', '4', '2' ] +utils.hashMessage("0x42") +//! + +// Hashing the binary data +// Note: this is the hash of the 1 byte [ 0x42 ] +utils.hashMessage([ 0x42 ]) +//! + +// Hashing the binary data +// Note: similarly, this is the hash of the 1 byte [ 0x42 ] +utils.hashMessage(utils.arrayify("0x42")) +//! + + +_property: ethers.utils.namehash(name) => string<[[DataHexString]]<32>> @ @SRC +Returns the [ENS Namehash](link-namehash) of //name//. _code: Namehash @lang @@ -154,6 +182,121 @@ utils.namehash("ricmoo.firefly.eth") utils.namehash("ricmoo.xyz") //! +_heading: Typed Data Encoder @ @SRC + +The **TypedDataEncoder** is used to compute the various encoded data required +for [[link-eip-712]] signed data. + +Signed data requires a domain, list of structures and their members and the data +itself. + +The **domain** is an object with values for any of the standard domain +properties. + +The **types** is an object with each property being the name of a structure, mapping +to an array of field descriptions. It should **not** include the ``EIP712Domain`` +property unless it is required as a child structure of another. + +_note: Experimental Feature (this exported class name will change) +This is still an experimental feature. If using it, please specify the **exact** +version of ethers you are using (e.g. spcify ``"5.0.18"``, **not** ``"^5.0.18"``) as +the exported class name will be renamed from ``_TypedDataEncoder`` to ``TypedDataEncoder`` once +it has been used in the field a bit. + +_property: ethers.utils._TypedDataEncoder.from(types) => [TypedDataEncoder] @ @SRC + +Creates a new **TypedDataEncoder** for //types//. This object is a fairly +low-level object that most developers should not require using instances +directly. + +Most developers will find the static class methods below the most useful. + +_property: TypedDataEncoder.encode(domain, types, values) => string @ @SRC + +Encodes the Returns the hashed [[link-eip-712]] domain. + +_property: TypedDataEncoder.getPayload(domain, types, value) => any @ @SRC + +Returns the standard payload used by various JSON-RPC ``eth_signTypedData*`` +calls. + +All domain values and entries in value are normalized and the types are +verified. + +_property: TypedDataEncoder.getPrimaryType(types) => string @ @SRC + +Constructs a directed acyclic graph of the types and returns the +root type, which can be used as the **primaryType** for [[link-eip-712]] +payloads. + +_property: TypedDataEncoder.hash(domain, types, values) => string<[[DataHexString]]<32>> @ @SRC + +Returns the computed [[link-eip-712]] hash. + +_property: TypedDataEncoder.hashDomain(domain) => string<[[DataHexString]]<32>> @ @SRC + +Returns the hashed [[link-eip-712]] domain. + +_property: TypedDataEncoder.resolveNames(domain, types, value, resolveName) => Promise @ @SRC + +Returns a copy of value, where any leaf value with a type of ``address`` will have +been recursively replacedwith the value of calling //resolveName// with that value. + +_code: Typed Data Example @lang + +// +TypedDataEncoder = ethers.utils._TypedDataEncoder +// + +const domain = { + name: 'Ether Mail', + version: '1', + chainId: 1, + verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC' +} + +// The named list of all type definitions +const types = { + Person: [ + { name: 'name', type: 'string' }, + { name: 'wallet', type: 'address' } + ], + Mail: [ + { name: 'from', type: 'Person' }, + { name: 'to', type: 'Person' }, + { name: 'contents', type: 'string' } + ] +} + +// The data to sign +const value = { + from: { + name: 'Cow', + wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826' + }, + to: { + name: 'Bob', + wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB' + }, + contents: 'Hello, Bob!' +} + + +TypedDataEncoder.encode(domain, types, value) +//! + +TypedDataEncoder.getPayload(domain, types, value) +//! + +TypedDataEncoder.getPrimaryType(types) +//! + +TypedDataEncoder.hash(domain, types, value) +//! + +TypedDataEncoder.hashDomain(domain) +//! + _subsection: Solidity Hashing Algorithms @ @@ -187,3 +330,20 @@ utils.solidityKeccak256([ "int16", "uint48" ], [ -1, 12 ]) utils.soliditySha256([ "int16", "uint48" ], [ -1, 12 ]) //! +// As a short example of the non-distinguished nature of +// Solidity tight-packing (which is why it is inappropriate +// for many things from a security point of view), consider +// the following examples are all equal, despite representing +// very different values and layouts. + +utils.solidityPack([ "string", "string" ], [ "hello", "world01" ]) +//! + +utils.solidityPack([ "string", "string" ], [ "helloworld", "01" ]) +//! + +utils.solidityPack([ "string", "string", "uint16" ], [ "hell", "oworld", 0x3031 ]) +//! + +utils.solidityPack([ "uint96" ], [ "32309054545061485574011236401" ]) +//! diff --git a/docs.wrm/api/utils/logger.wrm b/docs.wrm/api/utils/logger.wrm index b971ab344..e61274a1b 100644 --- a/docs.wrm/api/utils/logger.wrm +++ b/docs.wrm/api/utils/logger.wrm @@ -196,7 +196,7 @@ _property: Logger.levels.DEBUG Log all output, including debugging information. _property: Logger.levels.INFO -Only log output for infomational, warnings and errors. +Only log output for informational, warnings and errors. _property: Logger.levels.WARNING Only log output for warnings and errors. diff --git a/docs.wrm/api/utils/signing-key.wrm b/docs.wrm/api/utils/signing-key.wrm index a09609f3b..932c359bc 100644 --- a/docs.wrm/api/utils/signing-key.wrm +++ b/docs.wrm/api/utils/signing-key.wrm @@ -39,7 +39,13 @@ will then be used to compute the address; this allows systems which use the v to encode additional data (such as [EIP-155](link-eip-155)) to be used since the v parameter is still completely non-ambiguous. +_property: ethers.utils.verifyTypedData(domain, types, value, signature) => string<[[address]]> @ @SRC +Returns the address that signed the [[link-eip-712]] //value// for the //domain// +and //types// to produce the signature. + _property: ethers.utils.recoverPublicKey(digest, signature) => string<[[DataHexString]]<65>> @ +Returns the uncompressed public key (i.e. the first byte will be ``0x04``) +of the private key that was used to sign //digest// which gave the //signature//. _property: ethers.utils.computePublicKey(key [, compressed = false ]) => string<[[DataHexString]]> @ Computes the public key of //key//, optionally compressing it. The //key// diff --git a/docs.wrm/api/utils/transactions.wrm b/docs.wrm/api/utils/transactions.wrm index 0669e65b0..5aca013f3 100644 --- a/docs.wrm/api/utils/transactions.wrm +++ b/docs.wrm/api/utils/transactions.wrm @@ -7,7 +7,7 @@ An unsigned transaction represents a transaction that has not been signed and its values are flexible as long as they are not ambiguous. _property: unsignedTransaction.to => string<[Address](address)> -The addres this transaction is to. +The address this transaction is to. _property: unsignedTransaction.nonce => number The nonce of this transaction. @@ -98,7 +98,7 @@ used to encode the chain ID into the serialized transaction. _subsection: Functions @ _property: ethers.utils.parseTransaction(aBytesLike) => [[Transaction]] @ @SRC -Parses the transaction properties from a serialized transactions. +Parses the transaction properties from a serialized transaction. _property: ethers.utils.serializeTransaction(tx [ , signature ]) => string<[[DataHexString]]> @ @SRC Computes the serialized //transaction//, optionally serialized with diff --git a/docs.wrm/api/utils/web.wrm b/docs.wrm/api/utils/web.wrm index da66bbbf8..561201352 100644 --- a/docs.wrm/api/utils/web.wrm +++ b/docs.wrm/api/utils/web.wrm @@ -3,7 +3,7 @@ _section: Web Utilities @ _property: ethers.utils.fetchJson(urlOrConnectionInfo [, json [ , processFunc ] ]) => Promise @ Fetch and parse the JSON content from //urlOrConnectionInfo//, with the -optiona body //json// and optionally processing the result with //processFun// +optional body //json// and optionally processing the result with //processFun// before returning it. _property: ethers.utils.poll(pollFunc [, options ]) => Promise @ diff --git a/docs.wrm/api/utils/wordlists.wrm b/docs.wrm/api/utils/wordlists.wrm index eef1895de..dc67ef9d5 100644 --- a/docs.wrm/api/utils/wordlists.wrm +++ b/docs.wrm/api/utils/wordlists.wrm @@ -30,7 +30,7 @@ the registered //name//. _subsection: Languages @ -The [official wordlists](link-bip39-wordlists) available in at +The [official wordlists](link-bip39-wordlists) available at `ethers.wordlists`. In the browser, only the english language is available by default; to include the others (which increases the size of the library), see the dist files in the `ethers` package. diff --git a/docs.wrm/cli/asm.wrm b/docs.wrm/cli/asm.wrm index e249cd5b3..3eee1bd7b 100644 --- a/docs.wrm/cli/asm.wrm +++ b/docs.wrm/cli/asm.wrm @@ -104,8 +104,8 @@ bytecode by running multiple passes of an assemble stage, each pass more closely approximating the final result. This allows small portions of the bytecode to be massaged and tweaked -until the bytecode stablizes. This allows for more compact jump -destinations and for code to be include more advanced meta-programming +until the bytecode stabilizes. This allows for more compact jump +destinations and for code to include more advanced meta-programming techniques. _code: @lang diff --git a/docs.wrm/cli/plugin.wrm b/docs.wrm/cli/plugin.wrm index 09ed26371..f5f8c5b6d 100644 --- a/docs.wrm/cli/plugin.wrm +++ b/docs.wrm/cli/plugin.wrm @@ -47,8 +47,8 @@ for a given option is invalid or some combination of options and flags is not allowed. Once the prepareOptions is complete (the returned promise is resolved), the ``prepareArguments`` -is called. This should validate the number of arguments is expected and throw -and error if there are too many or too few arguments or if any arguments do not +is called. This should validate the number of arguments expected and throw +an error if there are too many or too few arguments or if any arguments do not make sense. Once the prepareArguments is complete (the returned promise is resolved), the ``run`` diff --git a/docs.wrm/concepts/index.wrm b/docs.wrm/concepts/index.wrm index 42486b594..8c88e35a4 100644 --- a/docs.wrm/concepts/index.wrm +++ b/docs.wrm/concepts/index.wrm @@ -11,3 +11,4 @@ _toc: events gas security + best-practices diff --git a/docs.wrm/config.js b/docs.wrm/config.js index d14b786af..09ea577fc 100644 --- a/docs.wrm/config.js +++ b/docs.wrm/config.js @@ -127,7 +127,7 @@ function codeContextify(context) { context.hexlify = ethers.utils.hexlify; context.hexValue = ethers.utils.hexValue; context.Wallet = ethers.Wallet; - context.provider = new ethers.providers.InfuraProvider(); + context.provider = new ethers.providers.InfuraProvider("mainnet", "49a0efa3aaee4fd99797bfa94d8ce2f1"); context.BigNumber.prototype[inspect.custom] = function(depth, options) { return `{ BigNumber: ${JSON.stringify(this.toString()) } }`; @@ -142,6 +142,7 @@ function codeContextify(context) { //return JSON.stringify(value); return inspect(value, { compact: false, + depth: null, breakLength: Infinity, sorted: true, }); @@ -185,6 +186,7 @@ module.exports = { "link-metamask": { name: "Metamask", url: "https:/\/metamask.io/" }, "link-otto": "https:/\/github.com/robertkrimen/otto", "link-parity": { name: "Parity", url: "https:/\/www.parity.io" }, + "link-pocket": { name: "Pocket Network", url: "https:/\/pokt.network" }, "link-react-native": { name: "React Native", url: "https:/\/reactnative.dev" }, "link-rtd": "https:/\/github.com/readthedocs/sphinx_rtd_theme", "link-semver": { name: "semver", url: "https:/\/semver.org" }, @@ -195,6 +197,7 @@ module.exports = { "link-etherscan-signup": "https:/\/etherscan.io/apis", "link-etherscan-ratelimit": "https:/\/info.etherscan.com/api-return-errors/", "link-infura-signup": "https:/\/infura.io/register", + "link-pocket-signup": "https:/\/pokt.network/pocket-gateway-ethereum-mainnet/", "link-json-rpc": "https:/\/github.com/ethereum/wiki/wiki/JSON-RPC", "link-web3-send": "https:/\/github.com/ethereum/web3.js/blob/1.x/packages/web3-providers-http/types/index.d.ts#L57", @@ -236,6 +239,7 @@ module.exports = { "link-eip-155": { name: "EIP-155", url: "https:/\/eips.ethereum.org/EIPS/eip-155" }, "link-eip-191": { name: "EIP-191", url: "https:/\/eips.ethereum.org/EIPS/eip-191" }, "link-eip-609": { name: "EIP-609", url: "https:/\/eips.ethereum.org/EIPS/eip-609" }, + "link-eip-712": { name: "EIP-712", url: "https:/\/eips.ethereum.org/EIPS/eip-712" }, "link-eip-1014": { name: "EIP-1014", url: "https:/\/eips.ethereum.org/EIPS/eip-1014" }, "link-eip-1193": { name: "EIP-1193", url: "https:/\/eips.ethereum.org/EIPS/eip-1193" }, "link-eip-2098": { name: "EIP-2098", url: "https:/\/eips.ethereum.org/EIPS/eip-2098" }, @@ -247,7 +251,7 @@ module.exports = { "link-npm-events": { name: "EventEmitter", url: "https:/\/nodejs.org/dist/latest-v13.x/docs/api/events.html#events_class_eventemitter" }, "link-npm-bnjs": { name: "BN.js", url: "https:/\/www.npmjs.com/package/bn.js" }, "link-npm-query-bignumber": "https:/\/www.npmjs.com/search?q=bignumber", - "link-npm-react-native-crypto": { name: "React Native Crypto", url: "https:/\/www.npmjs.com/package/react-native-crypto" }, + "link-npm-react-native-get-random-values": { name: "React Native get-random-values", url: "https:/\/www.npmjs.com/package/react-native-get-random-values" }, "link-js-array": "https:/\/developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array", "link-js-bigint": "https:/\/developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt", diff --git a/docs.wrm/contributing.wrm b/docs.wrm/contributing.wrm index 7d52f0b89..db2783082 100644 --- a/docs.wrm/contributing.wrm +++ b/docs.wrm/contributing.wrm @@ -21,7 +21,7 @@ So, pull requests are always welcome, but please keep a few points in mind: may not be accepted In general, **please start an issue //before// beginning a pull request**, so we can -have a public discussion and figure out the best way to address to problem/feature. +have a public discussion and figure out the best way to address the problem/feature. **:)** diff --git a/docs.wrm/cookbook/react-native.wrm b/docs.wrm/cookbook/react-native.wrm index 5b216dbff..cc7a11192 100644 --- a/docs.wrm/cookbook/react-native.wrm +++ b/docs.wrm/cookbook/react-native.wrm @@ -40,8 +40,21 @@ _subsection: Security @ The React Native environment does not contain a secure random source, which is used when computing random private keys. This could result in private -keys that others could guess, allowing the funds to be stolen. +keys that others could possibly guess, allowing funds to be stolen and assets +manipulated. -For this reason, it is **HIGHLY RECOMMENDED** to get either the -[[link-npm-react-native-crypto]] module working or some equivalent. +For this reason, it is **HIGHLY RECOMMENDED** to also install the +[[link-npm-react-native-get-random-values]], which **must** be included +before the shims. If it worked correctly you should not receive any +warning in the console regarding missing secure random sources. +_code: Importing with Secure Random Sources @lang