keccak256("0x") // '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470' keccak256("0x1337") // '0x2636a8beb2c41b8ccafa9a55a5a5e333892a83b491df3a67d2768946a9f9c6dc' keccak256(new Uint8Array([ 0x13, 0x37 ])) // '0x2636a8beb2c41b8ccafa9a55a5a5e333892a83b491df3a67d2768946a9f9c6dc' // Strings are assumed to be DataHexString, otherwise it will // throw. To hash UTF-8 data, see the note above. keccak256("Hello World") // Error("invalid BytesLike value", { // code: "INVALID_ARGUMENT" // argument: "data" // value: "Hello World" // })
ripemd160("0x") // '0x9c1185a5c5e9fc54612808977ee8f548b2258d31' ripemd160("0x1337") // '0x224d2bd5251d8f9faa114eb0826e371d1236fda1' ripemd160(new Uint8Array([ 0x13, 0x37 ])) // '0x224d2bd5251d8f9faa114eb0826e371d1236fda1'
sha256("0x") // '0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' sha256("0x1337") // '0x158760c856e5ea1ba97e2e2a456736c4bf30d964559afa6d748cf05694a636ff' sha256(new Uint8Array([ 0x13, 0x37 ])) // '0x158760c856e5ea1ba97e2e2a456736c4bf30d964559afa6d748cf05694a636ff'
sha512("0x") // '0xcf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e' sha512("0x1337") // '0x55ccb35e52b39adac42b68304bf33ff7ecb854f09b2e761e234061482e98e45b4e68de2756bcc7b7099d7dd178f04dafa229d403b90bf8884eedea3806d4642b' sha512(new Uint8Array([ 0x13, 0x37 ])) // '0x55ccb35e52b39adac42b68304bf33ff7ecb854f09b2e761e234061482e98e45b4e68de2756bcc7b7099d7dd178f04dafa229d403b90bf8884eedea3806d4642b'
key = id("some-secret") // Compute the HMAC computeHmac("sha256", key, "0x1337") // '0xbc985612171f71b89c7561c593f2cea20038d3f38f710b2516e405085d7c0c79' // To compute the HMAC of UTF-8 data, the data must be // converted to UTF-8 bytes computeHmac("sha256", key, toUtf8Bytes("Hello World")) // '0xd0404ef8fae0d7f18a54a0ddfad8b81afa9e4cdab872a1dc36628c4397fd8201'
// The password must be converted to bytes, and it is generally // best practices to ensure the string has been normalized. Many // formats explicitly indicate the normalization form to use. password = "hello" passwordBytes = toUtf8Bytes(password, "NFKC") salt = id("some-salt") // Compute the PBKDF2 pbkdf2(passwordBytes, salt, 1024, 16, "sha256") // '0x226addf5b6d87544337e9733b99ceb9d'
// The password must be converted to bytes, and it is generally // best practices to ensure the string has been normalized. Many // formats explicitly indicate the normalization form to use. password = "hello" passwordBytes = toUtf8Bytes(password, "NFKC") salt = id("some-salt") // Compute the scrypt scrypt(passwordBytes, salt, 1024, 8, 1, 16) // Promise<'0x3982633256a26ab2e62efa0621d1a5c0'>
// The password must be converted to bytes, and it is generally // best practices to ensure the string has been normalized. Many // formats explicitly indicate the normalization form to use. password = "hello" passwordBytes = toUtf8Bytes(password, "NFKC") salt = id("some-salt") // Compute the scrypt scryptSync(passwordBytes, salt, 1024, 8, 1, 16) // '0x3982633256a26ab2e62efa0621d1a5c0'
randomBytes(8) // Uint8Array(8) [ // 122, 197, 123, // 228, 254, 209, // 45, 213 // ]
PROPERTIES
CREATING INSTANCES
METHODS
STATIC METHODS
Signature.getChainId(45) // 5n Signature.getChainId(46) // 5n
Signature.getChainIdV(5, 27) // 45n Signature.getChainIdV(5, 28) // 46n
// The values 0 and 1 imply v is actually yParity Signature.getNormalizedV(0) // 27 // Legacy non-EIP-1559 transaction (i.e. 27 or 28) Signature.getNormalizedV(27) // 27 // Legacy EIP-155 transaction (i.e. >= 35) Signature.getNormalizedV(46) // 28 // Invalid values throw Signature.getNormalizedV(5) // Error("invalid v", { // code: "INVALID_ARGUMENT" // argument: "v" // value: 5 // })
PROPERTIES
CREATING INSTANCES
METHODS
sign1 = new SigningKey(id("some-secret-1")) sign2 = new SigningKey(id("some-secret-2")) // Notice that privA.computeSharedSecret(pubB)... sign1.computeSharedSecret(sign2.publicKey) // '0x04b5bc2a5428042331a4c70da8f090d5552bdb35bc08a00ea8ed0a9b6d8737b8b7ea016b268d7cb9f02e11736b82b129ea3f37a8fdc6a7b0e9f5cdde4105ceb0de' // ...is equal to privB.computeSharedSecret(pubA). sign2.computeSharedSecret(sign1.publicKey) // '0x04b5bc2a5428042331a4c70da8f090d5552bdb35bc08a00ea8ed0a9b6d8737b8b7ea016b268d7cb9f02e11736b82b129ea3f37a8fdc6a7b0e9f5cdde4105ceb0de'
STATIC METHODS
sign = new SigningKey(id("some-secret")); // Compute the uncompressed public key for a private key SigningKey.computePublicKey(sign.privateKey) // '0x04925bec9818e11ac806bf8b142a7965ac9231aaa9d23f256795d63b1d8d7f203f7481609b6a6964a0f5b459585e9d18a9ec9070d0baf24689138868811c974c96' // Compute the compressed public key for a private key SigningKey.computePublicKey(sign.privateKey, true) // '0x02925bec9818e11ac806bf8b142a7965ac9231aaa9d23f256795d63b1d8d7f203f' // Compute the uncompressed public key SigningKey.computePublicKey(sign.publicKey, false); // '0x04925bec9818e11ac806bf8b142a7965ac9231aaa9d23f256795d63b1d8d7f203f7481609b6a6964a0f5b459585e9d18a9ec9070d0baf24689138868811c974c96' // Compute the Compressed a public key SigningKey.computePublicKey(sign.publicKey, true); // '0x02925bec9818e11ac806bf8b142a7965ac9231aaa9d23f256795d63b1d8d7f203f'
key = new SigningKey(id("some-secret")) digest = id("hello world") sig = key.sign(digest) // Notice the signer public key... key.publicKey // '0x04925bec9818e11ac806bf8b142a7965ac9231aaa9d23f256795d63b1d8d7f203f7481609b6a6964a0f5b459585e9d18a9ec9070d0baf24689138868811c974c96' // ...is equal to the recovered public key SigningKey.recoverPublicKey(digest, sig) // '0x04925bec9818e11ac806bf8b142a7965ac9231aaa9d23f256795d63b1d8d7f203f7481609b6a6964a0f5b459585e9d18a9ec9070d0baf24689138868811c974c96'