@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
|
@@ -331,7 +331,7 @@ export default class MerklePath {
|
|
|
331
331
|
const l = offset << 1
|
|
332
332
|
|
|
333
333
|
const leaf0 = this.findOrComputeLeaf(h, l)
|
|
334
|
-
if (leaf0
|
|
334
|
+
if (leaf0?.hash == null || leaf0.hash === '') return undefined
|
|
335
335
|
|
|
336
336
|
const leaf1 = this.findOrComputeLeaf(h, l + 1)
|
|
337
337
|
if (leaf1?.hash == null) {
|
|
@@ -431,7 +431,7 @@ export default class MerklePath {
|
|
|
431
431
|
*/
|
|
432
432
|
trim (): void {
|
|
433
433
|
const pushIfNew = (v: number, a: number[]): void => {
|
|
434
|
-
if (a.length === 0 || a.
|
|
434
|
+
if (a.length === 0 || a.at(-1) !== v) {
|
|
435
435
|
a.push(v)
|
|
436
436
|
}
|
|
437
437
|
}
|
|
@@ -457,9 +457,9 @@ export default class MerklePath {
|
|
|
457
457
|
|
|
458
458
|
let computedOffsets: number[] = [] // in next level
|
|
459
459
|
let dropOffsets: number[] = []
|
|
460
|
-
for (
|
|
460
|
+
for (const level of this.path) {
|
|
461
461
|
// Sort each level by increasing offset order
|
|
462
|
-
|
|
462
|
+
level.sort((a, b) => a.offset - b.offset)
|
|
463
463
|
}
|
|
464
464
|
for (let l = 0; l < this.path[0].length; l++) {
|
|
465
465
|
const n = this.path[0][l]
|
|
@@ -17,6 +17,7 @@ import { Beef, BEEF_V1 } from './Beef.js'
|
|
|
17
17
|
import P2PKH from '../script/templates/P2PKH.js'
|
|
18
18
|
import type { WalletInterface, DescriptionString5to50Bytes, CreateActionOptions } from '../wallet/Wallet.interfaces.js'
|
|
19
19
|
import TransactionSignature from '../primitives/TransactionSignature.js'
|
|
20
|
+
import Random from '../primitives/Random.js'
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* Represents a complete Bitcoin transaction. This class encapsulates all the details
|
|
@@ -79,7 +80,7 @@ export default class Transaction {
|
|
|
79
80
|
if (typeof obj.pathIndex === 'number') {
|
|
80
81
|
const path = BUMPs[obj.pathIndex]
|
|
81
82
|
if (typeof path !== 'object') {
|
|
82
|
-
throw new
|
|
83
|
+
throw new TypeError('Invalid merkle path index found in BEEF!')
|
|
83
84
|
}
|
|
84
85
|
obj.tx.merklePath = path
|
|
85
86
|
} else {
|
|
@@ -89,7 +90,7 @@ export default class Transaction {
|
|
|
89
90
|
}
|
|
90
91
|
const sourceObj = transactions[input.sourceTXID]
|
|
91
92
|
if (typeof sourceObj !== 'object') {
|
|
92
|
-
throw new
|
|
93
|
+
throw new TypeError(
|
|
93
94
|
`Reference to unknown TXID in BEEF: ${input.sourceTXID ?? 'undefined'}`
|
|
94
95
|
)
|
|
95
96
|
}
|
|
@@ -123,10 +124,10 @@ export default class Transaction {
|
|
|
123
124
|
static fromAtomicBEEF (beef: number[] | Uint8Array): Transaction {
|
|
124
125
|
const { tx, txid, beef: b } = Transaction.fromAnyBeef(beef)
|
|
125
126
|
if (txid !== b.atomicTxid) {
|
|
126
|
-
if (b.atomicTxid
|
|
127
|
-
throw new Error(`Transaction with TXID ${b.atomicTxid} not found in BEEF data.`)
|
|
128
|
-
} else {
|
|
127
|
+
if (b.atomicTxid == null) {
|
|
129
128
|
throw new Error('beef must conform to BRC-95 and must contain the subject txid.')
|
|
129
|
+
} else {
|
|
130
|
+
throw new Error(`Transaction with TXID ${b.atomicTxid} not found in BEEF data.`)
|
|
130
131
|
}
|
|
131
132
|
}
|
|
132
133
|
return tx
|
|
@@ -137,13 +138,17 @@ export default class Transaction {
|
|
|
137
138
|
if (b.txs.length < 1) {
|
|
138
139
|
throw new Error('beef must include at least one transaction.')
|
|
139
140
|
}
|
|
140
|
-
const
|
|
141
|
+
const lastTx = b.txs.at(-1)
|
|
142
|
+
if (lastTx == null) {
|
|
143
|
+
throw new Error('beef must include at least one transaction.')
|
|
144
|
+
}
|
|
145
|
+
const target = txid ?? b.atomicTxid ?? lastTx.txid
|
|
141
146
|
const tx = b.findAtomicTransaction(target)
|
|
142
147
|
if (tx == null) {
|
|
143
|
-
if (txid
|
|
144
|
-
throw new Error(`Transaction with TXID ${target} not found in BEEF data.`)
|
|
145
|
-
} else {
|
|
148
|
+
if (txid == null) {
|
|
146
149
|
throw new Error('beef does not contain transaction for atomic txid.')
|
|
150
|
+
} else {
|
|
151
|
+
throw new Error(`Transaction with TXID ${String(target)} not found in BEEF data.`)
|
|
147
152
|
}
|
|
148
153
|
}
|
|
149
154
|
return { tx, beef: b, txid: target }
|
|
@@ -172,7 +177,7 @@ export default class Transaction {
|
|
|
172
177
|
const lockingScriptBin = br.read(lockingScriptLength)
|
|
173
178
|
const lockingScript = LockingScript.fromBinary(lockingScriptBin)
|
|
174
179
|
const sourceTransaction = new Transaction(undefined, [], [], undefined)
|
|
175
|
-
sourceTransaction.outputs = Array(sourceOutputIndex + 1).fill(null)
|
|
180
|
+
sourceTransaction.outputs = new Array(sourceOutputIndex + 1).fill(null)
|
|
176
181
|
sourceTransaction.outputs[sourceOutputIndex] = {
|
|
177
182
|
satoshis,
|
|
178
183
|
lockingScript
|
|
@@ -364,17 +369,15 @@ export default class Transaction {
|
|
|
364
369
|
*/
|
|
365
370
|
addInput (input: TransactionInput): void {
|
|
366
371
|
if (
|
|
367
|
-
|
|
368
|
-
|
|
372
|
+
input.sourceTXID === undefined &&
|
|
373
|
+
input.sourceTransaction === undefined
|
|
369
374
|
) {
|
|
370
|
-
throw new
|
|
375
|
+
throw new TypeError(
|
|
371
376
|
'A reference to an an input transaction is required. If the input transaction itself cannot be referenced, its TXID must still be provided.'
|
|
372
377
|
)
|
|
373
378
|
}
|
|
374
379
|
// If the input sequence number hasn't been set, the expectation is that it is final.
|
|
375
|
-
|
|
376
|
-
input.sequence = 0xffffffff
|
|
377
|
-
}
|
|
380
|
+
input.sequence ??= 0xffffffff
|
|
378
381
|
this.invalidateSerializationCaches()
|
|
379
382
|
this.inputs.push(input)
|
|
380
383
|
}
|
|
@@ -387,8 +390,8 @@ export default class Transaction {
|
|
|
387
390
|
addOutput (output: TransactionOutput): void {
|
|
388
391
|
this.cachedHash = undefined
|
|
389
392
|
if (output.change !== true) {
|
|
390
|
-
if (
|
|
391
|
-
throw new
|
|
393
|
+
if (output.satoshis === undefined) {
|
|
394
|
+
throw new TypeError(
|
|
392
395
|
'either satoshis must be defined or change must be set to true'
|
|
393
396
|
)
|
|
394
397
|
}
|
|
@@ -407,7 +410,7 @@ export default class Transaction {
|
|
|
407
410
|
*/
|
|
408
411
|
addP2PKHOutput (address: number[] | string, satoshis?: number): void {
|
|
409
412
|
const lockingScript = new P2PKH().lock(address)
|
|
410
|
-
if (
|
|
413
|
+
if (satoshis === undefined) {
|
|
411
414
|
return this.addOutput({ lockingScript, change: true })
|
|
412
415
|
}
|
|
413
416
|
this.addOutput({
|
|
@@ -462,7 +465,7 @@ export default class Transaction {
|
|
|
462
465
|
let change = 0
|
|
463
466
|
for (const input of this.inputs) {
|
|
464
467
|
if (typeof input.sourceTransaction !== 'object') {
|
|
465
|
-
throw new
|
|
468
|
+
throw new TypeError(
|
|
466
469
|
'Source transactions are required for all inputs during fee computation'
|
|
467
470
|
)
|
|
468
471
|
}
|
|
@@ -492,11 +495,11 @@ export default class Transaction {
|
|
|
492
495
|
distributedChange = this.distributeEqualChange(change, changeOutputs)
|
|
493
496
|
}
|
|
494
497
|
if (distributedChange < change) {
|
|
495
|
-
const lastOutput = this.outputs
|
|
496
|
-
if (lastOutput.satoshis
|
|
497
|
-
lastOutput.satoshis += change - distributedChange
|
|
498
|
-
} else {
|
|
498
|
+
const lastOutput = this.outputs.at(-1)
|
|
499
|
+
if (lastOutput.satoshis === undefined) {
|
|
499
500
|
lastOutput.satoshis = change - distributedChange
|
|
501
|
+
} else {
|
|
502
|
+
lastOutput.satoshis += change - distributedChange
|
|
500
503
|
}
|
|
501
504
|
}
|
|
502
505
|
}
|
|
@@ -507,7 +510,7 @@ export default class Transaction {
|
|
|
507
510
|
): number {
|
|
508
511
|
let distributedChange = 0
|
|
509
512
|
let changeToUse = change
|
|
510
|
-
const benfordNumbers = Array(changeOutputs.length).fill(1)
|
|
513
|
+
const benfordNumbers = new Array(changeOutputs.length).fill(1)
|
|
511
514
|
changeToUse -= changeOutputs.length
|
|
512
515
|
distributedChange += changeOutputs.length
|
|
513
516
|
for (let i = 0; i < changeOutputs.length - 1; i++) {
|
|
@@ -536,7 +539,7 @@ export default class Transaction {
|
|
|
536
539
|
}
|
|
537
540
|
|
|
538
541
|
private benfordNumber (min: number, max: number): number {
|
|
539
|
-
const d =
|
|
542
|
+
const d = Random(1)[0] % 9 + 1
|
|
540
543
|
return Math.floor(
|
|
541
544
|
min + ((max - min) * Math.log10(1 + 1 / d)) / Math.log10(10)
|
|
542
545
|
)
|
|
@@ -551,7 +554,7 @@ export default class Transaction {
|
|
|
551
554
|
let totalIn = 0
|
|
552
555
|
for (const input of this.inputs) {
|
|
553
556
|
if (typeof input.sourceTransaction !== 'object') {
|
|
554
|
-
throw new
|
|
557
|
+
throw new TypeError(
|
|
555
558
|
'Source transactions or sourceSatoshis are required for all inputs to calculate fee'
|
|
556
559
|
)
|
|
557
560
|
}
|
|
@@ -571,7 +574,7 @@ export default class Transaction {
|
|
|
571
574
|
async sign (): Promise<void> {
|
|
572
575
|
this.invalidateSerializationCaches()
|
|
573
576
|
for (const out of this.outputs) {
|
|
574
|
-
if (
|
|
577
|
+
if (out.satoshis === undefined) {
|
|
575
578
|
if (out.change === true) {
|
|
576
579
|
throw new Error(
|
|
577
580
|
'There are still change outputs with uncomputed amounts. Use the fee() method to compute the change amounts and transaction fees prior to signing.'
|
|
@@ -615,11 +618,11 @@ export default class Transaction {
|
|
|
615
618
|
writer.writeUInt32LE(this.version)
|
|
616
619
|
writer.writeVarIntNum(this.inputs.length)
|
|
617
620
|
for (const i of this.inputs) {
|
|
618
|
-
if (
|
|
619
|
-
if (i.sourceTransaction
|
|
620
|
-
writer.write(i.sourceTransaction.hash() as number[])
|
|
621
|
-
} else {
|
|
621
|
+
if (i.sourceTXID === undefined) {
|
|
622
|
+
if (i.sourceTransaction == null) {
|
|
622
623
|
throw new Error('sourceTransaction is undefined')
|
|
624
|
+
} else {
|
|
625
|
+
writer.write(i.sourceTransaction.hash() as number[])
|
|
623
626
|
}
|
|
624
627
|
} else {
|
|
625
628
|
writer.writeReverse(toArray(i.sourceTXID, 'hex'))
|
|
@@ -650,9 +653,7 @@ export default class Transaction {
|
|
|
650
653
|
}
|
|
651
654
|
|
|
652
655
|
private getSerializedBytes (): Uint8Array {
|
|
653
|
-
|
|
654
|
-
this.rawBytesCache = this.buildSerializedBytes()
|
|
655
|
-
}
|
|
656
|
+
this.rawBytesCache ??= this.buildSerializedBytes()
|
|
656
657
|
return this.rawBytesCache
|
|
657
658
|
}
|
|
658
659
|
|
|
@@ -674,12 +675,12 @@ export default class Transaction {
|
|
|
674
675
|
writer.write([0, 0, 0, 0, 0, 0xef])
|
|
675
676
|
writer.writeVarIntNum(this.inputs.length)
|
|
676
677
|
for (const i of this.inputs) {
|
|
677
|
-
if (
|
|
678
|
-
throw new
|
|
678
|
+
if (i.sourceTransaction === undefined) {
|
|
679
|
+
throw new TypeError(
|
|
679
680
|
'All inputs must have source transactions when serializing to EF format'
|
|
680
681
|
)
|
|
681
682
|
}
|
|
682
|
-
if (
|
|
683
|
+
if (i.sourceTXID === undefined) {
|
|
683
684
|
writer.write(i.sourceTransaction.hash() as number[])
|
|
684
685
|
} else {
|
|
685
686
|
writer.write(toArray(i.sourceTXID, 'hex').reverse() as number[])
|
|
@@ -783,9 +784,7 @@ export default class Transaction {
|
|
|
783
784
|
* @returns {string | number[]} - The hash of the transaction in the specified format.
|
|
784
785
|
*/
|
|
785
786
|
hash (enc?: 'hex'): number[] | string {
|
|
786
|
-
|
|
787
|
-
this.cachedHash = hash256(this.getSerializedBytes())
|
|
788
|
-
}
|
|
787
|
+
this.cachedHash ??= hash256(this.getSerializedBytes())
|
|
789
788
|
if (enc === 'hex') {
|
|
790
789
|
return toHex(this.cachedHash)
|
|
791
790
|
}
|
|
@@ -866,7 +865,7 @@ export default class Transaction {
|
|
|
866
865
|
}
|
|
867
866
|
|
|
868
867
|
// Verify fee if feeModel is provided
|
|
869
|
-
if (
|
|
868
|
+
if (feeModel !== undefined) {
|
|
870
869
|
if (tx === undefined) {
|
|
871
870
|
throw new Error('Transaction is undefined')
|
|
872
871
|
}
|
|
@@ -890,12 +889,12 @@ export default class Transaction {
|
|
|
890
889
|
for (let i = 0; i < tx.inputs.length; i++) {
|
|
891
890
|
const input = tx.inputs[i]
|
|
892
891
|
if (typeof input.sourceTransaction !== 'object') {
|
|
893
|
-
throw new
|
|
892
|
+
throw new TypeError(
|
|
894
893
|
`Verification failed because the input at index ${i} of transaction ${txid} is missing an associated source transaction. This source transaction is required for transaction verification because there is no merkle proof for the transaction spending a UTXO it contains.`
|
|
895
894
|
)
|
|
896
895
|
}
|
|
897
896
|
if (typeof input.unlockingScript !== 'object') {
|
|
898
|
-
throw new
|
|
897
|
+
throw new TypeError(
|
|
899
898
|
`Verification failed because the input at index ${i} of transaction ${txid} is missing an associated unlocking script. This script is required for transaction verification because there is no merkle proof for the transaction spending the UTXO.`
|
|
900
899
|
)
|
|
901
900
|
}
|
|
@@ -909,9 +908,7 @@ export default class Transaction {
|
|
|
909
908
|
}
|
|
910
909
|
|
|
911
910
|
const otherInputs = tx.inputs.filter((_, idx) => idx !== i)
|
|
912
|
-
|
|
913
|
-
input.sourceTXID = sourceTxid
|
|
914
|
-
}
|
|
911
|
+
input.sourceTXID ??= sourceTxid
|
|
915
912
|
|
|
916
913
|
const spend = new Spend({
|
|
917
914
|
sourceTXID: input.sourceTXID,
|
|
@@ -938,7 +935,7 @@ export default class Transaction {
|
|
|
938
935
|
let outputTotal = 0
|
|
939
936
|
for (const out of tx.outputs) {
|
|
940
937
|
if (typeof out.satoshis !== 'number') {
|
|
941
|
-
throw new
|
|
938
|
+
throw new TypeError(
|
|
942
939
|
'Every output must have a defined amount during transaction verification.'
|
|
943
940
|
)
|
|
944
941
|
}
|
|
@@ -1240,14 +1237,14 @@ export default class Transaction {
|
|
|
1240
1237
|
}
|
|
1241
1238
|
|
|
1242
1239
|
// Extract options that apply to signAction (subset of CreateActionOptions)
|
|
1243
|
-
const signActionOptions: SignActionOptions | undefined = options
|
|
1244
|
-
?
|
|
1240
|
+
const signActionOptions: SignActionOptions | undefined = options == null
|
|
1241
|
+
? undefined
|
|
1242
|
+
: {
|
|
1245
1243
|
acceptDelayedBroadcast: options.acceptDelayedBroadcast,
|
|
1246
1244
|
returnTXIDOnly: options.returnTXIDOnly,
|
|
1247
1245
|
noSend: options.noSend,
|
|
1248
1246
|
sendWith: options.sendWith
|
|
1249
1247
|
}
|
|
1250
|
-
: undefined
|
|
1251
1248
|
|
|
1252
1249
|
// Call signAction with the generated unlocking scripts
|
|
1253
1250
|
const signResult = await wallet.signAction({
|
|
@@ -98,23 +98,23 @@ export function binaryHttpClient(): HttpClient {
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
if (
|
|
101
|
+
if (globalThis.window !== undefined && typeof globalThis.window.fetch === 'function') {
|
|
102
102
|
// Browser tab/page context
|
|
103
|
-
return new BinaryFetchClient(window.fetch.bind(window))
|
|
103
|
+
return new BinaryFetchClient(globalThis.window.fetch.bind(globalThis.window))
|
|
104
104
|
} else if (typeof globalThis.fetch === 'function') {
|
|
105
105
|
// Service workers, Deno, Node 18+ (any environment with global fetch)
|
|
106
106
|
return new BinaryFetchClient(globalThis.fetch.bind(globalThis))
|
|
107
|
-
} else if (typeof require
|
|
107
|
+
} else if (typeof require === 'undefined') {
|
|
108
|
+
return noHttpClient
|
|
109
|
+
} else {
|
|
108
110
|
// Older Node.js — use https module
|
|
109
|
-
// eslint-disable-next-line
|
|
110
111
|
try {
|
|
111
112
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
112
|
-
const https = require('https')
|
|
113
|
+
const https = require('node:https')
|
|
113
114
|
return new BinaryNodejsHttpClient(https)
|
|
114
|
-
} catch (
|
|
115
|
+
} catch (_httpsModuleUnavailable) {
|
|
116
|
+
// node:https not available in this runtime; fall through to noHttpClient
|
|
115
117
|
return noHttpClient
|
|
116
118
|
}
|
|
117
|
-
} else {
|
|
118
|
-
return noHttpClient
|
|
119
119
|
}
|
|
120
120
|
}
|
|
@@ -14,23 +14,23 @@ export function defaultHttpClient(): HttpClient {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
if (
|
|
17
|
+
if (globalThis.window !== undefined && typeof globalThis.window.fetch === 'function') {
|
|
18
18
|
// Browser tab/page context
|
|
19
|
-
return new FetchHttpClient(window.fetch.bind(window))
|
|
19
|
+
return new FetchHttpClient(globalThis.window.fetch.bind(globalThis.window))
|
|
20
20
|
} else if (typeof globalThis.fetch === 'function') {
|
|
21
21
|
// Service workers, Deno, Node 18+ (any environment with global fetch)
|
|
22
22
|
return new FetchHttpClient(globalThis.fetch.bind(globalThis))
|
|
23
|
-
} else if (typeof require
|
|
23
|
+
} else if (typeof require === 'undefined') {
|
|
24
|
+
return noHttpClient
|
|
25
|
+
} else {
|
|
24
26
|
// Older Node.js — use https module
|
|
25
|
-
// eslint-disable-next-line
|
|
26
27
|
try {
|
|
27
28
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
28
|
-
const https = require('https')
|
|
29
|
+
const https = require('node:https')
|
|
29
30
|
return new NodejsHttpClient(https)
|
|
30
|
-
} catch (
|
|
31
|
+
} catch (_httpsModuleUnavailable) {
|
|
32
|
+
// node:https not available in this runtime; fall through to noHttpClient
|
|
31
33
|
return noHttpClient
|
|
32
34
|
}
|
|
33
|
-
} else {
|
|
34
|
-
return noHttpClient
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -2,6 +2,8 @@ import { Point, PrivateKey, PublicKey, SymmetricKey } from '../primitives/index.
|
|
|
2
2
|
import { Counterparty, KeyDeriver, KeyDeriverApi } from './KeyDeriver.js'
|
|
3
3
|
import { WalletProtocol } from './Wallet.interfaces.js'
|
|
4
4
|
|
|
5
|
+
type CachedKeyValue = PublicKey | PrivateKey | SymmetricKey | Point | number[]
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* A cached version of KeyDeriver that caches the results of key derivation methods.
|
|
7
9
|
* This is useful for optimizing performance when the same keys are derived multiple times.
|
|
@@ -9,7 +11,7 @@ import { WalletProtocol } from './Wallet.interfaces.js'
|
|
|
9
11
|
*/
|
|
10
12
|
export default class CachedKeyDeriver implements KeyDeriverApi {
|
|
11
13
|
private readonly keyDeriver: KeyDeriver
|
|
12
|
-
private readonly cache: Map<string,
|
|
14
|
+
private readonly cache: Map<string, CachedKeyValue>
|
|
13
15
|
private readonly maxCacheSize: number
|
|
14
16
|
|
|
15
17
|
/**
|
|
@@ -47,9 +49,9 @@ export default class CachedKeyDeriver implements KeyDeriverApi {
|
|
|
47
49
|
}
|
|
48
50
|
)
|
|
49
51
|
this.identityKey = this.rootKey.toPublicKey().toString()
|
|
50
|
-
this.cache = new Map<string,
|
|
52
|
+
this.cache = new Map<string, CachedKeyValue>()
|
|
51
53
|
const maxCacheSize = options?.maxCacheSize
|
|
52
|
-
this.maxCacheSize = (maxCacheSize != null && !isNaN(maxCacheSize) && maxCacheSize > 0) ? maxCacheSize : 1000
|
|
54
|
+
this.maxCacheSize = (maxCacheSize != null && !Number.isNaN(maxCacheSize) && maxCacheSize > 0) ? maxCacheSize : 1000
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
/**
|
|
@@ -252,7 +254,7 @@ export default class CachedKeyDeriver implements KeyDeriverApi {
|
|
|
252
254
|
} else if (typeof arg === 'object' && arg !== null) {
|
|
253
255
|
return JSON.stringify(arg)
|
|
254
256
|
} else {
|
|
255
|
-
return String(arg)
|
|
257
|
+
return String(arg as string | number | boolean)
|
|
256
258
|
}
|
|
257
259
|
}
|
|
258
260
|
|
|
@@ -261,7 +263,7 @@ export default class CachedKeyDeriver implements KeyDeriverApi {
|
|
|
261
263
|
* @param {string} cacheKey - The key of the cached item.
|
|
262
264
|
* @returns {any} - The cached value.
|
|
263
265
|
*/
|
|
264
|
-
private cacheGet (cacheKey: string):
|
|
266
|
+
private cacheGet (cacheKey: string): CachedKeyValue | undefined {
|
|
265
267
|
const value = this.cache.get(cacheKey)
|
|
266
268
|
// Update the entry to reflect recent use
|
|
267
269
|
this.cache.delete(cacheKey)
|
|
@@ -276,7 +278,7 @@ export default class CachedKeyDeriver implements KeyDeriverApi {
|
|
|
276
278
|
* @param {string} cacheKey - The key of the item to cache.
|
|
277
279
|
* @param {any} value - The value to cache.
|
|
278
280
|
*/
|
|
279
|
-
private cacheSet (cacheKey: string, value:
|
|
281
|
+
private cacheSet (cacheKey: string, value: CachedKeyValue): void {
|
|
280
282
|
if (this.cache.size >= this.maxCacheSize) {
|
|
281
283
|
// Evict the least recently used item (first item in Map)
|
|
282
284
|
const firstKey = this.cache.keys().next().value
|
package/src/wallet/KeyDeriver.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from '../primitives/index.js'
|
|
9
9
|
import { WalletProtocol, PubKeyHex } from './Wallet.interfaces.js'
|
|
10
10
|
|
|
11
|
-
export type Counterparty = PublicKey | PubKeyHex
|
|
11
|
+
export type Counterparty = PublicKey | PubKeyHex
|
|
12
12
|
|
|
13
13
|
export interface KeyDeriverApi {
|
|
14
14
|
/**
|
|
@@ -216,11 +216,11 @@ export type SecurityLevel = 0 | 1 | 2
|
|
|
216
216
|
|
|
217
217
|
export type WalletProtocol = [SecurityLevel, ProtocolString5To400Bytes]
|
|
218
218
|
|
|
219
|
-
export type WalletCounterparty = PubKeyHex
|
|
219
|
+
export type WalletCounterparty = PubKeyHex
|
|
220
220
|
|
|
221
221
|
export type AcquisitionProtocol = 'direct' | 'issuance'
|
|
222
222
|
|
|
223
|
-
export type KeyringRevealer = PubKeyHex
|
|
223
|
+
export type KeyringRevealer = PubKeyHex
|
|
224
224
|
|
|
225
225
|
export type ActionStatus =
|
|
226
226
|
| 'completed'
|
|
@@ -412,8 +412,23 @@ export interface AbortActionArgs {
|
|
|
412
412
|
reference: Base64String
|
|
413
413
|
}
|
|
414
414
|
|
|
415
|
+
/**
|
|
416
|
+
* Result of an `abortAction` call.
|
|
417
|
+
*
|
|
418
|
+
* `aborted` is informative: `true` indicates the wallet successfully invalidated
|
|
419
|
+
* the action (it will not be broadcast and its inputs are released), `false`
|
|
420
|
+
* indicates the wallet refused to abort because the underlying transaction was
|
|
421
|
+
* found to already be on chain (mined or known to mempool). On a refusal the
|
|
422
|
+
* caller should typically invoke `internalizeAction` instead, which will treat
|
|
423
|
+
* the call as explicit authorization to advance the nosend lifecycle.
|
|
424
|
+
*
|
|
425
|
+
* Note that confirming on-chain status requires network reachability. When
|
|
426
|
+
* confirmation is impossible (services unreachable or returning errors), the
|
|
427
|
+
* wallet proceeds with the abort and returns `aborted: true` rather than
|
|
428
|
+
* refusing — refusal is reserved for positive on-chain confirmation.
|
|
429
|
+
*/
|
|
415
430
|
export interface AbortActionResult {
|
|
416
|
-
aborted:
|
|
431
|
+
aborted: boolean
|
|
417
432
|
}
|
|
418
433
|
|
|
419
434
|
export type AcquireCertificateResult = WalletCertificate
|
|
@@ -935,8 +950,6 @@ export interface DiscoverByAttributesArgs {
|
|
|
935
950
|
seekPermission?: BooleanDefaultTrue
|
|
936
951
|
}
|
|
937
952
|
|
|
938
|
-
// export interface AcquireCertificateResult extends WalletCertificate {}
|
|
939
|
-
|
|
940
953
|
/**
|
|
941
954
|
* Every method of the `Wallet` interface has a return value of the form `Promise<object>`.
|
|
942
955
|
* When errors occur, an exception object may be thrown which must conform to the `WalletErrorObject` interface.
|
|
@@ -131,7 +131,7 @@ export default class WalletClient implements WalletInterface {
|
|
|
131
131
|
const fastResults = await Promise.allSettled(fastAttempts)
|
|
132
132
|
const fastSuccessful = fastResults
|
|
133
133
|
.filter((r): r is PromiseFulfilledResult<{ success: boolean, sub?: WalletInterface }> => r.status === 'fulfilled' && r.value.success && r.value.sub !== undefined)
|
|
134
|
-
.map(r => r.value.sub
|
|
134
|
+
.map(r => r.value.sub)
|
|
135
135
|
|
|
136
136
|
if (fastSuccessful.length > 0) {
|
|
137
137
|
this.substrate = fastSuccessful[0]
|
|
@@ -169,7 +169,7 @@ export default class WalletClient implements WalletInterface {
|
|
|
169
169
|
|
|
170
170
|
async abortAction (args: {
|
|
171
171
|
reference: Base64String
|
|
172
|
-
}): Promise<{ aborted:
|
|
172
|
+
}): Promise<{ aborted: boolean }> {
|
|
173
173
|
validateAbortActionArgs(args)
|
|
174
174
|
await this.connectToSubstrate()
|
|
175
175
|
return await (this.substrate as WalletInterface).abortAction(
|
|
@@ -225,7 +225,7 @@ export default class WalletClient implements WalletInterface {
|
|
|
225
225
|
keyID?: KeyIDStringUnder800Bytes
|
|
226
226
|
privileged?: BooleanDefaultFalse
|
|
227
227
|
privilegedReason?: DescriptionString5to50Bytes
|
|
228
|
-
counterparty?: PubKeyHex
|
|
228
|
+
counterparty?: PubKeyHex
|
|
229
229
|
forSelf?: BooleanDefaultFalse
|
|
230
230
|
}): Promise<{ publicKey: PubKeyHex }> {
|
|
231
231
|
await this.connectToSubstrate()
|
|
@@ -283,7 +283,7 @@ export default class WalletClient implements WalletInterface {
|
|
|
283
283
|
protocolID: [SecurityLevel, ProtocolString5To400Bytes]
|
|
284
284
|
keyID: KeyIDStringUnder800Bytes
|
|
285
285
|
privilegedReason?: DescriptionString5to50Bytes
|
|
286
|
-
counterparty?: PubKeyHex
|
|
286
|
+
counterparty?: PubKeyHex
|
|
287
287
|
privileged?: BooleanDefaultFalse
|
|
288
288
|
}): Promise<{ ciphertext: Byte[] }> {
|
|
289
289
|
await this.connectToSubstrate()
|
|
@@ -298,7 +298,7 @@ export default class WalletClient implements WalletInterface {
|
|
|
298
298
|
protocolID: [SecurityLevel, ProtocolString5To400Bytes]
|
|
299
299
|
keyID: KeyIDStringUnder800Bytes
|
|
300
300
|
privilegedReason?: DescriptionString5to50Bytes
|
|
301
|
-
counterparty?: PubKeyHex
|
|
301
|
+
counterparty?: PubKeyHex
|
|
302
302
|
privileged?: BooleanDefaultFalse
|
|
303
303
|
}): Promise<{ plaintext: Byte[] }> {
|
|
304
304
|
await this.connectToSubstrate()
|
|
@@ -313,7 +313,7 @@ export default class WalletClient implements WalletInterface {
|
|
|
313
313
|
protocolID: [SecurityLevel, ProtocolString5To400Bytes]
|
|
314
314
|
keyID: KeyIDStringUnder800Bytes
|
|
315
315
|
privilegedReason?: DescriptionString5to50Bytes
|
|
316
|
-
counterparty?: PubKeyHex
|
|
316
|
+
counterparty?: PubKeyHex
|
|
317
317
|
privileged?: BooleanDefaultFalse
|
|
318
318
|
}): Promise<{ hmac: Byte[] }> {
|
|
319
319
|
await this.connectToSubstrate()
|
|
@@ -329,7 +329,7 @@ export default class WalletClient implements WalletInterface {
|
|
|
329
329
|
protocolID: [SecurityLevel, ProtocolString5To400Bytes]
|
|
330
330
|
keyID: KeyIDStringUnder800Bytes
|
|
331
331
|
privilegedReason?: DescriptionString5to50Bytes
|
|
332
|
-
counterparty?: PubKeyHex
|
|
332
|
+
counterparty?: PubKeyHex
|
|
333
333
|
privileged?: BooleanDefaultFalse
|
|
334
334
|
}): Promise<{ valid: true }> {
|
|
335
335
|
await this.connectToSubstrate()
|
|
@@ -345,7 +345,7 @@ export default class WalletClient implements WalletInterface {
|
|
|
345
345
|
protocolID: [SecurityLevel, ProtocolString5To400Bytes]
|
|
346
346
|
keyID: KeyIDStringUnder800Bytes
|
|
347
347
|
privilegedReason?: DescriptionString5to50Bytes
|
|
348
|
-
counterparty?: PubKeyHex
|
|
348
|
+
counterparty?: PubKeyHex
|
|
349
349
|
privileged?: BooleanDefaultFalse
|
|
350
350
|
}): Promise<{ signature: Byte[] }> {
|
|
351
351
|
await this.connectToSubstrate()
|
|
@@ -362,7 +362,7 @@ export default class WalletClient implements WalletInterface {
|
|
|
362
362
|
protocolID: [SecurityLevel, ProtocolString5To400Bytes]
|
|
363
363
|
keyID: KeyIDStringUnder800Bytes
|
|
364
364
|
privilegedReason?: DescriptionString5to50Bytes
|
|
365
|
-
counterparty?: PubKeyHex
|
|
365
|
+
counterparty?: PubKeyHex
|
|
366
366
|
forSelf?: BooleanDefaultFalse
|
|
367
367
|
privileged?: BooleanDefaultFalse
|
|
368
368
|
}): Promise<{ valid: true }> {
|
|
@@ -25,7 +25,7 @@ export class WalletError extends Error {
|
|
|
25
25
|
* @returns stringified JSON representation of the error such that it can be deserialized to a WalletError.
|
|
26
26
|
*/
|
|
27
27
|
static unknownToJson (error: any): string {
|
|
28
|
-
let e: any
|
|
28
|
+
let e: any
|
|
29
29
|
if (error.isError === true && String(error.name).startsWith('WERR_')) {
|
|
30
30
|
e = {
|
|
31
31
|
name: error.name,
|
|
@@ -749,11 +749,15 @@ describe('WalletClient.listOutputs – substrate delegation', () => {
|
|
|
749
749
|
|
|
750
750
|
describe('WalletClient.connectToSubstrate – error when no substrate available', () => {
|
|
751
751
|
it('throws a descriptive error when auto-substrate fails to connect', async () => {
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
752
|
+
const fetchSpy = jest.spyOn(globalThis, 'fetch').mockRejectedValue(new Error('No test wallet available'))
|
|
753
|
+
|
|
754
|
+
try {
|
|
755
|
+
const client = new WalletClient('auto', 'test.origin')
|
|
756
|
+
await expect(client.connectToSubstrate()).rejects.toThrow(
|
|
757
|
+
'No wallet available over any communication substrate'
|
|
758
|
+
)
|
|
759
|
+
} finally {
|
|
760
|
+
fetchSpy.mockRestore()
|
|
761
|
+
}
|
|
758
762
|
}, 10000)
|
|
759
763
|
})
|