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
|
@@ -1,118 +1,126 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Add details about signing here.
|
|
3
|
-
*
|
|
4
|
-
* @_subsection: api/crypto:Signing [about-signing]
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
getBytes,
|
|
12
|
-
dataLength, getBytesCopy, hexlify,
|
|
13
|
-
assertArgument
|
|
14
|
-
} from "../utils/index.js";
|
|
15
|
-
|
|
16
|
-
import { Signature } from "./signature.js";
|
|
17
|
-
|
|
18
|
-
import type { BytesLike } from "../utils/index.js";
|
|
19
|
-
|
|
20
|
-
import type { SignatureLike } from "./index.js";
|
|
21
|
-
|
|
22
|
-
const CRYPTO_MESSAGE_LENGTH = 32;
|
|
23
|
-
const CRYPTO_SECRETKEY_BYTES = 64 + 2560 + 1312 + 128;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* A **SigningKey** provides high-level access to cryptography operations and key management.
|
|
28
|
-
*/
|
|
29
|
-
export class SigningKey {
|
|
30
|
-
#privateKey: string;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Creates a new **SigningKey** for %%privateKey%%.
|
|
34
|
-
*/
|
|
35
|
-
constructor(privateKey: BytesLike) {
|
|
36
|
-
assertArgument(dataLength(privateKey) === CRYPTO_SECRETKEY_BYTES, "invalid private key", "privateKey", "[REDACTED]");
|
|
37
|
-
this.#privateKey = hexlify(privateKey);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* The private key.
|
|
42
|
-
*/
|
|
43
|
-
get privateKey(): string { return this.#privateKey; }
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* The public key.
|
|
47
|
-
*
|
|
48
|
-
*/
|
|
49
|
-
get publicKey(): string { return SigningKey.computePublicKey(this.#privateKey); }
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Return the signature of the signed %%digest%%.
|
|
53
|
-
*/
|
|
54
|
-
sign(digest: BytesLike): Signature {
|
|
55
|
-
assertArgument(dataLength(digest) === CRYPTO_MESSAGE_LENGTH, "invalid digest length", "digest", digest);
|
|
56
|
-
|
|
57
|
-
const sig: any =
|
|
58
|
-
const pubBytes: any = getBytes(this.publicKey);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
let
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Add details about signing here.
|
|
3
|
+
*
|
|
4
|
+
* @_subsection: api/crypto:Signing [about-signing]
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {combinePublicKeySignature, publicKeyFromPrivateKey, publicKeyFromSignature} from "quantum-coin-js-sdk";
|
|
8
|
+
import {cryptoSign} from "quantum-coin-pqc-js-sdk";
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
getBytes,
|
|
12
|
+
dataLength, getBytesCopy, hexlify,
|
|
13
|
+
assertArgument,
|
|
14
|
+
} from "../utils/index.js";
|
|
15
|
+
|
|
16
|
+
import { Signature } from "./signature.js";
|
|
17
|
+
|
|
18
|
+
import type { BytesLike } from "../utils/index.js";
|
|
19
|
+
|
|
20
|
+
import type { SignatureLike } from "./index.js";
|
|
21
|
+
|
|
22
|
+
const CRYPTO_MESSAGE_LENGTH = 32;
|
|
23
|
+
const CRYPTO_SECRETKEY_BYTES = 64 + 2560 + 1312 + 128;
|
|
24
|
+
const CRYPTO_PUBLICKEY_BYTES = 32 + 1312 + 64;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A **SigningKey** provides high-level access to cryptography operations and key management.
|
|
28
|
+
*/
|
|
29
|
+
export class SigningKey {
|
|
30
|
+
#privateKey: string;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new **SigningKey** for %%privateKey%%.
|
|
34
|
+
*/
|
|
35
|
+
constructor(privateKey: BytesLike) {
|
|
36
|
+
assertArgument(dataLength(privateKey) === CRYPTO_SECRETKEY_BYTES, "invalid private key", "privateKey", "[REDACTED]");
|
|
37
|
+
this.#privateKey = hexlify(privateKey);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The private key.
|
|
42
|
+
*/
|
|
43
|
+
get privateKey(): string { return this.#privateKey; }
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The public key.
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
get publicKey(): string { return SigningKey.computePublicKey(this.#privateKey); }
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Return the signature of the signed %%digest%%.
|
|
53
|
+
*/
|
|
54
|
+
sign(digest: BytesLike): Signature {
|
|
55
|
+
assertArgument(dataLength(digest) === CRYPTO_MESSAGE_LENGTH, "invalid digest length", "digest", digest);
|
|
56
|
+
|
|
57
|
+
const sig: any = cryptoSign(getBytesCopy(digest), getBytesCopy(this.#privateKey));
|
|
58
|
+
const pubBytes: any = getBytes(this.publicKey);
|
|
59
|
+
let combinedSig = combinePublicKeySignature(pubBytes, sig);
|
|
60
|
+
combinedSig = "0x" + combinedSig;
|
|
61
|
+
|
|
62
|
+
return Signature.from({
|
|
63
|
+
r: this.publicKey,
|
|
64
|
+
s: combinedSig,
|
|
65
|
+
v: 0x1
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Compute the public key for a private %%key%%. If a publicKey is passed, it is returned as is. for backward compatibility.
|
|
71
|
+
*
|
|
72
|
+
*
|
|
73
|
+
* @example:
|
|
74
|
+
* sign = new SigningKey(id("some-secret"));
|
|
75
|
+
*
|
|
76
|
+
* // Compute the public key for a private key
|
|
77
|
+
* SigningKey.computePublicKey(sign.privateKey)
|
|
78
|
+
* //_result:
|
|
79
|
+
*/
|
|
80
|
+
static computePublicKey(key: BytesLike): string {
|
|
81
|
+
let keyBytes: any = getBytes(key, "key");
|
|
82
|
+
let pubKey: any;
|
|
83
|
+
|
|
84
|
+
if (keyBytes.length == CRYPTO_SECRETKEY_BYTES) {
|
|
85
|
+
pubKey = publicKeyFromPrivateKey(keyBytes);
|
|
86
|
+
assertArgument(pubKey !== null && pubKey !== undefined, "invalid key", "key", "[REDACTED]");
|
|
87
|
+
pubKey = '0x' + pubKey;
|
|
88
|
+
} else if(keyBytes.length == CRYPTO_PUBLICKEY_BYTES) {
|
|
89
|
+
pubKey = keyBytes;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
assertArgument(pubKey !== null && pubKey !== undefined, "invalid key", "key", "[REDACTED]");
|
|
93
|
+
return pubKey;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Returns the public key for the private key which produced the
|
|
98
|
+
* %%signature%% for the given %%digest%%.
|
|
99
|
+
*
|
|
100
|
+
* @example:
|
|
101
|
+
* key = new SigningKey(id("some-secret"))
|
|
102
|
+
* digest = id("hello world")
|
|
103
|
+
* sig = key.sign(digest)
|
|
104
|
+
*
|
|
105
|
+
* // Notice the signer public key...
|
|
106
|
+
* key.publicKey
|
|
107
|
+
* //_result:
|
|
108
|
+
*
|
|
109
|
+
* // ...is equal to the recovered public key
|
|
110
|
+
* SigningKey.recoverPublicKey(digest, sig)
|
|
111
|
+
* //_result:
|
|
112
|
+
*
|
|
113
|
+
*/
|
|
114
|
+
static recoverPublicKey(digest: BytesLike, signature: SignatureLike): string {
|
|
115
|
+
assertArgument(dataLength(digest) === CRYPTO_MESSAGE_LENGTH, "invalid digest length", "digest", digest);
|
|
116
|
+
|
|
117
|
+
const sig = Signature.from(signature);
|
|
118
|
+
let sigBytes: any = getBytes(sig.s);
|
|
119
|
+
let digestBytes: any = digest;
|
|
120
|
+
|
|
121
|
+
let publicKey = publicKeyFromSignature(digestBytes, sigBytes);
|
|
122
|
+
|
|
123
|
+
return publicKey;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import { getAddress } from "../address/index.js";
|
|
2
|
-
import { keccak256 } from "../crypto/index.js";
|
|
3
|
-
import { recoverAddress } from "../transaction/index.js";
|
|
4
|
-
import {
|
|
5
|
-
assertArgument, concat, encodeRlp, toBeArray
|
|
6
|
-
} from "../utils/index.js";
|
|
7
|
-
|
|
8
|
-
import type { Addressable } from "../address/index.js";
|
|
9
|
-
import type { SignatureLike } from "../crypto/index.js";
|
|
10
|
-
import type { BigNumberish, Numeric } from "../utils/index.js";
|
|
11
|
-
|
|
12
|
-
export interface AuthorizationRequest {
|
|
13
|
-
address: string | Addressable;
|
|
14
|
-
nonce?: Numeric;
|
|
15
|
-
chainId?: BigNumberish;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Computes the [[link-eip-7702]] authorization digest to sign.
|
|
20
|
-
*/
|
|
21
|
-
export function hashAuthorization(auth: AuthorizationRequest): string {
|
|
22
|
-
assertArgument(typeof(auth.address) === "string", "invalid address for hashAuthorization", "auth.address", auth);
|
|
23
|
-
return keccak256(concat([
|
|
24
|
-
"0x05", encodeRlp([
|
|
25
|
-
(auth.chainId != null) ? toBeArray(auth.chainId): "0x",
|
|
26
|
-
getAddress(auth.address),
|
|
27
|
-
(auth.nonce != null) ? toBeArray(auth.nonce): "0x",
|
|
28
|
-
])
|
|
29
|
-
]));
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Return the address of the private key that produced
|
|
34
|
-
* the signature %%sig%% during signing for %%message%%.
|
|
35
|
-
*/
|
|
36
|
-
export function verifyAuthorization(auth: AuthorizationRequest, sig: SignatureLike): string {
|
|
37
|
-
return recoverAddress(hashAuthorization(auth), sig);
|
|
38
|
-
}
|
|
1
|
+
import { getAddress } from "../address/index.js";
|
|
2
|
+
import { keccak256 } from "../crypto/index.js";
|
|
3
|
+
import { recoverAddress } from "../transaction/index.js";
|
|
4
|
+
import {
|
|
5
|
+
assertArgument, concat, encodeRlp, toBeArray
|
|
6
|
+
} from "../utils/index.js";
|
|
7
|
+
|
|
8
|
+
import type { Addressable } from "../address/index.js";
|
|
9
|
+
import type { SignatureLike } from "../crypto/index.js";
|
|
10
|
+
import type { BigNumberish, Numeric } from "../utils/index.js";
|
|
11
|
+
|
|
12
|
+
export interface AuthorizationRequest {
|
|
13
|
+
address: string | Addressable;
|
|
14
|
+
nonce?: Numeric;
|
|
15
|
+
chainId?: BigNumberish;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Computes the [[link-eip-7702]] authorization digest to sign.
|
|
20
|
+
*/
|
|
21
|
+
export function hashAuthorization(auth: AuthorizationRequest): string {
|
|
22
|
+
assertArgument(typeof(auth.address) === "string", "invalid address for hashAuthorization", "auth.address", auth);
|
|
23
|
+
return keccak256(concat([
|
|
24
|
+
"0x05", encodeRlp([
|
|
25
|
+
(auth.chainId != null) ? toBeArray(auth.chainId): "0x",
|
|
26
|
+
getAddress(auth.address),
|
|
27
|
+
(auth.nonce != null) ? toBeArray(auth.nonce): "0x",
|
|
28
|
+
])
|
|
29
|
+
]));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Return the address of the private key that produced
|
|
34
|
+
* the signature %%sig%% during signing for %%message%%.
|
|
35
|
+
*/
|
|
36
|
+
export function verifyAuthorization(auth: AuthorizationRequest, sig: SignatureLike): string {
|
|
37
|
+
return recoverAddress(hashAuthorization(auth), sig);
|
|
38
|
+
}
|
package/src.ts/hash/id.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { keccak256 } from "../crypto/index.js";
|
|
2
|
-
import { toUtf8Bytes } from "../utils/index.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* A simple hashing function which operates on UTF-8 strings to
|
|
6
|
-
* compute an 32-byte identifier.
|
|
7
|
-
*
|
|
8
|
-
* This simply computes the [UTF-8 bytes](toUtf8Bytes) and computes
|
|
9
|
-
* the [[keccak256]].
|
|
10
|
-
*
|
|
11
|
-
* @example:
|
|
12
|
-
* id("hello world")
|
|
13
|
-
* //_result:
|
|
14
|
-
*/
|
|
15
|
-
export function id(value: string): string {
|
|
16
|
-
return keccak256(toUtf8Bytes(value));
|
|
17
|
-
}
|
|
1
|
+
import { keccak256 } from "../crypto/index.js";
|
|
2
|
+
import { toUtf8Bytes } from "../utils/index.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A simple hashing function which operates on UTF-8 strings to
|
|
6
|
+
* compute an 32-byte identifier.
|
|
7
|
+
*
|
|
8
|
+
* This simply computes the [UTF-8 bytes](toUtf8Bytes) and computes
|
|
9
|
+
* the [[keccak256]].
|
|
10
|
+
*
|
|
11
|
+
* @example:
|
|
12
|
+
* id("hello world")
|
|
13
|
+
* //_result:
|
|
14
|
+
*/
|
|
15
|
+
export function id(value: string): string {
|
|
16
|
+
return keccak256(toUtf8Bytes(value));
|
|
17
|
+
}
|
package/src.ts/hash/index.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utilities for common tasks involving hashing. Also see
|
|
3
|
-
* [cryptographic hashing](about-crypto-hashing).
|
|
4
|
-
*
|
|
5
|
-
* @_section: api/hashing:Hashing Utilities [about-hashing]
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export { hashAuthorization, verifyAuthorization } from "./authorization.js";
|
|
9
|
-
export { id } from "./id.js"
|
|
10
|
-
export { ensNormalize, isValidName, namehash, dnsEncode } from "./namehash.js";
|
|
11
|
-
export { hashMessage, verifyMessage } from "./message.js";
|
|
12
|
-
export {
|
|
13
|
-
solidityPacked, solidityPackedKeccak256, solidityPackedSha256
|
|
14
|
-
} from "./solidity.js";
|
|
15
|
-
export { TypedDataEncoder, verifyTypedData } from "./typed-data.js";
|
|
16
|
-
|
|
17
|
-
export type { AuthorizationRequest } from "./authorization.js";
|
|
18
|
-
export type { TypedDataDomain, TypedDataField } from "./typed-data.js";
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for common tasks involving hashing. Also see
|
|
3
|
+
* [cryptographic hashing](about-crypto-hashing).
|
|
4
|
+
*
|
|
5
|
+
* @_section: api/hashing:Hashing Utilities [about-hashing]
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export { hashAuthorization, verifyAuthorization } from "./authorization.js";
|
|
9
|
+
export { id } from "./id.js"
|
|
10
|
+
export { ensNormalize, isValidName, namehash, dnsEncode } from "./namehash.js";
|
|
11
|
+
export { hashMessage, verifyMessage } from "./message.js";
|
|
12
|
+
export {
|
|
13
|
+
solidityPacked, solidityPackedKeccak256, solidityPackedSha256
|
|
14
|
+
} from "./solidity.js";
|
|
15
|
+
export { TypedDataEncoder, verifyTypedData } from "./typed-data.js";
|
|
16
|
+
|
|
17
|
+
export type { AuthorizationRequest } from "./authorization.js";
|
|
18
|
+
export type { TypedDataDomain, TypedDataField } from "./typed-data.js";
|
package/src.ts/hash/message.ts
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
import { keccak256 } from "../crypto/index.js";
|
|
2
|
-
import { MessagePrefix } from "../constants/index.js";
|
|
3
|
-
import { recoverAddress } from "../transaction/index.js";
|
|
4
|
-
import { concat, toUtf8Bytes } from "../utils/index.js";
|
|
5
|
-
|
|
6
|
-
import type { SignatureLike } from "../crypto/index.js";
|
|
7
|
-
/**
|
|
8
|
-
* Computes the [[link-eip-191]] personal-sign message digest to sign.
|
|
9
|
-
*
|
|
10
|
-
* This prefixes the message with [[MessagePrefix]] and the decimal length
|
|
11
|
-
* of %%message%% and computes the [[keccak256]] digest.
|
|
12
|
-
*
|
|
13
|
-
* If %%message%% is a string, it is converted to its UTF-8 bytes
|
|
14
|
-
* first. To compute the digest of a [[DataHexString]], it must be converted
|
|
15
|
-
* to [bytes](getBytes).
|
|
16
|
-
*
|
|
17
|
-
* @example:
|
|
18
|
-
* hashMessage("Hello World")
|
|
19
|
-
* //_result:
|
|
20
|
-
*
|
|
21
|
-
* // Hashes the SIX (6) string characters, i.e.
|
|
22
|
-
* // [ "0", "x", "4", "2", "4", "3" ]
|
|
23
|
-
* hashMessage("0x4243")
|
|
24
|
-
* //_result:
|
|
25
|
-
*
|
|
26
|
-
* // Hashes the TWO (2) bytes [ 0x42, 0x43 ]...
|
|
27
|
-
* hashMessage(getBytes("0x4243"))
|
|
28
|
-
* //_result:
|
|
29
|
-
*
|
|
30
|
-
* // ...which is equal to using data
|
|
31
|
-
* hashMessage(new Uint8Array([ 0x42, 0x43 ]))
|
|
32
|
-
* //_result:
|
|
33
|
-
*
|
|
34
|
-
*/
|
|
35
|
-
export function hashMessage(message: Uint8Array | string): string {
|
|
36
|
-
if (typeof(message) === "string") { message = toUtf8Bytes(message); }
|
|
37
|
-
return keccak256(concat([
|
|
38
|
-
toUtf8Bytes(MessagePrefix),
|
|
39
|
-
toUtf8Bytes(String(message.length)),
|
|
40
|
-
message
|
|
41
|
-
]));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Return the address of the private key that produced
|
|
46
|
-
* the signature %%sig%% during signing for %%message%%.
|
|
47
|
-
*/
|
|
48
|
-
export function verifyMessage(message: Uint8Array | string, sig: SignatureLike): string {
|
|
49
|
-
const digest = hashMessage(message);
|
|
50
|
-
return recoverAddress(digest, sig);
|
|
51
|
-
}
|
|
1
|
+
import { keccak256 } from "../crypto/index.js";
|
|
2
|
+
import { MessagePrefix } from "../constants/index.js";
|
|
3
|
+
import { recoverAddress } from "../transaction/index.js";
|
|
4
|
+
import { concat, toUtf8Bytes } from "../utils/index.js";
|
|
5
|
+
|
|
6
|
+
import type { SignatureLike } from "../crypto/index.js";
|
|
7
|
+
/**
|
|
8
|
+
* Computes the [[link-eip-191]] personal-sign message digest to sign.
|
|
9
|
+
*
|
|
10
|
+
* This prefixes the message with [[MessagePrefix]] and the decimal length
|
|
11
|
+
* of %%message%% and computes the [[keccak256]] digest.
|
|
12
|
+
*
|
|
13
|
+
* If %%message%% is a string, it is converted to its UTF-8 bytes
|
|
14
|
+
* first. To compute the digest of a [[DataHexString]], it must be converted
|
|
15
|
+
* to [bytes](getBytes).
|
|
16
|
+
*
|
|
17
|
+
* @example:
|
|
18
|
+
* hashMessage("Hello World")
|
|
19
|
+
* //_result:
|
|
20
|
+
*
|
|
21
|
+
* // Hashes the SIX (6) string characters, i.e.
|
|
22
|
+
* // [ "0", "x", "4", "2", "4", "3" ]
|
|
23
|
+
* hashMessage("0x4243")
|
|
24
|
+
* //_result:
|
|
25
|
+
*
|
|
26
|
+
* // Hashes the TWO (2) bytes [ 0x42, 0x43 ]...
|
|
27
|
+
* hashMessage(getBytes("0x4243"))
|
|
28
|
+
* //_result:
|
|
29
|
+
*
|
|
30
|
+
* // ...which is equal to using data
|
|
31
|
+
* hashMessage(new Uint8Array([ 0x42, 0x43 ]))
|
|
32
|
+
* //_result:
|
|
33
|
+
*
|
|
34
|
+
*/
|
|
35
|
+
export function hashMessage(message: Uint8Array | string): string {
|
|
36
|
+
if (typeof(message) === "string") { message = toUtf8Bytes(message); }
|
|
37
|
+
return keccak256(concat([
|
|
38
|
+
toUtf8Bytes(MessagePrefix),
|
|
39
|
+
toUtf8Bytes(String(message.length)),
|
|
40
|
+
message
|
|
41
|
+
]));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Return the address of the private key that produced
|
|
46
|
+
* the signature %%sig%% during signing for %%message%%.
|
|
47
|
+
*/
|
|
48
|
+
export function verifyMessage(message: Uint8Array | string, sig: SignatureLike): string {
|
|
49
|
+
const digest = hashMessage(message);
|
|
50
|
+
return recoverAddress(digest, sig);
|
|
51
|
+
}
|