Global

Methods

isERC55(Address)

Checks an Ethereum address for ERC-55: Mixed-case checksum address encoding.

Parameters:
Name Type Description
Address string

40-byte hex string beginning with '0x'. e.g.
'0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'

Source:
Returns:

true if address is in correct ERC-55 encoding, false otherwise

isUri(URI)

Parses a Uniform Resource Identifier (URI) defined in RFC 3986.

Parameters:
Name Type Description
URI string

the URI to parse

Source:
Returns:

false if the URI is invalid, otherwise a URI object. e.g.

const obj = isUri('uri://user:pass@example.com:123/one/two.three?q1=a1&q2=a2#body');

returns:

obj.scheme = 'uri'
obj.userinfo = 'user:pass'
obj.host = 'example.com',
obj.port = 123,
obj.path = '/one/two.three',
obj.query = 'q1=a1&q2=a2',
obj.fragment = 'body'

keccak256(msg)

A keccak-256 hash function specialized for ASCII-only string input (character codes 0 - 127). It is a modification of the general work https://github.com/cryptocoinjs/keccak.

CAVEAT: This function should never be used for secure cryptography purposes. It is used here merely as a means of getting the correct hash for the ERC-55 Ethereum address checksum. It is assumed that security is not an issue for this use.

The license for the original work is reproduced here.

 The MIT License (MIT)

Copyright (c) 2016-2019 https://github.com/cryptocoinjs/keccak contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Parameters:
Name Type Description
msg string

must be a string of ASCII-only characters (character codes 0 - 127). Will throw exception with any other type of input.

Source:
Returns:

The keccak-256 hash or digest of the input string. e.g.

keccak256('')             => 'c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'
keccak256('Hello world!') => 'ecd0e108a98e192af1d2c25055f4e3bed784b5c877204e73219a5203251feaab'

parseSiweMessage(msg, erc55)

Parses an ERC-4361: Sign-In with Ethereum message to an object with the message components.

Parameters:
Name Type Default Description
msg string

the ERC-4361 message

erc55 string validate

controls ERC-55 processing of the message address

  • 'validate' - (default) parser fails if address is not in ERC-55 encoding
  • 'convert' - parser will convert the address to ERC-55 encoding
  • 'other' - (actually, any value other than 'validate', 'convert' or undefined) parser ignores ERC-55 encoding
Source:
Returns:

An siwe message object or throws exception with instructive message on format error.
e.g. message

example.com:80 wants you to sign in with your Ethereum account:
0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2

Valid statement

URI: https://example.com/login
Version: 1
Chain ID: 123456789
Nonce: 32891756
Issued At: 2021-09-30T16:25:24Z
Request ID: someRequestId
Resources:
- ftp://myftpsite.com/
- https://example.com/my-web2-claim.json

returns object, obj:

  obj.scheme = undefined
  obj.domain = 'example.com:80'
  obj.address = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'
  obj.statement = 'Valid statement'
  obj.uri = 'https://example.com/login'
  obj.version = 1
  obj.chainId = 123456789
  obj.nonce = '32891756'
  obj.issuedAt = '2021-09-30T16:25:24Z'
  obj.expirationTime = undefined
  obj.notBefore = undefined
  obj.requestId = 'someRequestId'
  obj.resources = [ 'ftp://myftpsite.com/', 'https://example.com/my-web2-claim.json' ]

siweObjectToString(o)

Stringify an ERC-4361: Sign-In with Ethereum (siwe) object. Note that this function does no validation of the input object. It simply returns a string that includes the valid parts of the object, if any. For validation, use parseSiweMessage.

Parameters:
Name Type Description
o object

an siwe message object (see parseSiweMessage )

Source:
Returns:

A stringified version of the object suitable as input to parseSiweMessage.

For example, to validate an siwe object
(ignore backslash, JSDoc can't handle closed bracket character without it):

try{
 parseSiweMessage(siweObjectToString(siweObject));
 console.log('siweObject is valid');
\}catch(e){
 console.log('siweObject is not valid: ' + e.message);
\}

toERC55(address)

Converts an Ethereum address to ERC-55: Mixed-case checksum address encoding.

Parameters:
Name Type Description
address string

40-byte hex string beginning with '0x'

Source:
Returns:

address in correct ERC-55 encoding

For example:

'0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed' = toERC55('0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed');