@bsv/sdk 2.1.0 → 2.1.2
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/README.md +7 -7
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/src/auth/Peer.js +8 -13
- package/dist/cjs/src/auth/Peer.js.map +1 -1
- package/dist/cjs/src/auth/SessionManager.js +4 -7
- package/dist/cjs/src/auth/SessionManager.js.map +1 -1
- package/dist/cjs/src/auth/certificates/MasterCertificate.js +1 -1
- package/dist/cjs/src/auth/certificates/MasterCertificate.js.map +1 -1
- package/dist/cjs/src/auth/certificates/__tests/CompletedProtoWallet.js +1 -1
- package/dist/cjs/src/auth/certificates/__tests/CompletedProtoWallet.js.map +1 -1
- package/dist/cjs/src/auth/clients/AuthFetch.js +32 -32
- package/dist/cjs/src/auth/clients/AuthFetch.js.map +1 -1
- package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js +4 -4
- package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
- package/dist/cjs/src/compat/ECIES.js +29 -34
- package/dist/cjs/src/compat/ECIES.js.map +1 -1
- package/dist/cjs/src/compat/HD.js +9 -4
- package/dist/cjs/src/compat/HD.js.map +1 -1
- package/dist/cjs/src/compat/Mnemonic.js +12 -12
- package/dist/cjs/src/compat/Mnemonic.js.map +1 -1
- package/dist/cjs/src/identity/ContactsManager.js +212 -234
- package/dist/cjs/src/identity/ContactsManager.js.map +1 -1
- package/dist/cjs/src/identity/IdentityClient.js +199 -63
- package/dist/cjs/src/identity/IdentityClient.js.map +1 -1
- package/dist/cjs/src/kvstore/GlobalKVStore.js +30 -31
- package/dist/cjs/src/kvstore/GlobalKVStore.js.map +1 -1
- package/dist/cjs/src/kvstore/LocalKVStore.js +9 -9
- package/dist/cjs/src/kvstore/LocalKVStore.js.map +1 -1
- package/dist/cjs/src/kvstore/kvStoreInterpreter.js +2 -2
- package/dist/cjs/src/kvstore/kvStoreInterpreter.js.map +1 -1
- package/dist/cjs/src/messages/SignedMessage.js +1 -1
- package/dist/cjs/src/messages/SignedMessage.js.map +1 -1
- package/dist/cjs/src/overlay-tools/Historian.js +1 -1
- package/dist/cjs/src/overlay-tools/Historian.js.map +1 -1
- package/dist/cjs/src/overlay-tools/LookupResolver.js +213 -93
- package/dist/cjs/src/overlay-tools/LookupResolver.js.map +1 -1
- package/dist/cjs/src/overlay-tools/SHIPBroadcaster.js +75 -146
- package/dist/cjs/src/overlay-tools/SHIPBroadcaster.js.map +1 -1
- package/dist/cjs/src/primitives/AESGCM.js +2 -2
- package/dist/cjs/src/primitives/AESGCM.js.map +1 -1
- package/dist/cjs/src/primitives/BigNumber.js +164 -148
- package/dist/cjs/src/primitives/BigNumber.js.map +1 -1
- package/dist/cjs/src/primitives/Curve.js +17 -15
- package/dist/cjs/src/primitives/Curve.js.map +1 -1
- package/dist/cjs/src/primitives/ECDSA.js +12 -7
- package/dist/cjs/src/primitives/ECDSA.js.map +1 -1
- package/dist/cjs/src/primitives/Hash.js +312 -105
- package/dist/cjs/src/primitives/Hash.js.map +1 -1
- package/dist/cjs/src/primitives/JacobianPoint.js +8 -8
- package/dist/cjs/src/primitives/JacobianPoint.js.map +1 -1
- package/dist/cjs/src/primitives/K256.js +3 -3
- package/dist/cjs/src/primitives/K256.js.map +1 -1
- package/dist/cjs/src/primitives/Point.js +36 -40
- package/dist/cjs/src/primitives/Point.js.map +1 -1
- package/dist/cjs/src/primitives/PrivateKey.js +4 -4
- package/dist/cjs/src/primitives/PrivateKey.js.map +1 -1
- package/dist/cjs/src/primitives/PublicKey.js +4 -4
- package/dist/cjs/src/primitives/PublicKey.js.map +1 -1
- package/dist/cjs/src/primitives/Random.js +10 -14
- package/dist/cjs/src/primitives/Random.js.map +1 -1
- package/dist/cjs/src/primitives/ReaderUint8Array.js +6 -6
- package/dist/cjs/src/primitives/ReaderUint8Array.js.map +1 -1
- package/dist/cjs/src/primitives/Schnorr.js +2 -2
- package/dist/cjs/src/primitives/Schnorr.js.map +1 -1
- package/dist/cjs/src/primitives/Secp256r1.js +2 -1
- package/dist/cjs/src/primitives/Secp256r1.js.map +1 -1
- package/dist/cjs/src/primitives/Signature.js +8 -8
- package/dist/cjs/src/primitives/Signature.js.map +1 -1
- package/dist/cjs/src/primitives/SymmetricKey.js +123 -1
- package/dist/cjs/src/primitives/SymmetricKey.js.map +1 -1
- package/dist/cjs/src/primitives/TransactionSignature.js +20 -21
- package/dist/cjs/src/primitives/TransactionSignature.js.map +1 -1
- package/dist/cjs/src/primitives/utils.js +39 -46
- package/dist/cjs/src/primitives/utils.js.map +1 -1
- package/dist/cjs/src/registry/RegistryClient.js +31 -23
- package/dist/cjs/src/registry/RegistryClient.js.map +1 -1
- package/dist/cjs/src/remittance/RemittanceManager.js +19 -18
- package/dist/cjs/src/remittance/RemittanceManager.js.map +1 -1
- package/dist/cjs/src/remittance/modules/BasicBRC29.js.map +1 -1
- package/dist/cjs/src/script/Script.js +93 -170
- package/dist/cjs/src/script/Script.js.map +1 -1
- package/dist/cjs/src/script/ScriptEvaluationError.js +2 -2
- package/dist/cjs/src/script/ScriptEvaluationError.js.map +1 -1
- package/dist/cjs/src/script/Spend.js +14 -12
- package/dist/cjs/src/script/Spend.js.map +1 -1
- package/dist/cjs/src/script/templates/PushDrop.js +22 -18
- package/dist/cjs/src/script/templates/PushDrop.js.map +1 -1
- package/dist/cjs/src/script/templates/RPuzzle.js +2 -4
- package/dist/cjs/src/script/templates/RPuzzle.js.map +1 -1
- package/dist/cjs/src/storage/StorageDownloader.js +42 -9
- package/dist/cjs/src/storage/StorageDownloader.js.map +1 -1
- package/dist/cjs/src/totp/totp.js +1 -1
- package/dist/cjs/src/totp/totp.js.map +1 -1
- package/dist/cjs/src/transaction/Beef.js +239 -192
- package/dist/cjs/src/transaction/Beef.js.map +1 -1
- package/dist/cjs/src/transaction/BeefConstants.js +19 -0
- package/dist/cjs/src/transaction/BeefConstants.js.map +1 -0
- package/dist/cjs/src/transaction/BeefTx.js +12 -12
- package/dist/cjs/src/transaction/BeefTx.js.map +1 -1
- package/dist/cjs/src/transaction/MerklePath.js +4 -4
- package/dist/cjs/src/transaction/MerklePath.js.map +1 -1
- package/dist/cjs/src/transaction/Transaction.js +49 -52
- package/dist/cjs/src/transaction/Transaction.js.map +1 -1
- package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js +1 -1
- package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -1
- package/dist/cjs/src/transaction/http/BinaryFetchClient.js +9 -9
- package/dist/cjs/src/transaction/http/BinaryFetchClient.js.map +1 -1
- package/dist/cjs/src/transaction/http/DefaultHttpClient.js +9 -9
- package/dist/cjs/src/transaction/http/DefaultHttpClient.js.map +1 -1
- package/dist/cjs/src/wallet/CachedKeyDeriver.js +1 -1
- package/dist/cjs/src/wallet/CachedKeyDeriver.js.map +1 -1
- package/dist/cjs/src/wallet/WalletClient.js.map +1 -1
- package/dist/cjs/src/wallet/WalletError.js.map +1 -1
- package/dist/cjs/src/wallet/substrates/HTTPWalletJSON.js +5 -4
- package/dist/cjs/src/wallet/substrates/HTTPWalletJSON.js.map +1 -1
- package/dist/cjs/src/wallet/substrates/ReactNativeWebView.js +9 -9
- package/dist/cjs/src/wallet/substrates/ReactNativeWebView.js.map +1 -1
- package/dist/cjs/src/wallet/substrates/WalletWireProcessor.js +92 -92
- package/dist/cjs/src/wallet/substrates/WalletWireProcessor.js.map +1 -1
- package/dist/cjs/src/wallet/substrates/WalletWireTransceiver.js +387 -711
- package/dist/cjs/src/wallet/substrates/WalletWireTransceiver.js.map +1 -1
- package/dist/cjs/src/wallet/substrates/XDM.js +4 -4
- package/dist/cjs/src/wallet/substrates/XDM.js.map +1 -1
- package/dist/cjs/src/wallet/substrates/window.CWI.js +2 -2
- package/dist/cjs/src/wallet/substrates/window.CWI.js.map +1 -1
- package/dist/cjs/src/wallet/validationHelpers.js +9 -9
- package/dist/cjs/src/wallet/validationHelpers.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/auth/Peer.js +25 -13
- package/dist/esm/src/auth/Peer.js.map +1 -1
- package/dist/esm/src/auth/SessionManager.js +4 -7
- package/dist/esm/src/auth/SessionManager.js.map +1 -1
- package/dist/esm/src/auth/certificates/MasterCertificate.js +1 -1
- package/dist/esm/src/auth/certificates/MasterCertificate.js.map +1 -1
- package/dist/esm/src/auth/certificates/__tests/CompletedProtoWallet.js +1 -1
- package/dist/esm/src/auth/certificates/__tests/CompletedProtoWallet.js.map +1 -1
- package/dist/esm/src/auth/clients/AuthFetch.js +32 -32
- package/dist/esm/src/auth/clients/AuthFetch.js.map +1 -1
- package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js +4 -4
- package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
- package/dist/esm/src/compat/ECIES.js +29 -34
- package/dist/esm/src/compat/ECIES.js.map +1 -1
- package/dist/esm/src/compat/HD.js +9 -4
- package/dist/esm/src/compat/HD.js.map +1 -1
- package/dist/esm/src/compat/Mnemonic.js +12 -12
- package/dist/esm/src/compat/Mnemonic.js.map +1 -1
- package/dist/esm/src/identity/ContactsManager.js +212 -234
- package/dist/esm/src/identity/ContactsManager.js.map +1 -1
- package/dist/esm/src/identity/IdentityClient.js +199 -63
- package/dist/esm/src/identity/IdentityClient.js.map +1 -1
- package/dist/esm/src/kvstore/GlobalKVStore.js +30 -31
- package/dist/esm/src/kvstore/GlobalKVStore.js.map +1 -1
- package/dist/esm/src/kvstore/LocalKVStore.js +9 -9
- package/dist/esm/src/kvstore/LocalKVStore.js.map +1 -1
- package/dist/esm/src/kvstore/kvStoreInterpreter.js +2 -2
- package/dist/esm/src/kvstore/kvStoreInterpreter.js.map +1 -1
- package/dist/esm/src/messages/SignedMessage.js +1 -1
- package/dist/esm/src/messages/SignedMessage.js.map +1 -1
- package/dist/esm/src/overlay-tools/Historian.js +1 -1
- package/dist/esm/src/overlay-tools/Historian.js.map +1 -1
- package/dist/esm/src/overlay-tools/LookupResolver.js +213 -93
- package/dist/esm/src/overlay-tools/LookupResolver.js.map +1 -1
- package/dist/esm/src/overlay-tools/SHIPBroadcaster.js +74 -146
- package/dist/esm/src/overlay-tools/SHIPBroadcaster.js.map +1 -1
- package/dist/esm/src/primitives/AESGCM.js +2 -2
- package/dist/esm/src/primitives/AESGCM.js.map +1 -1
- package/dist/esm/src/primitives/BigNumber.js +167 -154
- package/dist/esm/src/primitives/BigNumber.js.map +1 -1
- package/dist/esm/src/primitives/Curve.js +17 -15
- package/dist/esm/src/primitives/Curve.js.map +1 -1
- package/dist/esm/src/primitives/ECDSA.js +12 -7
- package/dist/esm/src/primitives/ECDSA.js.map +1 -1
- package/dist/esm/src/primitives/Hash.js +316 -105
- package/dist/esm/src/primitives/Hash.js.map +1 -1
- package/dist/esm/src/primitives/JacobianPoint.js +8 -8
- package/dist/esm/src/primitives/JacobianPoint.js.map +1 -1
- package/dist/esm/src/primitives/K256.js +3 -3
- package/dist/esm/src/primitives/K256.js.map +1 -1
- package/dist/esm/src/primitives/Point.js +36 -40
- package/dist/esm/src/primitives/Point.js.map +1 -1
- package/dist/esm/src/primitives/PrivateKey.js +4 -4
- package/dist/esm/src/primitives/PrivateKey.js.map +1 -1
- package/dist/esm/src/primitives/PublicKey.js +4 -4
- package/dist/esm/src/primitives/PublicKey.js.map +1 -1
- package/dist/esm/src/primitives/Random.js +10 -14
- package/dist/esm/src/primitives/Random.js.map +1 -1
- package/dist/esm/src/primitives/ReaderUint8Array.js +6 -6
- package/dist/esm/src/primitives/ReaderUint8Array.js.map +1 -1
- package/dist/esm/src/primitives/Schnorr.js +1 -1
- package/dist/esm/src/primitives/Schnorr.js.map +1 -1
- package/dist/esm/src/primitives/Secp256r1.js +2 -1
- package/dist/esm/src/primitives/Secp256r1.js.map +1 -1
- package/dist/esm/src/primitives/Signature.js +8 -8
- package/dist/esm/src/primitives/Signature.js.map +1 -1
- package/dist/esm/src/primitives/SymmetricKey.js +123 -1
- package/dist/esm/src/primitives/SymmetricKey.js.map +1 -1
- package/dist/esm/src/primitives/TransactionSignature.js +20 -21
- package/dist/esm/src/primitives/TransactionSignature.js.map +1 -1
- package/dist/esm/src/primitives/utils.js +39 -48
- package/dist/esm/src/primitives/utils.js.map +1 -1
- package/dist/esm/src/registry/RegistryClient.js +31 -23
- package/dist/esm/src/registry/RegistryClient.js.map +1 -1
- package/dist/esm/src/remittance/RemittanceManager.js +19 -18
- package/dist/esm/src/remittance/RemittanceManager.js.map +1 -1
- package/dist/esm/src/remittance/modules/BasicBRC29.js.map +1 -1
- package/dist/esm/src/script/Script.js +93 -170
- package/dist/esm/src/script/Script.js.map +1 -1
- package/dist/esm/src/script/ScriptEvaluationError.js +2 -2
- package/dist/esm/src/script/ScriptEvaluationError.js.map +1 -1
- package/dist/esm/src/script/Spend.js +14 -12
- package/dist/esm/src/script/Spend.js.map +1 -1
- package/dist/esm/src/script/templates/PushDrop.js +4 -3
- package/dist/esm/src/script/templates/PushDrop.js.map +1 -1
- package/dist/esm/src/script/templates/RPuzzle.js +2 -4
- package/dist/esm/src/script/templates/RPuzzle.js.map +1 -1
- package/dist/esm/src/storage/StorageDownloader.js +1 -1
- package/dist/esm/src/storage/StorageDownloader.js.map +1 -1
- package/dist/esm/src/totp/totp.js +1 -1
- package/dist/esm/src/totp/totp.js.map +1 -1
- package/dist/esm/src/transaction/Beef.js +229 -186
- package/dist/esm/src/transaction/Beef.js.map +1 -1
- package/dist/esm/src/transaction/BeefConstants.js +16 -0
- package/dist/esm/src/transaction/BeefConstants.js.map +1 -0
- package/dist/esm/src/transaction/BeefTx.js +3 -3
- package/dist/esm/src/transaction/BeefTx.js.map +1 -1
- package/dist/esm/src/transaction/MerklePath.js +4 -4
- package/dist/esm/src/transaction/MerklePath.js.map +1 -1
- package/dist/esm/src/transaction/Transaction.js +49 -52
- package/dist/esm/src/transaction/Transaction.js.map +1 -1
- package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js +1 -1
- package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -1
- package/dist/esm/src/transaction/http/BinaryFetchClient.js +9 -9
- package/dist/esm/src/transaction/http/BinaryFetchClient.js.map +1 -1
- package/dist/esm/src/transaction/http/DefaultHttpClient.js +9 -9
- package/dist/esm/src/transaction/http/DefaultHttpClient.js.map +1 -1
- package/dist/esm/src/wallet/CachedKeyDeriver.js +1 -1
- package/dist/esm/src/wallet/CachedKeyDeriver.js.map +1 -1
- package/dist/esm/src/wallet/WalletClient.js.map +1 -1
- package/dist/esm/src/wallet/WalletError.js.map +1 -1
- package/dist/esm/src/wallet/substrates/HTTPWalletJSON.js +5 -4
- package/dist/esm/src/wallet/substrates/HTTPWalletJSON.js.map +1 -1
- package/dist/esm/src/wallet/substrates/ReactNativeWebView.js +9 -9
- package/dist/esm/src/wallet/substrates/ReactNativeWebView.js.map +1 -1
- package/dist/esm/src/wallet/substrates/WalletWireProcessor.js +92 -92
- package/dist/esm/src/wallet/substrates/WalletWireProcessor.js.map +1 -1
- package/dist/esm/src/wallet/substrates/WalletWireTransceiver.js +387 -711
- package/dist/esm/src/wallet/substrates/WalletWireTransceiver.js.map +1 -1
- package/dist/esm/src/wallet/substrates/XDM.js +4 -4
- package/dist/esm/src/wallet/substrates/XDM.js.map +1 -1
- package/dist/esm/src/wallet/substrates/window.CWI.js +2 -2
- package/dist/esm/src/wallet/substrates/window.CWI.js.map +1 -1
- package/dist/esm/src/wallet/validationHelpers.js +9 -9
- package/dist/esm/src/wallet/validationHelpers.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/auth/Peer.d.ts +13 -0
- package/dist/types/src/auth/Peer.d.ts.map +1 -1
- package/dist/types/src/auth/SessionManager.d.ts.map +1 -1
- package/dist/types/src/auth/clients/AuthFetch.d.ts.map +1 -1
- package/dist/types/src/compat/ECIES.d.ts.map +1 -1
- package/dist/types/src/compat/HD.d.ts.map +1 -1
- package/dist/types/src/identity/ContactsManager.d.ts +31 -2
- package/dist/types/src/identity/ContactsManager.d.ts.map +1 -1
- package/dist/types/src/identity/IdentityClient.d.ts +75 -10
- package/dist/types/src/identity/IdentityClient.d.ts.map +1 -1
- package/dist/types/src/kvstore/GlobalKVStore.d.ts.map +1 -1
- package/dist/types/src/overlay-tools/LookupResolver.d.ts +73 -2
- package/dist/types/src/overlay-tools/LookupResolver.d.ts.map +1 -1
- package/dist/types/src/overlay-tools/SHIPBroadcaster.d.ts +18 -3
- package/dist/types/src/overlay-tools/SHIPBroadcaster.d.ts.map +1 -1
- package/dist/types/src/primitives/BigNumber.d.ts +13 -3
- package/dist/types/src/primitives/BigNumber.d.ts.map +1 -1
- package/dist/types/src/primitives/Curve.d.ts.map +1 -1
- package/dist/types/src/primitives/ECDSA.d.ts.map +1 -1
- package/dist/types/src/primitives/Hash.d.ts +22 -17
- package/dist/types/src/primitives/Hash.d.ts.map +1 -1
- package/dist/types/src/primitives/JacobianPoint.d.ts +3 -1
- package/dist/types/src/primitives/JacobianPoint.d.ts.map +1 -1
- package/dist/types/src/primitives/Point.d.ts.map +1 -1
- package/dist/types/src/primitives/Random.d.ts +2 -2
- package/dist/types/src/primitives/Random.d.ts.map +1 -1
- package/dist/types/src/primitives/ReaderUint8Array.d.ts.map +1 -1
- package/dist/types/src/primitives/Schnorr.d.ts +2 -1
- package/dist/types/src/primitives/Schnorr.d.ts.map +1 -1
- package/dist/types/src/primitives/Secp256r1.d.ts.map +1 -1
- package/dist/types/src/primitives/SymmetricKey.d.ts.map +1 -1
- package/dist/types/src/primitives/utils.d.ts +2 -4
- package/dist/types/src/primitives/utils.d.ts.map +1 -1
- package/dist/types/src/registry/RegistryClient.d.ts.map +1 -1
- package/dist/types/src/remittance/RemittanceManager.d.ts.map +1 -1
- package/dist/types/src/remittance/modules/BasicBRC29.d.ts.map +1 -1
- package/dist/types/src/script/Script.d.ts +15 -8
- package/dist/types/src/script/Script.d.ts.map +1 -1
- package/dist/types/src/script/Spend.d.ts.map +1 -1
- package/dist/types/src/script/templates/PushDrop.d.ts +3 -1
- package/dist/types/src/script/templates/PushDrop.d.ts.map +1 -1
- package/dist/types/src/script/templates/RPuzzle.d.ts.map +1 -1
- package/dist/types/src/transaction/Beef.d.ts +46 -8
- package/dist/types/src/transaction/Beef.d.ts.map +1 -1
- package/dist/types/src/transaction/BeefConstants.d.ts +15 -0
- package/dist/types/src/transaction/BeefConstants.d.ts.map +1 -0
- package/dist/types/src/transaction/Transaction.d.ts.map +1 -1
- package/dist/types/src/wallet/CachedKeyDeriver.d.ts.map +1 -1
- package/dist/types/src/wallet/KeyDeriver.d.ts +1 -1
- package/dist/types/src/wallet/KeyDeriver.d.ts.map +1 -1
- package/dist/types/src/wallet/Wallet.interfaces.d.ts +18 -3
- package/dist/types/src/wallet/Wallet.interfaces.d.ts.map +1 -1
- package/dist/types/src/wallet/WalletClient.d.ts +8 -8
- package/dist/types/src/wallet/WalletClient.d.ts.map +1 -1
- package/dist/types/src/wallet/substrates/HTTPWalletJSON.d.ts +7 -7
- package/dist/types/src/wallet/substrates/HTTPWalletJSON.d.ts.map +1 -1
- package/dist/types/src/wallet/substrates/WalletWireTransceiver.d.ts +36 -7
- package/dist/types/src/wallet/substrates/WalletWireTransceiver.d.ts.map +1 -1
- package/dist/types/src/wallet/substrates/window.CWI.d.ts +9 -9
- package/dist/types/src/wallet/substrates/window.CWI.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +3 -3
- package/package.json +1 -1
- package/src/auth/Peer.ts +26 -13
- package/src/auth/SessionManager.ts +4 -7
- package/src/auth/certificates/MasterCertificate.ts +1 -1
- package/src/auth/certificates/__tests/CompletedProtoWallet.ts +1 -1
- package/src/auth/clients/AuthFetch.ts +41 -41
- package/src/auth/transports/SimplifiedFetchTransport.ts +4 -4
- package/src/compat/ECIES.ts +29 -34
- package/src/compat/HD.ts +10 -5
- package/src/compat/Mnemonic.ts +11 -11
- package/src/compat/__tests/HD.test.ts +19 -0
- package/src/identity/ContactsManager.ts +236 -258
- package/src/identity/IdentityClient.ts +244 -71
- package/src/identity/__tests/IdentityClient.additional.test.ts +150 -1
- package/src/identity/__tests/IdentityClient.test.ts +27 -3
- package/src/kvstore/GlobalKVStore.ts +31 -32
- package/src/kvstore/LocalKVStore.ts +8 -8
- package/src/kvstore/kvStoreInterpreter.ts +2 -2
- package/src/messages/SignedMessage.ts +1 -1
- package/src/overlay-tools/Historian.ts +1 -1
- package/src/overlay-tools/LookupResolver.ts +264 -90
- package/src/overlay-tools/SHIPBroadcaster.ts +92 -168
- package/src/primitives/AESGCM.ts +2 -2
- package/src/primitives/BigNumber.ts +122 -113
- package/src/primitives/Curve.ts +16 -15
- package/src/primitives/ECDSA.ts +10 -8
- package/src/primitives/Hash.ts +381 -146
- package/src/primitives/JacobianPoint.ts +13 -11
- package/src/primitives/K256.ts +3 -3
- package/src/primitives/Point.ts +35 -38
- package/src/primitives/PrivateKey.ts +3 -3
- package/src/primitives/PublicKey.ts +3 -3
- package/src/primitives/Random.ts +11 -14
- package/src/primitives/ReaderUint8Array.ts +7 -7
- package/src/primitives/Schnorr.ts +2 -1
- package/src/primitives/Secp256r1.ts +2 -1
- package/src/primitives/Signature.ts +8 -8
- package/src/primitives/SymmetricKey.ts +145 -1
- package/src/primitives/TransactionSignature.ts +16 -16
- package/src/primitives/__tests/Hash.additional.test.ts +65 -0
- package/src/primitives/__tests/Hash.test.ts +6 -1
- package/src/primitives/utils.ts +37 -47
- package/src/registry/RegistryClient.ts +25 -25
- package/src/remittance/RemittanceManager.ts +17 -18
- package/src/remittance/modules/BasicBRC29.ts +2 -5
- package/src/script/Script.ts +114 -170
- package/src/script/ScriptEvaluationError.ts +2 -2
- package/src/script/Spend.ts +14 -15
- package/src/script/templates/PushDrop.ts +5 -3
- package/src/script/templates/RPuzzle.ts +2 -4
- package/src/storage/StorageDownloader.ts +1 -1
- package/src/totp/totp.ts +1 -1
- package/src/transaction/Beef.ts +241 -203
- package/src/transaction/BeefConstants.ts +16 -0
- package/src/transaction/BeefTx.ts +3 -3
- package/src/transaction/MerklePath.ts +4 -4
- package/src/transaction/Transaction.ts +48 -51
- package/src/transaction/fee-models/SatoshisPerKilobyte.ts +1 -1
- package/src/transaction/http/BinaryFetchClient.ts +8 -8
- package/src/transaction/http/DefaultHttpClient.ts +8 -8
- package/src/wallet/CachedKeyDeriver.ts +8 -6
- package/src/wallet/KeyDeriver.ts +1 -1
- package/src/wallet/Wallet.interfaces.ts +18 -5
- package/src/wallet/WalletClient.ts +9 -9
- package/src/wallet/WalletError.ts +1 -1
- package/src/wallet/__tests/WalletClient.substrate.test.ts +10 -6
- package/src/wallet/substrates/HTTPWalletJSON.ts +22 -21
- package/src/wallet/substrates/ReactNativeWebView.ts +9 -9
- package/src/wallet/substrates/WalletWireProcessor.ts +83 -83
- package/src/wallet/substrates/WalletWireTransceiver.ts +528 -938
- package/src/wallet/substrates/XDM.ts +4 -4
- package/src/wallet/substrates/__tests/HTTPWalletJSON.test.ts +38 -25
- package/src/wallet/substrates/__tests/ReactNativeWebView.test.ts +174 -0
- package/src/wallet/substrates/__tests/window.CWI.test.ts +256 -0
- package/src/wallet/substrates/window.CWI.ts +11 -11
- package/src/wallet/validationHelpers.ts +9 -9
|
@@ -190,6 +190,59 @@ function isSurrogatePair(msg, i) {
|
|
|
190
190
|
}
|
|
191
191
|
return (msg.charCodeAt(i + 1) & 0xfc00) === 0xdc00;
|
|
192
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Encode a single UTF-16 code unit (and possibly its surrogate partner)
|
|
195
|
+
* into UTF-8 bytes, appending them to `out`.
|
|
196
|
+
*
|
|
197
|
+
* Returns the index of the last consumed code unit so the caller can
|
|
198
|
+
* advance its loop variable when a surrogate pair is consumed.
|
|
199
|
+
*
|
|
200
|
+
* Inspired by stringToUtf8ByteArray() in closure-library by Google
|
|
201
|
+
* https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt#L117-L143
|
|
202
|
+
* Apache License 2.0
|
|
203
|
+
* https://github.com/google/closure-library/blob/master/LICENSE
|
|
204
|
+
*/
|
|
205
|
+
function appendUtf8CodeUnit(msg, i, out) {
|
|
206
|
+
let c = msg.charCodeAt(i);
|
|
207
|
+
if (c < 128) {
|
|
208
|
+
out.push(c);
|
|
209
|
+
return i;
|
|
210
|
+
}
|
|
211
|
+
if (c < 2048) {
|
|
212
|
+
out.push((c >> 6) | 192, (c & 63) | 128);
|
|
213
|
+
return i;
|
|
214
|
+
}
|
|
215
|
+
if (isSurrogatePair(msg, i)) {
|
|
216
|
+
c = 0x10000 + ((c & 0x03ff) << 10) + (msg.charCodeAt(i + 1) & 0x03ff);
|
|
217
|
+
out.push((c >> 18) | 240, ((c >> 12) & 63) | 128, ((c >> 6) & 63) | 128, (c & 63) | 128);
|
|
218
|
+
return i + 1;
|
|
219
|
+
}
|
|
220
|
+
out.push((c >> 12) | 224, ((c >> 6) & 63) | 128, (c & 63) | 128);
|
|
221
|
+
return i;
|
|
222
|
+
}
|
|
223
|
+
function utf8StringToArray(msg) {
|
|
224
|
+
const res = [];
|
|
225
|
+
for (let i = 0; i < msg.length; i++) {
|
|
226
|
+
i = appendUtf8CodeUnit(msg, i, res);
|
|
227
|
+
}
|
|
228
|
+
return res;
|
|
229
|
+
}
|
|
230
|
+
function hexStringToArray(msg) {
|
|
231
|
+
(0, hex_js_1.assertValidHex)(msg);
|
|
232
|
+
const normalized = (0, hex_js_1.normalizeHex)(msg);
|
|
233
|
+
const res = [];
|
|
234
|
+
for (let i = 0; i < normalized.length; i += 2) {
|
|
235
|
+
res.push(Number.parseInt(normalized[i] + normalized[i + 1], 16));
|
|
236
|
+
}
|
|
237
|
+
return res;
|
|
238
|
+
}
|
|
239
|
+
function numberArrayToByteArray(msg) {
|
|
240
|
+
const res = [];
|
|
241
|
+
for (let i = 0; i < msg.length; i++) {
|
|
242
|
+
res[i] = Math.trunc(msg[i]);
|
|
243
|
+
}
|
|
244
|
+
return res;
|
|
245
|
+
}
|
|
193
246
|
/**
|
|
194
247
|
*
|
|
195
248
|
* @param msg
|
|
@@ -203,52 +256,10 @@ function toArray(msg, enc) {
|
|
|
203
256
|
if (!msg) {
|
|
204
257
|
return [];
|
|
205
258
|
}
|
|
206
|
-
const res = [];
|
|
207
259
|
if (typeof msg === 'string') {
|
|
208
|
-
|
|
209
|
-
// Inspired by stringToUtf8ByteArray() in closure-library by Google
|
|
210
|
-
// https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt#L117-L143
|
|
211
|
-
// Apache License 2.0
|
|
212
|
-
// https://github.com/google/closure-library/blob/master/LICENSE
|
|
213
|
-
let p = 0;
|
|
214
|
-
for (let i = 0; i < msg.length; i++) {
|
|
215
|
-
let c = msg.charCodeAt(i);
|
|
216
|
-
if (c < 128) {
|
|
217
|
-
res[p++] = c;
|
|
218
|
-
}
|
|
219
|
-
else if (c < 2048) {
|
|
220
|
-
res[p++] = (c >> 6) | 192;
|
|
221
|
-
res[p++] = (c & 63) | 128;
|
|
222
|
-
}
|
|
223
|
-
else if (isSurrogatePair(msg, i)) {
|
|
224
|
-
c = 0x10000 + ((c & 0x03ff) << 10) + (msg.charCodeAt(++i) & 0x03ff);
|
|
225
|
-
res[p++] = (c >> 18) | 240;
|
|
226
|
-
res[p++] = ((c >> 12) & 63) | 128;
|
|
227
|
-
res[p++] = ((c >> 6) & 63) | 128;
|
|
228
|
-
res[p++] = (c & 63) | 128;
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
res[p++] = (c >> 12) | 224;
|
|
232
|
-
res[p++] = ((c >> 6) & 63) | 128;
|
|
233
|
-
res[p++] = (c & 63) | 128;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
else {
|
|
238
|
-
(0, hex_js_1.assertValidHex)(msg);
|
|
239
|
-
msg = (0, hex_js_1.normalizeHex)(msg);
|
|
240
|
-
for (let i = 0; i < msg.length; i += 2) {
|
|
241
|
-
res.push(parseInt(msg[i] + msg[i + 1], 16));
|
|
242
|
-
}
|
|
243
|
-
}
|
|
260
|
+
return enc === 'hex' ? hexStringToArray(msg) : utf8StringToArray(msg);
|
|
244
261
|
}
|
|
245
|
-
|
|
246
|
-
msg = msg;
|
|
247
|
-
for (let i = 0; i < msg.length; i++) {
|
|
248
|
-
res[i] = msg[i] | 0;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
return res;
|
|
262
|
+
return numberArrayToByteArray(msg);
|
|
252
263
|
}
|
|
253
264
|
/**
|
|
254
265
|
* @deprecated
|
|
@@ -262,8 +273,7 @@ function htonl(w) {
|
|
|
262
273
|
}
|
|
263
274
|
function toHex32(msg, endian) {
|
|
264
275
|
let res = '';
|
|
265
|
-
for (let
|
|
266
|
-
let w = msg[i];
|
|
276
|
+
for (let w of msg) {
|
|
267
277
|
if (endian === 'little') {
|
|
268
278
|
w = htonl(w);
|
|
269
279
|
}
|
|
@@ -297,11 +307,115 @@ function zero8(word) {
|
|
|
297
307
|
return word;
|
|
298
308
|
}
|
|
299
309
|
}
|
|
310
|
+
const BufferCtor = typeof globalThis === 'undefined' ? undefined : globalThis.Buffer;
|
|
311
|
+
const CAN_USE_BUFFER = BufferCtor != null && typeof BufferCtor.from === 'function';
|
|
312
|
+
const HEX_DIGITS = '0123456789abcdef';
|
|
313
|
+
const HEX_BYTE_STRINGS = new Array(256);
|
|
314
|
+
for (let i = 0; i < HEX_BYTE_STRINGS.length; i++) {
|
|
315
|
+
HEX_BYTE_STRINGS[i] = HEX_DIGITS[(i >> 4) & 0xf] + HEX_DIGITS[i & 0xf];
|
|
316
|
+
}
|
|
300
317
|
function bytesToHex(data) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
318
|
+
if (CAN_USE_BUFFER) {
|
|
319
|
+
return BufferCtor.from(data).toString('hex');
|
|
320
|
+
}
|
|
321
|
+
const out = new Array(data.length);
|
|
322
|
+
for (let i = 0; i < data.length; i++)
|
|
323
|
+
out[i] = HEX_BYTE_STRINGS[data[i]];
|
|
324
|
+
return out.join('');
|
|
325
|
+
}
|
|
326
|
+
const NODE_CRYPTO = (() => {
|
|
327
|
+
const processLike = typeof globalThis === 'undefined' ? undefined : globalThis.process;
|
|
328
|
+
const getBuiltinModule = processLike?.getBuiltinModule;
|
|
329
|
+
if (typeof getBuiltinModule === 'function') {
|
|
330
|
+
try {
|
|
331
|
+
const crypto = getBuiltinModule.call(processLike, 'node:crypto');
|
|
332
|
+
if (crypto != null)
|
|
333
|
+
return crypto;
|
|
334
|
+
}
|
|
335
|
+
catch {
|
|
336
|
+
// continue to CommonJS fallback
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
try {
|
|
340
|
+
if (typeof require === 'function') {
|
|
341
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
342
|
+
return require('node:crypto');
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
catch {
|
|
346
|
+
// node:crypto is unavailable in this runtime
|
|
347
|
+
}
|
|
348
|
+
return undefined;
|
|
349
|
+
})();
|
|
350
|
+
function toHashBytes(msg, enc) {
|
|
351
|
+
if (msg instanceof Uint8Array) {
|
|
352
|
+
return msg;
|
|
353
|
+
}
|
|
354
|
+
if (Array.isArray(msg)) {
|
|
355
|
+
return new Uint8Array(msg);
|
|
356
|
+
}
|
|
357
|
+
return Uint8Array.from(toArray(msg, enc));
|
|
358
|
+
}
|
|
359
|
+
function toHashKeyBytes(key) {
|
|
360
|
+
return typeof key === 'string' ? toHashBytes(key, 'hex') : toHashBytes(key);
|
|
361
|
+
}
|
|
362
|
+
function updateNativeOrFallback(native, fallback, data) {
|
|
363
|
+
if (native != null) {
|
|
364
|
+
native.update(data);
|
|
365
|
+
}
|
|
366
|
+
else if (fallback != null) {
|
|
367
|
+
fallback.update(data);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
function digestNativeOrFallback(native, fallback) {
|
|
371
|
+
if (native != null)
|
|
372
|
+
return Array.from(native.digest());
|
|
373
|
+
if (fallback != null)
|
|
374
|
+
return Array.from(fallback.digest());
|
|
375
|
+
return [];
|
|
376
|
+
}
|
|
377
|
+
function digestHexNativeOrFallback(native, fallback) {
|
|
378
|
+
if (native != null)
|
|
379
|
+
return native.digest('hex');
|
|
380
|
+
if (fallback != null)
|
|
381
|
+
return bytesToHex(fallback.digest());
|
|
382
|
+
return '';
|
|
383
|
+
}
|
|
384
|
+
function createNodeHash(algorithm) {
|
|
385
|
+
const createHash = NODE_CRYPTO?.createHash;
|
|
386
|
+
if (typeof createHash !== 'function')
|
|
387
|
+
return undefined;
|
|
388
|
+
try {
|
|
389
|
+
return createHash(algorithm);
|
|
390
|
+
}
|
|
391
|
+
catch {
|
|
392
|
+
return undefined;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
function createNodeHmac(algorithm, keyBytes) {
|
|
396
|
+
const createHmac = NODE_CRYPTO?.createHmac;
|
|
397
|
+
if (typeof createHmac !== 'function')
|
|
398
|
+
return undefined;
|
|
399
|
+
try {
|
|
400
|
+
return createHmac(algorithm, keyBytes);
|
|
401
|
+
}
|
|
402
|
+
catch {
|
|
403
|
+
return undefined;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
function digestWithNodeHash(algorithm, msg, enc) {
|
|
407
|
+
const hash = createNodeHash(algorithm);
|
|
408
|
+
if (hash == null)
|
|
409
|
+
return undefined;
|
|
410
|
+
hash.update(toHashBytes(msg, enc));
|
|
411
|
+
return hash.digest();
|
|
412
|
+
}
|
|
413
|
+
function digestWithNodeHmac(algorithm, key, msg, enc) {
|
|
414
|
+
const hmac = createNodeHmac(algorithm, toHashKeyBytes(key));
|
|
415
|
+
if (hmac == null)
|
|
416
|
+
return undefined;
|
|
417
|
+
hmac.update(toHashBytes(msg, enc));
|
|
418
|
+
return hmac.digest();
|
|
305
419
|
}
|
|
306
420
|
function join32(msg, start, end, endian) {
|
|
307
421
|
const len = end - start;
|
|
@@ -550,18 +664,20 @@ exports.RIPEMD160 = RIPEMD160;
|
|
|
550
664
|
*/
|
|
551
665
|
class SHA256 {
|
|
552
666
|
constructor() {
|
|
553
|
-
this.
|
|
667
|
+
this.native = createNodeHash('sha256');
|
|
668
|
+
if (this.native == null) {
|
|
669
|
+
this.h = new FastSHA256();
|
|
670
|
+
}
|
|
554
671
|
}
|
|
555
672
|
update(msg, enc) {
|
|
556
|
-
|
|
557
|
-
this.h.update(data);
|
|
673
|
+
updateNativeOrFallback(this.native, this.h, toHashBytes(msg, enc));
|
|
558
674
|
return this;
|
|
559
675
|
}
|
|
560
676
|
digest() {
|
|
561
|
-
return
|
|
677
|
+
return digestNativeOrFallback(this.native, this.h);
|
|
562
678
|
}
|
|
563
679
|
digestHex() {
|
|
564
|
-
return
|
|
680
|
+
return digestHexNativeOrFallback(this.native, this.h);
|
|
565
681
|
}
|
|
566
682
|
}
|
|
567
683
|
exports.SHA256 = SHA256;
|
|
@@ -610,7 +726,7 @@ class SHA1 extends BaseHash {
|
|
|
610
726
|
let d = this.h[3];
|
|
611
727
|
let e = this.h[4];
|
|
612
728
|
for (i = 0; i < W.length; i++) {
|
|
613
|
-
const s =
|
|
729
|
+
const s = Math.trunc(i / 20);
|
|
614
730
|
const t = SUM32_5(rotl32(a, 5), FT_1(s, b, c, d), e, W[i], this.k[s]);
|
|
615
731
|
e = d;
|
|
616
732
|
d = c;
|
|
@@ -653,18 +769,20 @@ exports.SHA1 = SHA1;
|
|
|
653
769
|
*/
|
|
654
770
|
class SHA512 {
|
|
655
771
|
constructor() {
|
|
656
|
-
this.
|
|
772
|
+
this.native = createNodeHash('sha512');
|
|
773
|
+
if (this.native == null) {
|
|
774
|
+
this.h = new FastSHA512();
|
|
775
|
+
}
|
|
657
776
|
}
|
|
658
777
|
update(msg, enc) {
|
|
659
|
-
|
|
660
|
-
this.h.update(data);
|
|
778
|
+
updateNativeOrFallback(this.native, this.h, toHashBytes(msg, enc));
|
|
661
779
|
return this;
|
|
662
780
|
}
|
|
663
781
|
digest() {
|
|
664
|
-
return
|
|
782
|
+
return digestNativeOrFallback(this.native, this.h);
|
|
665
783
|
}
|
|
666
784
|
digestHex() {
|
|
667
|
-
return
|
|
785
|
+
return digestHexNativeOrFallback(this.native, this.h);
|
|
668
786
|
}
|
|
669
787
|
}
|
|
670
788
|
exports.SHA512 = SHA512;
|
|
@@ -697,10 +815,11 @@ class SHA256HMAC {
|
|
|
697
815
|
constructor(key) {
|
|
698
816
|
this.blockSize = 64;
|
|
699
817
|
this.outSize = 32;
|
|
700
|
-
const k = key
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
818
|
+
const k = toHashKeyBytes(key);
|
|
819
|
+
this.native = createNodeHmac('sha256', k);
|
|
820
|
+
if (this.native == null) {
|
|
821
|
+
this.h = new HMAC(sha256Fast, k);
|
|
822
|
+
}
|
|
704
823
|
}
|
|
705
824
|
/**
|
|
706
825
|
* Updates the `SHA256HMAC` object with part of the message to be hashed.
|
|
@@ -714,8 +833,7 @@ class SHA256HMAC {
|
|
|
714
833
|
* myHMAC.update('deadbeef', 'hex');
|
|
715
834
|
*/
|
|
716
835
|
update(msg, enc) {
|
|
717
|
-
|
|
718
|
-
this.h.update(data);
|
|
836
|
+
updateNativeOrFallback(this.native, this.h, toHashBytes(msg, enc));
|
|
719
837
|
return this;
|
|
720
838
|
}
|
|
721
839
|
/**
|
|
@@ -728,7 +846,7 @@ class SHA256HMAC {
|
|
|
728
846
|
* let hashedMessage = myHMAC.digest();
|
|
729
847
|
*/
|
|
730
848
|
digest() {
|
|
731
|
-
return
|
|
849
|
+
return digestNativeOrFallback(this.native, this.h);
|
|
732
850
|
}
|
|
733
851
|
/**
|
|
734
852
|
* Finalizes the HMAC computation and returns the resultant hash as a hex string.
|
|
@@ -740,7 +858,7 @@ class SHA256HMAC {
|
|
|
740
858
|
* let hashedMessage = myHMAC.digestHex();
|
|
741
859
|
*/
|
|
742
860
|
digestHex() {
|
|
743
|
-
return
|
|
861
|
+
return digestHexNativeOrFallback(this.native, this.h);
|
|
744
862
|
}
|
|
745
863
|
}
|
|
746
864
|
exports.SHA256HMAC = SHA256HMAC;
|
|
@@ -810,10 +928,11 @@ class SHA512HMAC {
|
|
|
810
928
|
constructor(key) {
|
|
811
929
|
this.blockSize = 128;
|
|
812
930
|
this.outSize = 32;
|
|
813
|
-
const k = key
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
931
|
+
const k = toHashKeyBytes(key);
|
|
932
|
+
this.native = createNodeHmac('sha512', k);
|
|
933
|
+
if (this.native == null) {
|
|
934
|
+
this.h = new HMAC(sha512Fast, k);
|
|
935
|
+
}
|
|
817
936
|
}
|
|
818
937
|
/**
|
|
819
938
|
* Updates the `SHA512HMAC` object with part of the message to be hashed.
|
|
@@ -827,8 +946,7 @@ class SHA512HMAC {
|
|
|
827
946
|
* myHMAC.update('deadbeef', 'hex');
|
|
828
947
|
*/
|
|
829
948
|
update(msg, enc) {
|
|
830
|
-
|
|
831
|
-
this.h.update(data);
|
|
949
|
+
updateNativeOrFallback(this.native, this.h, toHashBytes(msg, enc));
|
|
832
950
|
return this;
|
|
833
951
|
}
|
|
834
952
|
/**
|
|
@@ -841,7 +959,7 @@ class SHA512HMAC {
|
|
|
841
959
|
* let hashedMessage = myHMAC.digest();
|
|
842
960
|
*/
|
|
843
961
|
digest() {
|
|
844
|
-
return
|
|
962
|
+
return digestNativeOrFallback(this.native, this.h);
|
|
845
963
|
}
|
|
846
964
|
/**
|
|
847
965
|
* Finalizes the HMAC computation and returns the resultant hash as a hex string.
|
|
@@ -853,10 +971,25 @@ class SHA512HMAC {
|
|
|
853
971
|
* let hashedMessage = myHMAC.digestHex();
|
|
854
972
|
*/
|
|
855
973
|
digestHex() {
|
|
856
|
-
return
|
|
974
|
+
return digestHexNativeOrFallback(this.native, this.h);
|
|
857
975
|
}
|
|
858
976
|
}
|
|
859
977
|
exports.SHA512HMAC = SHA512HMAC;
|
|
978
|
+
function sha256Bytes(msg, enc) {
|
|
979
|
+
const native = digestWithNodeHash('sha256', msg, enc);
|
|
980
|
+
if (native != null)
|
|
981
|
+
return native;
|
|
982
|
+
return new FastSHA256().update(toHashBytes(msg, enc)).digest();
|
|
983
|
+
}
|
|
984
|
+
function sha512Bytes(msg, enc) {
|
|
985
|
+
const native = digestWithNodeHash('sha512', msg, enc);
|
|
986
|
+
if (native != null)
|
|
987
|
+
return native;
|
|
988
|
+
return new FastSHA512().update(toHashBytes(msg, enc)).digest();
|
|
989
|
+
}
|
|
990
|
+
function ripemd160Bytes(msg, enc) {
|
|
991
|
+
return digestWithNodeHash('ripemd160', msg, enc);
|
|
992
|
+
}
|
|
860
993
|
/**
|
|
861
994
|
* Computes RIPEMD160 hash of a given message.
|
|
862
995
|
* @function ripemd160
|
|
@@ -869,6 +1002,9 @@ exports.SHA512HMAC = SHA512HMAC;
|
|
|
869
1002
|
* const digest = ripemd160('Hello, world!');
|
|
870
1003
|
*/
|
|
871
1004
|
const ripemd160 = (msg, enc) => {
|
|
1005
|
+
const native = ripemd160Bytes(msg, enc);
|
|
1006
|
+
if (native != null)
|
|
1007
|
+
return Array.from(native);
|
|
872
1008
|
return new RIPEMD160().update(msg, enc).digest();
|
|
873
1009
|
};
|
|
874
1010
|
exports.ripemd160 = ripemd160;
|
|
@@ -899,7 +1035,7 @@ exports.sha1 = sha1;
|
|
|
899
1035
|
* const digest = sha256('Hello, world!');
|
|
900
1036
|
*/
|
|
901
1037
|
const sha256 = (msg, enc) => {
|
|
902
|
-
return
|
|
1038
|
+
return Array.from(sha256Bytes(msg, enc));
|
|
903
1039
|
};
|
|
904
1040
|
exports.sha256 = sha256;
|
|
905
1041
|
/**
|
|
@@ -914,7 +1050,7 @@ exports.sha256 = sha256;
|
|
|
914
1050
|
* const digest = sha512('Hello, world!');
|
|
915
1051
|
*/
|
|
916
1052
|
const sha512 = (msg, enc) => {
|
|
917
|
-
return
|
|
1053
|
+
return Array.from(sha512Bytes(msg, enc));
|
|
918
1054
|
};
|
|
919
1055
|
exports.sha512 = sha512;
|
|
920
1056
|
/**
|
|
@@ -931,8 +1067,7 @@ exports.sha512 = sha512;
|
|
|
931
1067
|
* const doubleHash = hash256('Hello, world!');
|
|
932
1068
|
*/
|
|
933
1069
|
const hash256 = (msg, enc) => {
|
|
934
|
-
|
|
935
|
-
return new SHA256().update(first).digest();
|
|
1070
|
+
return Array.from(sha256Bytes(sha256Bytes(msg, enc)));
|
|
936
1071
|
};
|
|
937
1072
|
exports.hash256 = hash256;
|
|
938
1073
|
/**
|
|
@@ -948,7 +1083,10 @@ exports.hash256 = hash256;
|
|
|
948
1083
|
* const hash = hash160('Hello, world!');
|
|
949
1084
|
*/
|
|
950
1085
|
const hash160 = (msg, enc) => {
|
|
951
|
-
const first =
|
|
1086
|
+
const first = sha256Bytes(msg, enc);
|
|
1087
|
+
const native = ripemd160Bytes(first);
|
|
1088
|
+
if (native != null)
|
|
1089
|
+
return Array.from(native);
|
|
952
1090
|
return new RIPEMD160().update(first).digest();
|
|
953
1091
|
};
|
|
954
1092
|
exports.hash160 = hash160;
|
|
@@ -965,6 +1103,9 @@ exports.hash160 = hash160;
|
|
|
965
1103
|
* const digest = sha256hmac('deadbeef', 'ffff001d');
|
|
966
1104
|
*/
|
|
967
1105
|
const sha256hmac = (key, msg, enc) => {
|
|
1106
|
+
const native = digestWithNodeHmac('sha256', key, msg, enc);
|
|
1107
|
+
if (native != null)
|
|
1108
|
+
return Array.from(native);
|
|
968
1109
|
return new SHA256HMAC(key).update(msg, enc).digest();
|
|
969
1110
|
};
|
|
970
1111
|
exports.sha256hmac = sha256hmac;
|
|
@@ -981,6 +1122,9 @@ exports.sha256hmac = sha256hmac;
|
|
|
981
1122
|
* const digest = sha512hmac('deadbeef', 'ffff001d');
|
|
982
1123
|
*/
|
|
983
1124
|
const sha512hmac = (key, msg, enc) => {
|
|
1125
|
+
const native = digestWithNodeHmac('sha512', key, msg, enc);
|
|
1126
|
+
if (native != null)
|
|
1127
|
+
return Array.from(native);
|
|
984
1128
|
return new SHA512HMAC(key).update(msg, enc).digest();
|
|
985
1129
|
};
|
|
986
1130
|
exports.sha512hmac = sha512hmac;
|
|
@@ -1004,7 +1148,7 @@ function abytes(b, ...lengths) {
|
|
|
1004
1148
|
}
|
|
1005
1149
|
function ahash(h) {
|
|
1006
1150
|
if (typeof h !== 'function' || typeof h.create !== 'function') {
|
|
1007
|
-
throw new
|
|
1151
|
+
throw new TypeError('Hash should be wrapped by utils.createHasher');
|
|
1008
1152
|
}
|
|
1009
1153
|
anumber(h.outputLen);
|
|
1010
1154
|
anumber(h.blockLen);
|
|
@@ -1024,8 +1168,8 @@ function aoutput(out, instance) {
|
|
|
1024
1168
|
}
|
|
1025
1169
|
}
|
|
1026
1170
|
function clean(...arrays) {
|
|
1027
|
-
for (
|
|
1028
|
-
|
|
1171
|
+
for (const arr of arrays)
|
|
1172
|
+
arr.fill(0);
|
|
1029
1173
|
}
|
|
1030
1174
|
function createView(arr) {
|
|
1031
1175
|
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
@@ -1063,6 +1207,7 @@ const _32n = BigInt(32);
|
|
|
1063
1207
|
function fromBig(n, le = false) {
|
|
1064
1208
|
if (le)
|
|
1065
1209
|
return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };
|
|
1210
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1066
1211
|
return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
1067
1212
|
}
|
|
1068
1213
|
function split(lst, le = false) {
|
|
@@ -1084,13 +1229,17 @@ const rotrBH = (h, l, s) => (h << (64 - s)) | (l >>> (s - 32));
|
|
|
1084
1229
|
const rotrBL = (h, l, s) => (h >>> (s - 32)) | (l << (64 - s));
|
|
1085
1230
|
function add(Ah, Al, Bh, Bl) {
|
|
1086
1231
|
const l = (Al >>> 0) + (Bl >>> 0);
|
|
1232
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1087
1233
|
return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 };
|
|
1088
1234
|
}
|
|
1089
1235
|
const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
1236
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1090
1237
|
const add3H = (low, Ah, Bh, Ch) => (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0;
|
|
1091
1238
|
const add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
|
|
1239
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1092
1240
|
const add4H = (low, Ah, Bh, Ch, Dh) => (Ah + Bh + Ch + Dh + ((low / 2 ** 32) | 0)) | 0;
|
|
1093
1241
|
const add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
|
|
1242
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1094
1243
|
const add5H = (low, Ah, Bh, Ch, Dh, Eh) => (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0;
|
|
1095
1244
|
// _md helpers
|
|
1096
1245
|
class HashMD extends Hash {
|
|
@@ -1217,13 +1366,21 @@ const SHA256_W = new Uint32Array(64);
|
|
|
1217
1366
|
class FastSHA256 extends HashMD {
|
|
1218
1367
|
constructor(outputLen = 32) {
|
|
1219
1368
|
super(64, outputLen, 8, false);
|
|
1369
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1220
1370
|
this.A = SHA256_IV[0] | 0;
|
|
1371
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1221
1372
|
this.B = SHA256_IV[1] | 0;
|
|
1373
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1222
1374
|
this.C = SHA256_IV[2] | 0;
|
|
1375
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1223
1376
|
this.D = SHA256_IV[3] | 0;
|
|
1377
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1224
1378
|
this.E = SHA256_IV[4] | 0;
|
|
1379
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1225
1380
|
this.F = SHA256_IV[5] | 0;
|
|
1381
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1226
1382
|
this.G = SHA256_IV[6] | 0;
|
|
1383
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1227
1384
|
this.H = SHA256_IV[7] | 0;
|
|
1228
1385
|
}
|
|
1229
1386
|
get() {
|
|
@@ -1231,13 +1388,21 @@ class FastSHA256 extends HashMD {
|
|
|
1231
1388
|
return [A, B, C, D, E, F, G, H];
|
|
1232
1389
|
}
|
|
1233
1390
|
set(A, B, C, D, E, F, G, H) {
|
|
1391
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1234
1392
|
this.A = A | 0;
|
|
1393
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1235
1394
|
this.B = B | 0;
|
|
1395
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1236
1396
|
this.C = C | 0;
|
|
1397
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1237
1398
|
this.D = D | 0;
|
|
1399
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1238
1400
|
this.E = E | 0;
|
|
1401
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1239
1402
|
this.F = F | 0;
|
|
1403
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1240
1404
|
this.G = G | 0;
|
|
1405
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1241
1406
|
this.H = H | 0;
|
|
1242
1407
|
}
|
|
1243
1408
|
process(view, offset) {
|
|
@@ -1368,7 +1533,7 @@ const K512 = (() => split([
|
|
|
1368
1533
|
'0x597f299cfc657e2a',
|
|
1369
1534
|
'0x5fcb6fab3ad6faec',
|
|
1370
1535
|
'0x6c44198c4a475817'
|
|
1371
|
-
].map(
|
|
1536
|
+
].map(BigInt)))();
|
|
1372
1537
|
const SHA512_Kh = (() => K512[0])();
|
|
1373
1538
|
const SHA512_Kl = (() => K512[1])();
|
|
1374
1539
|
const SHA512_W_H = new Uint32Array(80);
|
|
@@ -1376,21 +1541,37 @@ const SHA512_W_L = new Uint32Array(80);
|
|
|
1376
1541
|
class FastSHA512 extends HashMD {
|
|
1377
1542
|
constructor(outputLen = 64) {
|
|
1378
1543
|
super(128, outputLen, 16, false);
|
|
1544
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1379
1545
|
this.Ah = SHA512_IV[0] | 0;
|
|
1546
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1380
1547
|
this.Al = SHA512_IV[1] | 0;
|
|
1548
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1381
1549
|
this.Bh = SHA512_IV[2] | 0;
|
|
1550
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1382
1551
|
this.Bl = SHA512_IV[3] | 0;
|
|
1552
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1383
1553
|
this.Ch = SHA512_IV[4] | 0;
|
|
1554
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1384
1555
|
this.Cl = SHA512_IV[5] | 0;
|
|
1556
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1385
1557
|
this.Dh = SHA512_IV[6] | 0;
|
|
1558
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1386
1559
|
this.Dl = SHA512_IV[7] | 0;
|
|
1560
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1387
1561
|
this.Eh = SHA512_IV[8] | 0;
|
|
1562
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1388
1563
|
this.El = SHA512_IV[9] | 0;
|
|
1564
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1389
1565
|
this.Fh = SHA512_IV[10] | 0;
|
|
1566
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1390
1567
|
this.Fl = SHA512_IV[11] | 0;
|
|
1568
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1391
1569
|
this.Gh = SHA512_IV[12] | 0;
|
|
1570
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1392
1571
|
this.Gl = SHA512_IV[13] | 0;
|
|
1572
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1393
1573
|
this.Hh = SHA512_IV[14] | 0;
|
|
1574
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1394
1575
|
this.Hl = SHA512_IV[15] | 0;
|
|
1395
1576
|
}
|
|
1396
1577
|
get() {
|
|
@@ -1398,40 +1579,62 @@ class FastSHA512 extends HashMD {
|
|
|
1398
1579
|
return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
|
|
1399
1580
|
}
|
|
1400
1581
|
set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
|
|
1582
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1401
1583
|
this.Ah = Ah | 0;
|
|
1584
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1402
1585
|
this.Al = Al | 0;
|
|
1586
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1403
1587
|
this.Bh = Bh | 0;
|
|
1588
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1404
1589
|
this.Bl = Bl | 0;
|
|
1590
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1405
1591
|
this.Ch = Ch | 0;
|
|
1592
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1406
1593
|
this.Cl = Cl | 0;
|
|
1594
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1407
1595
|
this.Dh = Dh | 0;
|
|
1596
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1408
1597
|
this.Dl = Dl | 0;
|
|
1598
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1409
1599
|
this.Eh = Eh | 0;
|
|
1600
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1410
1601
|
this.El = El | 0;
|
|
1602
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1411
1603
|
this.Fh = Fh | 0;
|
|
1604
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1412
1605
|
this.Fl = Fl | 0;
|
|
1606
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1413
1607
|
this.Gh = Gh | 0;
|
|
1608
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1414
1609
|
this.Gl = Gl | 0;
|
|
1610
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1415
1611
|
this.Hh = Hh | 0;
|
|
1612
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1416
1613
|
this.Hl = Hl | 0;
|
|
1417
1614
|
}
|
|
1418
1615
|
process(view, offset) {
|
|
1419
|
-
for (let i = 0; i < 16; i++, offset +=
|
|
1616
|
+
for (let i = 0; i < 16; i++, offset += 8) {
|
|
1420
1617
|
SHA512_W_H[i] = view.getUint32(offset);
|
|
1421
|
-
SHA512_W_L[i] = view.getUint32(
|
|
1618
|
+
SHA512_W_L[i] = view.getUint32(offset + 4);
|
|
1422
1619
|
}
|
|
1423
1620
|
for (let i = 16; i < 80; i++) {
|
|
1621
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1424
1622
|
const W15h = SHA512_W_H[i - 15] | 0;
|
|
1623
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1425
1624
|
const W15l = SHA512_W_L[i - 15] | 0;
|
|
1426
1625
|
const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
|
|
1427
1626
|
const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
|
|
1627
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1428
1628
|
const W2h = SHA512_W_H[i - 2] | 0;
|
|
1629
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1429
1630
|
const W2l = SHA512_W_L[i - 2] | 0;
|
|
1430
1631
|
const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
|
|
1431
1632
|
const s1l = rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6);
|
|
1432
1633
|
const SUMl = add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
|
|
1433
1634
|
const SUMh = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
|
|
1635
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1434
1636
|
SHA512_W_H[i] = SUMh | 0;
|
|
1637
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1435
1638
|
SHA512_W_L[i] = SUMl | 0;
|
|
1436
1639
|
}
|
|
1437
1640
|
let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
@@ -1442,26 +1645,40 @@ class FastSHA512 extends HashMD {
|
|
|
1442
1645
|
const CHIl = (El & Fl) ^ (~El & Gl);
|
|
1443
1646
|
const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
|
|
1444
1647
|
const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
|
|
1648
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1445
1649
|
const T1l = T1ll | 0;
|
|
1446
1650
|
const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
|
|
1447
1651
|
const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
|
|
1448
1652
|
const MAJh = (Ah & Bh) ^ (Ah & Ch) ^ (Bh & Ch);
|
|
1449
1653
|
const MAJl = (Al & Bl) ^ (Al & Cl) ^ (Bl & Cl);
|
|
1654
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1450
1655
|
Hh = Gh | 0;
|
|
1656
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1451
1657
|
Hl = Gl | 0;
|
|
1658
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1452
1659
|
Gh = Fh | 0;
|
|
1660
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1453
1661
|
Gl = Fl | 0;
|
|
1662
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1454
1663
|
Fh = Eh | 0;
|
|
1664
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1455
1665
|
Fl = El | 0;
|
|
1456
1666
|
({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
|
|
1667
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1457
1668
|
Dh = Ch | 0;
|
|
1669
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1458
1670
|
Dl = Cl | 0;
|
|
1671
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1459
1672
|
Ch = Bh | 0;
|
|
1673
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1460
1674
|
Cl = Bl | 0;
|
|
1675
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1461
1676
|
Bh = Ah | 0;
|
|
1677
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1462
1678
|
Bl = Al | 0;
|
|
1463
1679
|
const T2l = add3L(sigma0l, MAJl, T1l);
|
|
1464
1680
|
Ah = add3H(T2l, sigma0h, MAJh, T1h);
|
|
1681
|
+
// eslint-disable-next-line no-bitwise -- ToInt32 (ECMA-262); not truncation. Required for SHA arithmetic.
|
|
1465
1682
|
Al = T2l | 0;
|
|
1466
1683
|
}
|
|
1467
1684
|
;
|
|
@@ -1493,7 +1710,7 @@ class HMAC extends Hash {
|
|
|
1493
1710
|
const key = toBytes(_key);
|
|
1494
1711
|
this.iHash = hash.create();
|
|
1495
1712
|
if (typeof this.iHash.update !== 'function') {
|
|
1496
|
-
throw new
|
|
1713
|
+
throw new TypeError('Expected instance of class which extends utils.Hash');
|
|
1497
1714
|
}
|
|
1498
1715
|
this.blockLen = this.iHash.blockLen;
|
|
1499
1716
|
this.outputLen = this.iHash.outputLen;
|
|
@@ -1568,7 +1785,8 @@ function pbkdf2Core(hash, password, salt, opts) {
|
|
|
1568
1785
|
for (let ti = 1, pos = 0; pos < dkLen; ti++, pos += PRF.outputLen) {
|
|
1569
1786
|
const Ti = DK.subarray(pos, pos + PRF.outputLen);
|
|
1570
1787
|
view.setInt32(0, ti, false);
|
|
1571
|
-
|
|
1788
|
+
prfW = PRFSalt._cloneInto(prfW);
|
|
1789
|
+
prfW.update(arr).digestInto(u);
|
|
1572
1790
|
Ti.set(u.subarray(0, Ti.length));
|
|
1573
1791
|
for (let ui = 1; ui < c; ui++) {
|
|
1574
1792
|
PRF._cloneInto(prfW).update(u).digestInto(u);
|
|
@@ -1604,21 +1822,10 @@ function pbkdf2(password, salt, iterations, keylen, digest = 'sha512') {
|
|
|
1604
1822
|
if (digest !== 'sha512') {
|
|
1605
1823
|
throw new Error('Only sha512 is supported in this PBKDF2 implementation');
|
|
1606
1824
|
}
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
try {
|
|
1612
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
1613
|
-
const nodeCrypto = require('crypto');
|
|
1614
|
-
if (typeof nodeCrypto.pbkdf2Sync === 'function') {
|
|
1615
|
-
const p = Buffer.from(password);
|
|
1616
|
-
const s = Buffer.from(salt);
|
|
1617
|
-
return [...nodeCrypto.pbkdf2Sync(p, s, iterations, keylen, digest)];
|
|
1618
|
-
}
|
|
1619
|
-
}
|
|
1620
|
-
catch {
|
|
1621
|
-
// ignore
|
|
1825
|
+
const pbkdf2Sync = NODE_CRYPTO?.pbkdf2Sync;
|
|
1826
|
+
if (typeof pbkdf2Sync === 'function') {
|
|
1827
|
+
const out = pbkdf2Sync(toHashBytes(password), toHashBytes(salt), iterations, keylen, digest);
|
|
1828
|
+
return Array.from(out);
|
|
1622
1829
|
}
|
|
1623
1830
|
const p = Uint8Array.from(password);
|
|
1624
1831
|
const s = Uint8Array.from(salt);
|