quantumcoin 6.14.2 → 6.14.5
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 +442 -442
- package/FUNDING.json +10 -10
- package/LICENSE.md +21 -21
- package/README.md +132 -142
- package/SECURITY.md +34 -34
- package/dist/README.md +22 -22
- package/dist/quantumcoin.js +1127 -1324
- package/dist/quantumcoin.js.map +1 -1
- package/dist/quantumcoin.min.js +1 -1
- package/dist/quantumcoin.umd.js +1128 -1327
- package/dist/quantumcoin.umd.js.map +1 -1
- package/dist/quantumcoin.umd.min.js +1 -1
- package/dist/wordlists-extra.js +1 -1
- package/dist/wordlists-extra.js.map +1 -1
- package/dist/wordlists-extra.min.js +1 -1
- package/lib.commonjs/README.md +16 -16
- package/lib.commonjs/_version.js +1 -1
- package/lib.commonjs/crypto/signature.d.ts +3 -76
- package/lib.commonjs/crypto/signature.d.ts.map +1 -1
- package/lib.commonjs/crypto/signature.js +15 -199
- package/lib.commonjs/crypto/signature.js.map +1 -1
- package/lib.commonjs/crypto/signing-key.d.ts +1 -1
- package/lib.commonjs/crypto/signing-key.d.ts.map +1 -1
- package/lib.commonjs/crypto/signing-key.js +19 -10
- package/lib.commonjs/crypto/signing-key.js.map +1 -1
- package/lib.commonjs/package.json +12 -12
- package/lib.commonjs/providers/provider-jsonrpc.d.ts +0 -1
- package/lib.commonjs/providers/provider-jsonrpc.d.ts.map +1 -1
- package/lib.commonjs/providers/provider-jsonrpc.js +0 -1
- package/lib.commonjs/providers/provider-jsonrpc.js.map +1 -1
- package/lib.commonjs/quantumcoin.d.ts +2 -0
- package/lib.commonjs/quantumcoin.d.ts.map +1 -1
- package/lib.commonjs/quantumcoin.js +11 -5
- package/lib.commonjs/quantumcoin.js.map +1 -1
- package/lib.commonjs/transaction/address.d.ts.map +1 -1
- package/lib.commonjs/transaction/address.js +8 -3
- package/lib.commonjs/transaction/address.js.map +1 -1
- package/lib.commonjs/transaction/transaction.d.ts.map +1 -1
- package/lib.commonjs/transaction/transaction.js +7 -40
- package/lib.commonjs/transaction/transaction.js.map +1 -1
- package/lib.commonjs/wallet/json-keystore.d.ts.map +1 -1
- package/lib.commonjs/wallet/json-keystore.js +7 -7
- package/lib.commonjs/wallet/json-keystore.js.map +1 -1
- package/lib.commonjs/wallet/wallet.d.ts.map +1 -1
- package/lib.commonjs/wallet/wallet.js +2 -2
- package/lib.commonjs/wallet/wallet.js.map +1 -1
- package/lib.esm/README.md +16 -16
- package/lib.esm/_version.js +1 -1
- package/lib.esm/crypto/signature.d.ts +3 -76
- package/lib.esm/crypto/signature.d.ts.map +1 -1
- package/lib.esm/crypto/signature.js +16 -202
- package/lib.esm/crypto/signature.js.map +1 -1
- package/lib.esm/crypto/signing-key.d.ts +1 -1
- package/lib.esm/crypto/signing-key.d.ts.map +1 -1
- package/lib.esm/crypto/signing-key.js +20 -9
- package/lib.esm/crypto/signing-key.js.map +1 -1
- package/lib.esm/package.json +12 -12
- package/lib.esm/providers/provider-jsonrpc.d.ts +0 -1
- package/lib.esm/providers/provider-jsonrpc.d.ts.map +1 -1
- package/lib.esm/providers/provider-jsonrpc.js +0 -1
- package/lib.esm/providers/provider-jsonrpc.js.map +1 -1
- package/lib.esm/quantumcoin.d.ts +2 -0
- package/lib.esm/quantumcoin.d.ts.map +1 -1
- package/lib.esm/quantumcoin.js +6 -0
- package/lib.esm/quantumcoin.js.map +1 -1
- package/lib.esm/transaction/address.d.ts.map +1 -1
- package/lib.esm/transaction/address.js +8 -2
- package/lib.esm/transaction/address.js.map +1 -1
- package/lib.esm/transaction/transaction.d.ts.map +1 -1
- package/lib.esm/transaction/transaction.js +7 -40
- package/lib.esm/transaction/transaction.js.map +1 -1
- package/lib.esm/wallet/json-keystore.d.ts.map +1 -1
- package/lib.esm/wallet/json-keystore.js +11 -5
- package/lib.esm/wallet/json-keystore.js.map +1 -1
- package/lib.esm/wallet/wallet.d.ts.map +1 -1
- package/lib.esm/wallet/wallet.js +3 -1
- package/lib.esm/wallet/wallet.js.map +1 -1
- package/package.json +6 -5
- package/rollup.config.mjs +50 -50
- package/src.ts/_version.ts +1 -1
- package/src.ts/abi/abi-coder.ts +237 -237
- package/src.ts/abi/bytes32.ts +45 -45
- package/src.ts/abi/coders/abstract-coder.ts +541 -541
- package/src.ts/abi/coders/address.ts +36 -36
- package/src.ts/abi/coders/anonymous.ts +29 -29
- package/src.ts/abi/coders/array.ts +199 -199
- package/src.ts/abi/coders/boolean.ts +27 -27
- package/src.ts/abi/coders/bytes.ts +43 -43
- package/src.ts/abi/coders/fixed-bytes.ts +37 -37
- package/src.ts/abi/coders/null.ts +28 -28
- package/src.ts/abi/coders/number.ts +63 -63
- package/src.ts/abi/coders/string.ts +29 -29
- package/src.ts/abi/coders/tuple.ts +69 -69
- package/src.ts/abi/fragments.ts +1617 -1617
- package/src.ts/abi/index.ts +41 -41
- package/src.ts/abi/interface.ts +1271 -1271
- package/src.ts/abi/typed.ts +796 -796
- package/src.ts/address/address.ts +148 -148
- package/src.ts/address/checks.ts +123 -123
- package/src.ts/address/contract-address.ts +80 -80
- package/src.ts/address/index.ts +57 -57
- package/src.ts/constants/addresses.ts +8 -8
- package/src.ts/constants/hashes.ts +7 -7
- package/src.ts/constants/index.ts +16 -16
- package/src.ts/constants/numbers.ts +35 -35
- package/src.ts/constants/strings.ts +16 -16
- package/src.ts/contract/contract.ts +1120 -1120
- package/src.ts/contract/factory.ts +143 -143
- package/src.ts/contract/index.ts +31 -31
- package/src.ts/contract/types.ts +236 -236
- package/src.ts/contract/wrappers.ts +225 -225
- package/src.ts/crypto/crypto-browser.ts +64 -64
- package/src.ts/crypto/crypto.ts +4 -4
- package/src.ts/crypto/hmac.ts +51 -51
- package/src.ts/crypto/index.ts +59 -59
- package/src.ts/crypto/keccak.ts +54 -54
- package/src.ts/crypto/pbkdf2.ts +55 -55
- package/src.ts/crypto/random.ts +36 -36
- package/src.ts/crypto/ripemd160.ts +43 -43
- package/src.ts/crypto/scrypt.ts +114 -114
- package/src.ts/crypto/sha2.ts +78 -78
- package/src.ts/crypto/signature.ts +145 -349
- package/src.ts/crypto/signing-key.ts +126 -118
- package/src.ts/hash/authorization.ts +38 -38
- package/src.ts/hash/id.ts +17 -17
- package/src.ts/hash/index.ts +18 -18
- package/src.ts/hash/message.ts +51 -51
- package/src.ts/hash/namehash.ts +101 -101
- package/src.ts/hash/solidity.ts +117 -117
- package/src.ts/hash/typed-data.ts +658 -658
- package/src.ts/index.ts +12 -12
- package/src.ts/providers/abstract-provider.ts +1761 -1761
- package/src.ts/providers/abstract-signer.ts +314 -314
- package/src.ts/providers/community.ts +49 -49
- package/src.ts/providers/contracts.ts +42 -42
- package/src.ts/providers/default-provider.ts +96 -96
- package/src.ts/providers/ens-resolver.ts +606 -606
- package/src.ts/providers/format.ts +320 -320
- package/src.ts/providers/formatting.ts +418 -418
- package/src.ts/providers/index.ts +125 -125
- package/src.ts/providers/network.ts +327 -327
- package/src.ts/providers/pagination.ts +8 -8
- package/src.ts/providers/plugin-fallback.ts +35 -35
- package/src.ts/providers/plugins-network.ts +281 -281
- package/src.ts/providers/provider-browser.ts +334 -334
- package/src.ts/providers/provider-fallback.ts +801 -801
- package/src.ts/providers/provider-ipcsocket-browser.ts +3 -3
- package/src.ts/providers/provider-ipcsocket.ts +81 -81
- package/src.ts/providers/provider-jsonrpc.ts +1334 -1335
- package/src.ts/providers/provider-socket.ts +352 -352
- package/src.ts/providers/provider-websocket.ts +103 -103
- package/src.ts/providers/provider.ts +2136 -2136
- package/src.ts/providers/signer-noncemanager.ts +98 -98
- package/src.ts/providers/signer.ts +166 -166
- package/src.ts/providers/subscriber-connection.ts +74 -74
- package/src.ts/providers/subscriber-filterid.ts +199 -199
- package/src.ts/providers/subscriber-polling.ts +321 -321
- package/src.ts/providers/ws-browser.ts +11 -11
- package/src.ts/providers/ws.ts +3 -3
- package/src.ts/quantumcoin.ts +219 -211
- package/src.ts/thirdparty.d.ts +16 -16
- package/src.ts/transaction/accesslist.ts +43 -43
- package/src.ts/transaction/address.ts +35 -31
- package/src.ts/transaction/authorization.ts +14 -14
- package/src.ts/transaction/index.ts +51 -51
- package/src.ts/transaction/transaction.ts +1349 -1379
- package/src.ts/utils/base58.ts +73 -73
- package/src.ts/utils/base64-browser.ts +25 -25
- package/src.ts/utils/base64.ts +56 -56
- package/src.ts/utils/data.ts +199 -199
- package/src.ts/utils/errors.ts +793 -793
- package/src.ts/utils/events.ts +105 -105
- package/src.ts/utils/fetch.ts +970 -970
- package/src.ts/utils/fixednumber.ts +643 -643
- package/src.ts/utils/geturl-browser.ts +81 -81
- package/src.ts/utils/geturl.ts +134 -134
- package/src.ts/utils/index.ts +95 -95
- package/src.ts/utils/maths.ts +240 -240
- package/src.ts/utils/properties.ts +60 -60
- package/src.ts/utils/rlp-decode.ts +104 -104
- package/src.ts/utils/rlp-encode.ts +64 -64
- package/src.ts/utils/rlp.ts +20 -20
- package/src.ts/utils/units.ts +91 -91
- package/src.ts/utils/utf8.ts +325 -325
- package/src.ts/utils/uuid.ts +36 -36
- package/src.ts/wallet/base-wallet.ts +160 -160
- package/src.ts/wallet/index.ts +32 -32
- package/src.ts/wallet/json-keystore.ts +108 -106
- package/src.ts/wallet/utils.ts +147 -147
- package/src.ts/wallet/wallet.ts +138 -139
- package/src.ts/wordlists/bit-reader.ts +35 -35
- package/src.ts/wordlists/decode-owl.ts +58 -58
- package/src.ts/wordlists/decode-owla.ts +33 -33
- package/src.ts/wordlists/generation/encode-latin.ts +370 -370
- package/src.ts/wordlists/index.ts +26 -26
- package/src.ts/wordlists/lang-cz.ts +33 -33
- package/src.ts/wordlists/lang-en.ts +33 -33
- package/src.ts/wordlists/lang-es.ts +35 -35
- package/src.ts/wordlists/lang-fr.ts +34 -34
- package/src.ts/wordlists/lang-it.ts +33 -33
- package/src.ts/wordlists/lang-ja.ts +181 -181
- package/src.ts/wordlists/lang-ko.ts +104 -104
- package/src.ts/wordlists/lang-pt.ts +34 -34
- package/src.ts/wordlists/lang-zh.ts +112 -112
- package/src.ts/wordlists/wordlist-owl.ts +77 -77
- package/src.ts/wordlists/wordlist-owla.ts +41 -41
- package/src.ts/wordlists/wordlist.ts +59 -59
- package/src.ts/wordlists/wordlists-browser.ts +8 -8
- package/src.ts/wordlists/wordlists-extra.ts +9 -9
- package/src.ts/wordlists/wordlists.ts +38 -38
- package/dist/quantumcoin.min.js'.gz' +0 -0
- package/dist/quantumcoin.umd.min.js'.gz' +0 -0
- package/dist/wordlists-extra.min.js'.gz' +0 -0
- package/lib.commonjs/providers/provider-alchemy.d.ts +0 -50
- package/lib.commonjs/providers/provider-alchemy.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-alchemy.js +0 -151
- package/lib.commonjs/providers/provider-alchemy.js.map +0 -1
- package/lib.commonjs/providers/provider-ankr.d.ts +0 -61
- package/lib.commonjs/providers/provider-ankr.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-ankr.js +0 -137
- package/lib.commonjs/providers/provider-ankr.js.map +0 -1
- package/lib.commonjs/providers/provider-blockscout.d.ts +0 -59
- package/lib.commonjs/providers/provider-blockscout.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-blockscout.js +0 -145
- package/lib.commonjs/providers/provider-blockscout.js.map +0 -1
- package/lib.commonjs/providers/provider-chainstack.d.ts +0 -46
- package/lib.commonjs/providers/provider-chainstack.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-chainstack.js +0 -102
- package/lib.commonjs/providers/provider-chainstack.js.map +0 -1
- package/lib.commonjs/providers/provider-cloudflare.d.ts +0 -14
- package/lib.commonjs/providers/provider-cloudflare.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-cloudflare.js +0 -26
- package/lib.commonjs/providers/provider-cloudflare.js.map +0 -1
- package/lib.commonjs/providers/provider-etherscan.d.ts +0 -147
- package/lib.commonjs/providers/provider-etherscan.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-etherscan.js +0 -587
- package/lib.commonjs/providers/provider-etherscan.js.map +0 -1
- package/lib.commonjs/providers/provider-infura.d.ts +0 -101
- package/lib.commonjs/providers/provider-infura.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-infura.js +0 -206
- package/lib.commonjs/providers/provider-infura.js.map +0 -1
- package/lib.commonjs/providers/provider-pocket.d.ts +0 -54
- package/lib.commonjs/providers/provider-pocket.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-pocket.js +0 -109
- package/lib.commonjs/providers/provider-pocket.js.map +0 -1
- package/lib.commonjs/providers/provider-quicknode.d.ts +0 -59
- package/lib.commonjs/providers/provider-quicknode.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-quicknode.js +0 -163
- package/lib.commonjs/providers/provider-quicknode.js.map +0 -1
- package/lib.commonjs/wallet/hdwallet.d.ts +0 -248
- package/lib.commonjs/wallet/hdwallet.d.ts.map +0 -1
- package/lib.commonjs/wallet/hdwallet.js +0 -505
- package/lib.commonjs/wallet/hdwallet.js.map +0 -1
- package/lib.commonjs/wallet/json-crowdsale.d.ts +0 -27
- package/lib.commonjs/wallet/json-crowdsale.d.ts.map +0 -1
- package/lib.commonjs/wallet/json-crowdsale.js +0 -60
- package/lib.commonjs/wallet/json-crowdsale.js.map +0 -1
- package/lib.commonjs/wallet/mnemonic.d.ts +0 -65
- package/lib.commonjs/wallet/mnemonic.d.ts.map +0 -1
- package/lib.commonjs/wallet/mnemonic.js +0 -169
- package/lib.commonjs/wallet/mnemonic.js.map +0 -1
- package/lib.commonjs/wallet/seedwallet.d.ts +0 -4
- package/lib.commonjs/wallet/seedwallet.d.ts.map +0 -1
- package/lib.commonjs/wallet/seedwallet.js +0 -8
- package/lib.commonjs/wallet/seedwallet.js.map +0 -1
- package/lib.esm/providers/provider-alchemy.d.ts +0 -50
- package/lib.esm/providers/provider-alchemy.d.ts.map +0 -1
- package/lib.esm/providers/provider-alchemy.js +0 -147
- package/lib.esm/providers/provider-alchemy.js.map +0 -1
- package/lib.esm/providers/provider-ankr.d.ts +0 -61
- package/lib.esm/providers/provider-ankr.d.ts.map +0 -1
- package/lib.esm/providers/provider-ankr.js +0 -133
- package/lib.esm/providers/provider-ankr.js.map +0 -1
- package/lib.esm/providers/provider-blockscout.d.ts +0 -59
- package/lib.esm/providers/provider-blockscout.d.ts.map +0 -1
- package/lib.esm/providers/provider-blockscout.js +0 -141
- package/lib.esm/providers/provider-blockscout.js.map +0 -1
- package/lib.esm/providers/provider-chainstack.d.ts +0 -46
- package/lib.esm/providers/provider-chainstack.d.ts.map +0 -1
- package/lib.esm/providers/provider-chainstack.js +0 -98
- package/lib.esm/providers/provider-chainstack.js.map +0 -1
- package/lib.esm/providers/provider-cloudflare.d.ts +0 -14
- package/lib.esm/providers/provider-cloudflare.d.ts.map +0 -1
- package/lib.esm/providers/provider-cloudflare.js +0 -22
- package/lib.esm/providers/provider-cloudflare.js.map +0 -1
- package/lib.esm/providers/provider-etherscan.d.ts +0 -147
- package/lib.esm/providers/provider-etherscan.d.ts.map +0 -1
- package/lib.esm/providers/provider-etherscan.js +0 -584
- package/lib.esm/providers/provider-etherscan.js.map +0 -1
- package/lib.esm/providers/provider-infura.d.ts +0 -101
- package/lib.esm/providers/provider-infura.d.ts.map +0 -1
- package/lib.esm/providers/provider-infura.js +0 -201
- package/lib.esm/providers/provider-infura.js.map +0 -1
- package/lib.esm/providers/provider-pocket.d.ts +0 -54
- package/lib.esm/providers/provider-pocket.d.ts.map +0 -1
- package/lib.esm/providers/provider-pocket.js +0 -105
- package/lib.esm/providers/provider-pocket.js.map +0 -1
- package/lib.esm/providers/provider-quicknode.d.ts +0 -59
- package/lib.esm/providers/provider-quicknode.d.ts.map +0 -1
- package/lib.esm/providers/provider-quicknode.js +0 -159
- package/lib.esm/providers/provider-quicknode.js.map +0 -1
- package/lib.esm/wallet/hdwallet.d.ts +0 -248
- package/lib.esm/wallet/hdwallet.d.ts.map +0 -1
- package/lib.esm/wallet/hdwallet.js +0 -498
- package/lib.esm/wallet/hdwallet.js.map +0 -1
- package/lib.esm/wallet/json-crowdsale.d.ts +0 -27
- package/lib.esm/wallet/json-crowdsale.d.ts.map +0 -1
- package/lib.esm/wallet/json-crowdsale.js +0 -55
- package/lib.esm/wallet/json-crowdsale.js.map +0 -1
- package/lib.esm/wallet/mnemonic.d.ts +0 -65
- package/lib.esm/wallet/mnemonic.d.ts.map +0 -1
- package/lib.esm/wallet/mnemonic.js +0 -165
- package/lib.esm/wallet/mnemonic.js.map +0 -1
- package/lib.esm/wallet/seedwallet.d.ts +0 -4
- package/lib.esm/wallet/seedwallet.d.ts.map +0 -1
- package/lib.esm/wallet/seedwallet.js +0 -4
- package/lib.esm/wallet/seedwallet.js.map +0 -1
package/src.ts/crypto/hmac.ts
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* An **HMAC** enables verification that a given key was used
|
|
3
|
-
* to authenticate a payload.
|
|
4
|
-
*
|
|
5
|
-
* See: [[link-wiki-hmac]]
|
|
6
|
-
*
|
|
7
|
-
* @_subsection: api/crypto:HMAC [about-hmac]
|
|
8
|
-
*/
|
|
9
|
-
import { createHmac } from "./crypto.js";
|
|
10
|
-
import { getBytes, hexlify } from "../utils/index.js";
|
|
11
|
-
|
|
12
|
-
import type { BytesLike } from "../utils/index.js";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
let locked = false;
|
|
16
|
-
|
|
17
|
-
const _computeHmac = function(algorithm: "sha256" | "sha512", key: Uint8Array, data: Uint8Array): BytesLike {
|
|
18
|
-
return createHmac(algorithm, key).update(data).digest();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
let __computeHmac = _computeHmac;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Return the HMAC for %%data%% using the %%key%% key with the underlying
|
|
25
|
-
* %%algo%% used for compression.
|
|
26
|
-
*
|
|
27
|
-
* @example:
|
|
28
|
-
* key = id("some-secret")
|
|
29
|
-
*
|
|
30
|
-
* // Compute the HMAC
|
|
31
|
-
* computeHmac("sha256", key, "0x1337")
|
|
32
|
-
* //_result:
|
|
33
|
-
*
|
|
34
|
-
* // To compute the HMAC of UTF-8 data, the data must be
|
|
35
|
-
* // converted to UTF-8 bytes
|
|
36
|
-
* computeHmac("sha256", key, toUtf8Bytes("Hello World"))
|
|
37
|
-
* //_result:
|
|
38
|
-
*
|
|
39
|
-
*/
|
|
40
|
-
export function computeHmac(algorithm: "sha256" | "sha512", _key: BytesLike, _data: BytesLike): string {
|
|
41
|
-
const key = getBytes(_key, "key");
|
|
42
|
-
const data = getBytes(_data, "data");
|
|
43
|
-
return hexlify(__computeHmac(algorithm, key, data));
|
|
44
|
-
}
|
|
45
|
-
computeHmac._ = _computeHmac;
|
|
46
|
-
computeHmac.lock = function() { locked = true; }
|
|
47
|
-
computeHmac.register = function(func: (algorithm: "sha256" | "sha512", key: Uint8Array, data: Uint8Array) => BytesLike) {
|
|
48
|
-
if (locked) { throw new Error("computeHmac is locked"); }
|
|
49
|
-
__computeHmac = func;
|
|
50
|
-
}
|
|
51
|
-
Object.freeze(computeHmac);
|
|
1
|
+
/**
|
|
2
|
+
* An **HMAC** enables verification that a given key was used
|
|
3
|
+
* to authenticate a payload.
|
|
4
|
+
*
|
|
5
|
+
* See: [[link-wiki-hmac]]
|
|
6
|
+
*
|
|
7
|
+
* @_subsection: api/crypto:HMAC [about-hmac]
|
|
8
|
+
*/
|
|
9
|
+
import { createHmac } from "./crypto.js";
|
|
10
|
+
import { getBytes, hexlify } from "../utils/index.js";
|
|
11
|
+
|
|
12
|
+
import type { BytesLike } from "../utils/index.js";
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
let locked = false;
|
|
16
|
+
|
|
17
|
+
const _computeHmac = function(algorithm: "sha256" | "sha512", key: Uint8Array, data: Uint8Array): BytesLike {
|
|
18
|
+
return createHmac(algorithm, key).update(data).digest();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let __computeHmac = _computeHmac;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Return the HMAC for %%data%% using the %%key%% key with the underlying
|
|
25
|
+
* %%algo%% used for compression.
|
|
26
|
+
*
|
|
27
|
+
* @example:
|
|
28
|
+
* key = id("some-secret")
|
|
29
|
+
*
|
|
30
|
+
* // Compute the HMAC
|
|
31
|
+
* computeHmac("sha256", key, "0x1337")
|
|
32
|
+
* //_result:
|
|
33
|
+
*
|
|
34
|
+
* // To compute the HMAC of UTF-8 data, the data must be
|
|
35
|
+
* // converted to UTF-8 bytes
|
|
36
|
+
* computeHmac("sha256", key, toUtf8Bytes("Hello World"))
|
|
37
|
+
* //_result:
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
40
|
+
export function computeHmac(algorithm: "sha256" | "sha512", _key: BytesLike, _data: BytesLike): string {
|
|
41
|
+
const key = getBytes(_key, "key");
|
|
42
|
+
const data = getBytes(_data, "data");
|
|
43
|
+
return hexlify(__computeHmac(algorithm, key, data));
|
|
44
|
+
}
|
|
45
|
+
computeHmac._ = _computeHmac;
|
|
46
|
+
computeHmac.lock = function() { locked = true; }
|
|
47
|
+
computeHmac.register = function(func: (algorithm: "sha256" | "sha512", key: Uint8Array, data: Uint8Array) => BytesLike) {
|
|
48
|
+
if (locked) { throw new Error("computeHmac is locked"); }
|
|
49
|
+
__computeHmac = func;
|
|
50
|
+
}
|
|
51
|
+
Object.freeze(computeHmac);
|
package/src.ts/crypto/index.ts
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A fundamental building block of Ethereum is the underlying
|
|
3
|
-
* cryptographic primitives.
|
|
4
|
-
*
|
|
5
|
-
* @_section: api/crypto:Cryptographic Functions [about-crypto]
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
null
|
|
9
|
-
|
|
10
|
-
// We import all these so we can export lock()
|
|
11
|
-
import { computeHmac } from "./hmac.js";
|
|
12
|
-
import { keccak256 } from "./keccak.js";
|
|
13
|
-
import { ripemd160 } from "./ripemd160.js";
|
|
14
|
-
import { pbkdf2 } from "./pbkdf2.js";
|
|
15
|
-
import { randomBytes } from "./random.js";
|
|
16
|
-
import { scrypt, scryptSync } from "./scrypt.js";
|
|
17
|
-
import { sha256, sha512 } from "./sha2.js";
|
|
18
|
-
|
|
19
|
-
export {
|
|
20
|
-
computeHmac,
|
|
21
|
-
|
|
22
|
-
randomBytes,
|
|
23
|
-
|
|
24
|
-
keccak256,
|
|
25
|
-
ripemd160,
|
|
26
|
-
sha256, sha512,
|
|
27
|
-
|
|
28
|
-
pbkdf2,
|
|
29
|
-
scrypt, scryptSync
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export { SigningKey } from "./signing-key.js";
|
|
33
|
-
export { Signature } from "./signature.js";
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Once called, prevents any future change to the underlying cryptographic
|
|
37
|
-
* primitives using the ``.register`` feature for hooks.
|
|
38
|
-
*/
|
|
39
|
-
function lock(): void {
|
|
40
|
-
computeHmac.lock();
|
|
41
|
-
keccak256.lock();
|
|
42
|
-
pbkdf2.lock();
|
|
43
|
-
randomBytes.lock();
|
|
44
|
-
ripemd160.lock();
|
|
45
|
-
scrypt.lock();
|
|
46
|
-
scryptSync.lock();
|
|
47
|
-
sha256.lock();
|
|
48
|
-
sha512.lock();
|
|
49
|
-
randomBytes.lock();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export { lock };
|
|
53
|
-
|
|
54
|
-
/////////////////////////////
|
|
55
|
-
// Types
|
|
56
|
-
|
|
57
|
-
export type { ProgressCallback } from "./scrypt.js";
|
|
58
|
-
|
|
59
|
-
export type { SignatureLike } from "./signature.js";
|
|
1
|
+
/**
|
|
2
|
+
* A fundamental building block of Ethereum is the underlying
|
|
3
|
+
* cryptographic primitives.
|
|
4
|
+
*
|
|
5
|
+
* @_section: api/crypto:Cryptographic Functions [about-crypto]
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
null
|
|
9
|
+
|
|
10
|
+
// We import all these so we can export lock()
|
|
11
|
+
import { computeHmac } from "./hmac.js";
|
|
12
|
+
import { keccak256 } from "./keccak.js";
|
|
13
|
+
import { ripemd160 } from "./ripemd160.js";
|
|
14
|
+
import { pbkdf2 } from "./pbkdf2.js";
|
|
15
|
+
import { randomBytes } from "./random.js";
|
|
16
|
+
import { scrypt, scryptSync } from "./scrypt.js";
|
|
17
|
+
import { sha256, sha512 } from "./sha2.js";
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
computeHmac,
|
|
21
|
+
|
|
22
|
+
randomBytes,
|
|
23
|
+
|
|
24
|
+
keccak256,
|
|
25
|
+
ripemd160,
|
|
26
|
+
sha256, sha512,
|
|
27
|
+
|
|
28
|
+
pbkdf2,
|
|
29
|
+
scrypt, scryptSync
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { SigningKey } from "./signing-key.js";
|
|
33
|
+
export { Signature } from "./signature.js";
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Once called, prevents any future change to the underlying cryptographic
|
|
37
|
+
* primitives using the ``.register`` feature for hooks.
|
|
38
|
+
*/
|
|
39
|
+
function lock(): void {
|
|
40
|
+
computeHmac.lock();
|
|
41
|
+
keccak256.lock();
|
|
42
|
+
pbkdf2.lock();
|
|
43
|
+
randomBytes.lock();
|
|
44
|
+
ripemd160.lock();
|
|
45
|
+
scrypt.lock();
|
|
46
|
+
scryptSync.lock();
|
|
47
|
+
sha256.lock();
|
|
48
|
+
sha512.lock();
|
|
49
|
+
randomBytes.lock();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { lock };
|
|
53
|
+
|
|
54
|
+
/////////////////////////////
|
|
55
|
+
// Types
|
|
56
|
+
|
|
57
|
+
export type { ProgressCallback } from "./scrypt.js";
|
|
58
|
+
|
|
59
|
+
export type { SignatureLike } from "./signature.js";
|
package/src.ts/crypto/keccak.ts
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cryptographic hashing functions
|
|
3
|
-
*
|
|
4
|
-
* @_subsection: api/crypto:Hash Functions [about-crypto-hashing]
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { keccak_256 } from "@noble/hashes/sha3";
|
|
8
|
-
|
|
9
|
-
import { getBytes, hexlify } from "../utils/index.js";
|
|
10
|
-
|
|
11
|
-
import type { BytesLike } from "../utils/index.js";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let locked = false;
|
|
15
|
-
|
|
16
|
-
const _keccak256 = function(data: Uint8Array): Uint8Array {
|
|
17
|
-
return keccak_256(data);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
let __keccak256: (data: Uint8Array) => BytesLike = _keccak256;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Compute the cryptographic KECCAK256 hash of %%data%%.
|
|
24
|
-
*
|
|
25
|
-
* The %%data%% **must** be a data representation, to compute the
|
|
26
|
-
* hash of UTF-8 data use the [[id]] function.
|
|
27
|
-
*
|
|
28
|
-
* @returns DataHexstring
|
|
29
|
-
* @example:
|
|
30
|
-
* keccak256("0x")
|
|
31
|
-
* //_result:
|
|
32
|
-
*
|
|
33
|
-
* keccak256("0x1337")
|
|
34
|
-
* //_result:
|
|
35
|
-
*
|
|
36
|
-
* keccak256(new Uint8Array([ 0x13, 0x37 ]))
|
|
37
|
-
* //_result:
|
|
38
|
-
*
|
|
39
|
-
* // Strings are assumed to be DataHexString, otherwise it will
|
|
40
|
-
* // throw. To hash UTF-8 data, see the note above.
|
|
41
|
-
* keccak256("Hello World")
|
|
42
|
-
* //_error:
|
|
43
|
-
*/
|
|
44
|
-
export function keccak256(_data: BytesLike): string {
|
|
45
|
-
const data = getBytes(_data, "data");
|
|
46
|
-
return hexlify(__keccak256(data));
|
|
47
|
-
}
|
|
48
|
-
keccak256._ = _keccak256;
|
|
49
|
-
keccak256.lock = function(): void { locked = true; }
|
|
50
|
-
keccak256.register = function(func: (data: Uint8Array) => BytesLike) {
|
|
51
|
-
if (locked) { throw new TypeError("keccak256 is locked"); }
|
|
52
|
-
__keccak256 = func;
|
|
53
|
-
}
|
|
54
|
-
Object.freeze(keccak256);
|
|
1
|
+
/**
|
|
2
|
+
* Cryptographic hashing functions
|
|
3
|
+
*
|
|
4
|
+
* @_subsection: api/crypto:Hash Functions [about-crypto-hashing]
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { keccak_256 } from "@noble/hashes/sha3";
|
|
8
|
+
|
|
9
|
+
import { getBytes, hexlify } from "../utils/index.js";
|
|
10
|
+
|
|
11
|
+
import type { BytesLike } from "../utils/index.js";
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
let locked = false;
|
|
15
|
+
|
|
16
|
+
const _keccak256 = function(data: Uint8Array): Uint8Array {
|
|
17
|
+
return keccak_256(data);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let __keccak256: (data: Uint8Array) => BytesLike = _keccak256;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Compute the cryptographic KECCAK256 hash of %%data%%.
|
|
24
|
+
*
|
|
25
|
+
* The %%data%% **must** be a data representation, to compute the
|
|
26
|
+
* hash of UTF-8 data use the [[id]] function.
|
|
27
|
+
*
|
|
28
|
+
* @returns DataHexstring
|
|
29
|
+
* @example:
|
|
30
|
+
* keccak256("0x")
|
|
31
|
+
* //_result:
|
|
32
|
+
*
|
|
33
|
+
* keccak256("0x1337")
|
|
34
|
+
* //_result:
|
|
35
|
+
*
|
|
36
|
+
* keccak256(new Uint8Array([ 0x13, 0x37 ]))
|
|
37
|
+
* //_result:
|
|
38
|
+
*
|
|
39
|
+
* // Strings are assumed to be DataHexString, otherwise it will
|
|
40
|
+
* // throw. To hash UTF-8 data, see the note above.
|
|
41
|
+
* keccak256("Hello World")
|
|
42
|
+
* //_error:
|
|
43
|
+
*/
|
|
44
|
+
export function keccak256(_data: BytesLike): string {
|
|
45
|
+
const data = getBytes(_data, "data");
|
|
46
|
+
return hexlify(__keccak256(data));
|
|
47
|
+
}
|
|
48
|
+
keccak256._ = _keccak256;
|
|
49
|
+
keccak256.lock = function(): void { locked = true; }
|
|
50
|
+
keccak256.register = function(func: (data: Uint8Array) => BytesLike) {
|
|
51
|
+
if (locked) { throw new TypeError("keccak256 is locked"); }
|
|
52
|
+
__keccak256 = func;
|
|
53
|
+
}
|
|
54
|
+
Object.freeze(keccak256);
|
package/src.ts/crypto/pbkdf2.ts
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A **Password-Based Key-Derivation Function** is designed to create
|
|
3
|
-
* a sequence of bytes suitible as a **key** from a human-rememberable
|
|
4
|
-
* password.
|
|
5
|
-
*
|
|
6
|
-
* @_subsection: api/crypto:Passwords [about-pbkdf]
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { pbkdf2Sync } from "./crypto.js";
|
|
10
|
-
|
|
11
|
-
import { getBytes, hexlify } from "../utils/index.js";
|
|
12
|
-
|
|
13
|
-
import type { BytesLike } from "../utils/index.js";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
let locked = false;
|
|
17
|
-
|
|
18
|
-
const _pbkdf2 = function(password: Uint8Array, salt: Uint8Array, iterations: number, keylen: number, algo: "sha256" | "sha512"): BytesLike {
|
|
19
|
-
return pbkdf2Sync(password, salt, iterations, keylen, algo);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
let __pbkdf2 = _pbkdf2;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Return the [[link-pbkdf2]] for %%keylen%% bytes for %%password%% using
|
|
26
|
-
* the %%salt%% and using %%iterations%% of %%algo%%.
|
|
27
|
-
*
|
|
28
|
-
* This PBKDF is outdated and should not be used in new projects, but is
|
|
29
|
-
* required to decrypt older files.
|
|
30
|
-
*
|
|
31
|
-
* @example:
|
|
32
|
-
* // The password must be converted to bytes, and it is generally
|
|
33
|
-
* // best practices to ensure the string has been normalized. Many
|
|
34
|
-
* // formats explicitly indicate the normalization form to use.
|
|
35
|
-
* password = "hello"
|
|
36
|
-
* passwordBytes = toUtf8Bytes(password, "NFKC")
|
|
37
|
-
*
|
|
38
|
-
* salt = id("some-salt")
|
|
39
|
-
*
|
|
40
|
-
* // Compute the PBKDF2
|
|
41
|
-
* pbkdf2(passwordBytes, salt, 1024, 16, "sha256")
|
|
42
|
-
* //_result:
|
|
43
|
-
*/
|
|
44
|
-
export function pbkdf2(_password: BytesLike, _salt: BytesLike, iterations: number, keylen: number, algo: "sha256" | "sha512"): string {
|
|
45
|
-
const password = getBytes(_password, "password");
|
|
46
|
-
const salt = getBytes(_salt, "salt");
|
|
47
|
-
return hexlify(__pbkdf2(password, salt, iterations, keylen, algo));
|
|
48
|
-
}
|
|
49
|
-
pbkdf2._ = _pbkdf2;
|
|
50
|
-
pbkdf2.lock = function(): void { locked = true; }
|
|
51
|
-
pbkdf2.register = function(func: (password: Uint8Array, salt: Uint8Array, iterations: number, keylen: number, algo: "sha256" | "sha512") => BytesLike) {
|
|
52
|
-
if (locked) { throw new Error("pbkdf2 is locked"); }
|
|
53
|
-
__pbkdf2 = func;
|
|
54
|
-
}
|
|
55
|
-
Object.freeze(pbkdf2);
|
|
1
|
+
/**
|
|
2
|
+
* A **Password-Based Key-Derivation Function** is designed to create
|
|
3
|
+
* a sequence of bytes suitible as a **key** from a human-rememberable
|
|
4
|
+
* password.
|
|
5
|
+
*
|
|
6
|
+
* @_subsection: api/crypto:Passwords [about-pbkdf]
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { pbkdf2Sync } from "./crypto.js";
|
|
10
|
+
|
|
11
|
+
import { getBytes, hexlify } from "../utils/index.js";
|
|
12
|
+
|
|
13
|
+
import type { BytesLike } from "../utils/index.js";
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
let locked = false;
|
|
17
|
+
|
|
18
|
+
const _pbkdf2 = function(password: Uint8Array, salt: Uint8Array, iterations: number, keylen: number, algo: "sha256" | "sha512"): BytesLike {
|
|
19
|
+
return pbkdf2Sync(password, salt, iterations, keylen, algo);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let __pbkdf2 = _pbkdf2;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Return the [[link-pbkdf2]] for %%keylen%% bytes for %%password%% using
|
|
26
|
+
* the %%salt%% and using %%iterations%% of %%algo%%.
|
|
27
|
+
*
|
|
28
|
+
* This PBKDF is outdated and should not be used in new projects, but is
|
|
29
|
+
* required to decrypt older files.
|
|
30
|
+
*
|
|
31
|
+
* @example:
|
|
32
|
+
* // The password must be converted to bytes, and it is generally
|
|
33
|
+
* // best practices to ensure the string has been normalized. Many
|
|
34
|
+
* // formats explicitly indicate the normalization form to use.
|
|
35
|
+
* password = "hello"
|
|
36
|
+
* passwordBytes = toUtf8Bytes(password, "NFKC")
|
|
37
|
+
*
|
|
38
|
+
* salt = id("some-salt")
|
|
39
|
+
*
|
|
40
|
+
* // Compute the PBKDF2
|
|
41
|
+
* pbkdf2(passwordBytes, salt, 1024, 16, "sha256")
|
|
42
|
+
* //_result:
|
|
43
|
+
*/
|
|
44
|
+
export function pbkdf2(_password: BytesLike, _salt: BytesLike, iterations: number, keylen: number, algo: "sha256" | "sha512"): string {
|
|
45
|
+
const password = getBytes(_password, "password");
|
|
46
|
+
const salt = getBytes(_salt, "salt");
|
|
47
|
+
return hexlify(__pbkdf2(password, salt, iterations, keylen, algo));
|
|
48
|
+
}
|
|
49
|
+
pbkdf2._ = _pbkdf2;
|
|
50
|
+
pbkdf2.lock = function(): void { locked = true; }
|
|
51
|
+
pbkdf2.register = function(func: (password: Uint8Array, salt: Uint8Array, iterations: number, keylen: number, algo: "sha256" | "sha512") => BytesLike) {
|
|
52
|
+
if (locked) { throw new Error("pbkdf2 is locked"); }
|
|
53
|
+
__pbkdf2 = func;
|
|
54
|
+
}
|
|
55
|
+
Object.freeze(pbkdf2);
|
package/src.ts/crypto/random.ts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A **Cryptographically Secure Random Value** is one that has been
|
|
3
|
-
* generated with additional care take to prevent side-channels
|
|
4
|
-
* from allowing others to detect it and prevent others from through
|
|
5
|
-
* coincidence generate the same values.
|
|
6
|
-
*
|
|
7
|
-
* @_subsection: api/crypto:Random Values [about-crypto-random]
|
|
8
|
-
*/
|
|
9
|
-
import { randomBytes as crypto_random } from "./crypto.js";
|
|
10
|
-
|
|
11
|
-
let locked = false;
|
|
12
|
-
|
|
13
|
-
const _randomBytes = function(length: number): Uint8Array {
|
|
14
|
-
return new Uint8Array(crypto_random(length));
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
let __randomBytes = _randomBytes;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Return %%length%% bytes of cryptographically secure random data.
|
|
21
|
-
*
|
|
22
|
-
* @example:
|
|
23
|
-
* randomBytes(8)
|
|
24
|
-
* //_result:
|
|
25
|
-
*/
|
|
26
|
-
export function randomBytes(length: number): Uint8Array {
|
|
27
|
-
return __randomBytes(length);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
randomBytes._ = _randomBytes;
|
|
31
|
-
randomBytes.lock = function(): void { locked = true; }
|
|
32
|
-
randomBytes.register = function(func: (length: number) => Uint8Array) {
|
|
33
|
-
if (locked) { throw new Error("randomBytes is locked"); }
|
|
34
|
-
__randomBytes = func;
|
|
35
|
-
}
|
|
36
|
-
Object.freeze(randomBytes);
|
|
1
|
+
/**
|
|
2
|
+
* A **Cryptographically Secure Random Value** is one that has been
|
|
3
|
+
* generated with additional care take to prevent side-channels
|
|
4
|
+
* from allowing others to detect it and prevent others from through
|
|
5
|
+
* coincidence generate the same values.
|
|
6
|
+
*
|
|
7
|
+
* @_subsection: api/crypto:Random Values [about-crypto-random]
|
|
8
|
+
*/
|
|
9
|
+
import { randomBytes as crypto_random } from "./crypto.js";
|
|
10
|
+
|
|
11
|
+
let locked = false;
|
|
12
|
+
|
|
13
|
+
const _randomBytes = function(length: number): Uint8Array {
|
|
14
|
+
return new Uint8Array(crypto_random(length));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let __randomBytes = _randomBytes;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Return %%length%% bytes of cryptographically secure random data.
|
|
21
|
+
*
|
|
22
|
+
* @example:
|
|
23
|
+
* randomBytes(8)
|
|
24
|
+
* //_result:
|
|
25
|
+
*/
|
|
26
|
+
export function randomBytes(length: number): Uint8Array {
|
|
27
|
+
return __randomBytes(length);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
randomBytes._ = _randomBytes;
|
|
31
|
+
randomBytes.lock = function(): void { locked = true; }
|
|
32
|
+
randomBytes.register = function(func: (length: number) => Uint8Array) {
|
|
33
|
+
if (locked) { throw new Error("randomBytes is locked"); }
|
|
34
|
+
__randomBytes = func;
|
|
35
|
+
}
|
|
36
|
+
Object.freeze(randomBytes);
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import { ripemd160 as noble_ripemd160 } from "@noble/hashes/ripemd160";
|
|
2
|
-
|
|
3
|
-
import { getBytes, hexlify } from "../utils/index.js";
|
|
4
|
-
|
|
5
|
-
import type { BytesLike } from "../utils/index.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
let locked = false;
|
|
9
|
-
|
|
10
|
-
const _ripemd160 = function(data: Uint8Array): Uint8Array {
|
|
11
|
-
return noble_ripemd160(data);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
let __ripemd160: (data: Uint8Array) => BytesLike = _ripemd160;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Compute the cryptographic RIPEMD-160 hash of %%data%%.
|
|
18
|
-
*
|
|
19
|
-
* @_docloc: api/crypto:Hash Functions
|
|
20
|
-
* @returns DataHexstring
|
|
21
|
-
*
|
|
22
|
-
* @example:
|
|
23
|
-
* ripemd160("0x")
|
|
24
|
-
* //_result:
|
|
25
|
-
*
|
|
26
|
-
* ripemd160("0x1337")
|
|
27
|
-
* //_result:
|
|
28
|
-
*
|
|
29
|
-
* ripemd160(new Uint8Array([ 0x13, 0x37 ]))
|
|
30
|
-
* //_result:
|
|
31
|
-
*
|
|
32
|
-
*/
|
|
33
|
-
export function ripemd160(_data: BytesLike): string {
|
|
34
|
-
const data = getBytes(_data, "data");
|
|
35
|
-
return hexlify(__ripemd160(data));
|
|
36
|
-
}
|
|
37
|
-
ripemd160._ = _ripemd160;
|
|
38
|
-
ripemd160.lock = function(): void { locked = true; }
|
|
39
|
-
ripemd160.register = function(func: (data: Uint8Array) => BytesLike) {
|
|
40
|
-
if (locked) { throw new TypeError("ripemd160 is locked"); }
|
|
41
|
-
__ripemd160 = func;
|
|
42
|
-
}
|
|
43
|
-
Object.freeze(ripemd160);
|
|
1
|
+
import { ripemd160 as noble_ripemd160 } from "@noble/hashes/ripemd160";
|
|
2
|
+
|
|
3
|
+
import { getBytes, hexlify } from "../utils/index.js";
|
|
4
|
+
|
|
5
|
+
import type { BytesLike } from "../utils/index.js";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
let locked = false;
|
|
9
|
+
|
|
10
|
+
const _ripemd160 = function(data: Uint8Array): Uint8Array {
|
|
11
|
+
return noble_ripemd160(data);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let __ripemd160: (data: Uint8Array) => BytesLike = _ripemd160;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Compute the cryptographic RIPEMD-160 hash of %%data%%.
|
|
18
|
+
*
|
|
19
|
+
* @_docloc: api/crypto:Hash Functions
|
|
20
|
+
* @returns DataHexstring
|
|
21
|
+
*
|
|
22
|
+
* @example:
|
|
23
|
+
* ripemd160("0x")
|
|
24
|
+
* //_result:
|
|
25
|
+
*
|
|
26
|
+
* ripemd160("0x1337")
|
|
27
|
+
* //_result:
|
|
28
|
+
*
|
|
29
|
+
* ripemd160(new Uint8Array([ 0x13, 0x37 ]))
|
|
30
|
+
* //_result:
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
export function ripemd160(_data: BytesLike): string {
|
|
34
|
+
const data = getBytes(_data, "data");
|
|
35
|
+
return hexlify(__ripemd160(data));
|
|
36
|
+
}
|
|
37
|
+
ripemd160._ = _ripemd160;
|
|
38
|
+
ripemd160.lock = function(): void { locked = true; }
|
|
39
|
+
ripemd160.register = function(func: (data: Uint8Array) => BytesLike) {
|
|
40
|
+
if (locked) { throw new TypeError("ripemd160 is locked"); }
|
|
41
|
+
__ripemd160 = func;
|
|
42
|
+
}
|
|
43
|
+
Object.freeze(ripemd160);
|