@bsv/sdk 2.0.16 → 2.1.1
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 +14 -13
- 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 +172 -232
- package/dist/cjs/src/identity/ContactsManager.js.map +1 -1
- package/dist/cjs/src/identity/IdentityClient.js +122 -55
- 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 +139 -46
- 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 +140 -56
- 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/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 +172 -232
- package/dist/esm/src/identity/ContactsManager.js.map +1 -1
- package/dist/esm/src/identity/IdentityClient.js +122 -55
- 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 +139 -46
- 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 +140 -56
- 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/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 +18 -0
- package/dist/types/src/identity/ContactsManager.d.ts.map +1 -1
- package/dist/types/src/identity/IdentityClient.d.ts +47 -8
- 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 +59 -1
- 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 +3 -3
- 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/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 +2 -2
- package/dist/types/src/wallet/Wallet.interfaces.d.ts.map +1 -1
- package/dist/types/src/wallet/WalletClient.d.ts +7 -7
- 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 +8 -8
- 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/docs/reference/kvstore.md +1 -2
- package/docs/reference/primitives.md +0 -1
- package/docs/reference/script.md +0 -7
- package/docs/reference/transaction.md +2 -2
- package/package.json +29 -28
- 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 +194 -257
- package/src/identity/IdentityClient.ts +155 -66
- package/src/identity/__tests/IdentityClient.test.ts +25 -1
- 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 +182 -45
- 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 +152 -53
- 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/TransactionSignature.ts +16 -16
- 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 +2 -4
- package/src/wallet/WalletClient.ts +8 -8
- 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 +10 -10
- package/src/wallet/validationHelpers.ts +9 -9
- package/docs/swagger/dist/LICENSE +0 -21
- package/docs/swagger/dist/favicon-16x16.png +0 -0
- package/docs/swagger/dist/favicon-32x32.png +0 -0
- package/docs/swagger/dist/index.css +0 -16
- package/docs/swagger/dist/oauth2-redirect.html +0 -79
- package/docs/swagger/dist/swagger-initializer.js +0 -20
- package/docs/swagger/dist/swagger-ui-bundle.js +0 -2
- package/docs/swagger/dist/swagger-ui-bundle.js.map +0 -1
- package/docs/swagger/dist/swagger-ui-es-bundle-core.js +0 -3
- package/docs/swagger/dist/swagger-ui-es-bundle-core.js.map +0 -1
- package/docs/swagger/dist/swagger-ui-es-bundle.js +0 -2
- package/docs/swagger/dist/swagger-ui-es-bundle.js.map +0 -1
- package/docs/swagger/dist/swagger-ui-standalone-preset.js +0 -2
- package/docs/swagger/dist/swagger-ui-standalone-preset.js.map +0 -1
- package/docs/swagger/dist/swagger-ui.css +0 -3
- package/docs/swagger/dist/swagger-ui.css.map +0 -1
- package/docs/swagger/dist/swagger-ui.js +0 -2
- package/docs/swagger/dist/swagger-ui.js.map +0 -1
|
@@ -67,14 +67,14 @@ class Mnemonic {
|
|
|
67
67
|
*/
|
|
68
68
|
toBinary() {
|
|
69
69
|
const bw = new utils_js_1.Writer();
|
|
70
|
-
if (this.mnemonic
|
|
70
|
+
if (this.mnemonic === '') {
|
|
71
|
+
bw.writeVarIntNum(0);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
71
74
|
const buf = (0, utils_js_1.toArray)(this.mnemonic, 'utf8');
|
|
72
75
|
bw.writeVarIntNum(buf.length);
|
|
73
76
|
bw.write(buf);
|
|
74
77
|
}
|
|
75
|
-
else {
|
|
76
|
-
bw.writeVarIntNum(0);
|
|
77
|
-
}
|
|
78
78
|
if (this.seed.length > 0) {
|
|
79
79
|
bw.writeVarIntNum(this.seed.length);
|
|
80
80
|
bw.write(this.seed);
|
|
@@ -108,7 +108,7 @@ class Mnemonic {
|
|
|
108
108
|
* @throws {Error} If the bit length is not a multiple of 32 or is less than 128.
|
|
109
109
|
*/
|
|
110
110
|
fromRandom(bits) {
|
|
111
|
-
if (bits === undefined || bits === null || isNaN(bits) || bits === 0) {
|
|
111
|
+
if (bits === undefined || bits === null || Number.isNaN(bits) || bits === 0) {
|
|
112
112
|
bits = 128;
|
|
113
113
|
}
|
|
114
114
|
if (bits % 32 !== 0) {
|
|
@@ -200,8 +200,8 @@ class Mnemonic {
|
|
|
200
200
|
const hash = Hash.sha256(buf);
|
|
201
201
|
let bin = '';
|
|
202
202
|
const bits = buf.length * 8;
|
|
203
|
-
for (
|
|
204
|
-
bin = bin + ('00000000' +
|
|
203
|
+
for (const byte of buf) {
|
|
204
|
+
bin = bin + ('00000000' + byte.toString(2)).slice(-8);
|
|
205
205
|
}
|
|
206
206
|
let hashbits = hash[0].toString(2);
|
|
207
207
|
hashbits = ('00000000' + hashbits).slice(-8).slice(0, bits / 32);
|
|
@@ -215,7 +215,7 @@ class Mnemonic {
|
|
|
215
215
|
if (mnemonic !== '') {
|
|
216
216
|
mnemonic = mnemonic + this.Wordlist.space;
|
|
217
217
|
}
|
|
218
|
-
const wi = parseInt(bin.slice(i * 11, (i + 1) * 11), 2);
|
|
218
|
+
const wi = Number.parseInt(bin.slice(i * 11, (i + 1) * 11), 2);
|
|
219
219
|
mnemonic = mnemonic + this.Wordlist.value[wi];
|
|
220
220
|
}
|
|
221
221
|
this.mnemonic = mnemonic;
|
|
@@ -232,8 +232,8 @@ class Mnemonic {
|
|
|
232
232
|
// confirm no invalid words
|
|
233
233
|
const words = mnemonic.split(this.Wordlist.space);
|
|
234
234
|
let bin = '';
|
|
235
|
-
for (
|
|
236
|
-
const ind = this.Wordlist.value.indexOf(
|
|
235
|
+
for (const word of words) {
|
|
236
|
+
const ind = this.Wordlist.value.indexOf(word);
|
|
237
237
|
if (ind < 0) {
|
|
238
238
|
return false;
|
|
239
239
|
}
|
|
@@ -249,7 +249,7 @@ class Mnemonic {
|
|
|
249
249
|
const nonhashBits = bin.slice(0, bin.length - cs);
|
|
250
250
|
const buf = [];
|
|
251
251
|
for (let i = 0; i < nonhashBits.length / 8; i++) {
|
|
252
|
-
buf.push(parseInt(bin.slice(i * 8, (i + 1) * 8), 2));
|
|
252
|
+
buf.push(Number.parseInt(bin.slice(i * 8, (i + 1) * 8), 2));
|
|
253
253
|
}
|
|
254
254
|
const hash = Hash.sha256(buf.slice(0, nonhashBits.length / 8));
|
|
255
255
|
let expectedHashBits = hash[0].toString(2);
|
|
@@ -271,7 +271,7 @@ class Mnemonic {
|
|
|
271
271
|
throw new Error('Mnemonic does not pass the check - was the mnemonic typed incorrectly? Are there extra spaces?');
|
|
272
272
|
}
|
|
273
273
|
if (typeof passphrase !== 'string') {
|
|
274
|
-
throw new
|
|
274
|
+
throw new TypeError('passphrase must be a string or undefined');
|
|
275
275
|
}
|
|
276
276
|
mnemonic = mnemonic.normalize('NFKD');
|
|
277
277
|
passphrase = passphrase.normalize('NFKD');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Mnemonic.js","sourceRoot":"","sources":["../../../../src/compat/Mnemonic.ts"],"names":[],"mappings":";;;;;;;;;;;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C,CAAA;IACnD,CAAC;CACF;AArSD,2BAqSC"}
|
|
@@ -39,53 +39,55 @@ class ContactsManager {
|
|
|
39
39
|
* @returns A promise that resolves with an array of contacts
|
|
40
40
|
*/
|
|
41
41
|
async getContacts(identityKey, forceRefresh = false, limit = 1000) {
|
|
42
|
-
// Check in-memory cache first unless forcing refresh
|
|
43
42
|
if (!forceRefresh) {
|
|
44
|
-
const
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
const cachedContacts = JSON.parse(cached);
|
|
48
|
-
return identityKey != null
|
|
49
|
-
? cachedContacts.filter(c => c.identityKey === identityKey)
|
|
50
|
-
: cachedContacts;
|
|
51
|
-
}
|
|
52
|
-
catch (e) {
|
|
53
|
-
console.warn('Invalid cached contacts JSON; will reload from chain', e);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
const tags = [];
|
|
58
|
-
if (identityKey != null) {
|
|
59
|
-
// Hash the identity key to use as a tag for quick lookup
|
|
60
|
-
const { hmac: hashedIdentityKey } = await this.wallet.createHmac({
|
|
61
|
-
protocolID: CONTACT_PROTOCOL_ID,
|
|
62
|
-
keyID: identityKey,
|
|
63
|
-
counterparty: 'self',
|
|
64
|
-
data: index_js_2.Utils.toArray(identityKey, 'utf8')
|
|
65
|
-
}, this.originator);
|
|
66
|
-
tags.push(`identityKey ${index_js_2.Utils.toHex(hashedIdentityKey)}`);
|
|
43
|
+
const fromCache = this.loadCachedContacts(identityKey);
|
|
44
|
+
if (fromCache !== null)
|
|
45
|
+
return fromCache;
|
|
67
46
|
}
|
|
68
|
-
|
|
69
|
-
const outputs = await this.wallet.listOutputs({
|
|
70
|
-
basket: 'contacts',
|
|
71
|
-
include: 'locking scripts',
|
|
72
|
-
includeCustomInstructions: true,
|
|
73
|
-
tags,
|
|
74
|
-
limit
|
|
75
|
-
}, this.originator);
|
|
47
|
+
const tags = await this.buildIdentityKeyTags(identityKey);
|
|
48
|
+
const outputs = await this.wallet.listOutputs({ basket: 'contacts', include: 'locking scripts', includeCustomInstructions: true, tags, limit }, this.originator);
|
|
76
49
|
if (outputs.outputs == null || outputs.outputs.length === 0) {
|
|
77
50
|
this.cache.setItem(this.CONTACTS_CACHE_KEY, JSON.stringify([]));
|
|
78
51
|
return [];
|
|
79
52
|
}
|
|
80
|
-
|
|
53
|
+
const contacts = await this.decryptContactOutputs(outputs.outputs);
|
|
54
|
+
this.cache.setItem(this.CONTACTS_CACHE_KEY, JSON.stringify(contacts));
|
|
55
|
+
return identityKey != null ? contacts.filter(c => c.identityKey === identityKey) : contacts;
|
|
56
|
+
}
|
|
57
|
+
/** Returns cached contacts (optionally filtered) or null if cache is missing/invalid. */
|
|
58
|
+
loadCachedContacts(identityKey) {
|
|
59
|
+
const cached = this.cache.getItem(this.CONTACTS_CACHE_KEY);
|
|
60
|
+
if (cached == null || cached === '')
|
|
61
|
+
return null;
|
|
62
|
+
try {
|
|
63
|
+
const cachedContacts = JSON.parse(cached);
|
|
64
|
+
return identityKey != null ? cachedContacts.filter(c => c.identityKey === identityKey) : cachedContacts;
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
console.warn('Invalid cached contacts JSON; will reload from chain', e);
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** Builds the HMAC-based identity-key tag array; empty array if no identity key is given. */
|
|
72
|
+
async buildIdentityKeyTags(identityKey) {
|
|
73
|
+
if (identityKey == null)
|
|
74
|
+
return [];
|
|
75
|
+
const { hmac: hashedIdentityKey } = await this.wallet.createHmac({
|
|
76
|
+
protocolID: CONTACT_PROTOCOL_ID,
|
|
77
|
+
keyID: identityKey,
|
|
78
|
+
counterparty: 'self',
|
|
79
|
+
data: index_js_2.Utils.toArray(identityKey, 'utf8')
|
|
80
|
+
}, this.originator);
|
|
81
|
+
return [`identityKey ${index_js_2.Utils.toHex(hashedIdentityKey)}`];
|
|
82
|
+
}
|
|
83
|
+
/** Decodes and decrypts all contact outputs in parallel, returning valid Contact objects. */
|
|
84
|
+
async decryptContactOutputs(rawOutputs) {
|
|
81
85
|
const decryptTasks = [];
|
|
82
|
-
for (const output of
|
|
86
|
+
for (const output of rawOutputs) {
|
|
83
87
|
try {
|
|
84
|
-
if (output.lockingScript == null)
|
|
88
|
+
if (output.lockingScript == null || output.customInstructions == null)
|
|
85
89
|
continue;
|
|
86
90
|
const decoded = index_js_3.PushDrop.decode(index_js_3.LockingScript.fromHex(output.lockingScript));
|
|
87
|
-
if (output.customInstructions == null)
|
|
88
|
-
continue;
|
|
89
91
|
const keyID = JSON.parse(output.customInstructions).keyID;
|
|
90
92
|
decryptTasks.push({ keyID, ciphertext: decoded.fields[0] });
|
|
91
93
|
}
|
|
@@ -93,20 +95,12 @@ class ContactsManager {
|
|
|
93
95
|
console.warn('ContactsManager: Failed to decode contact output:', error);
|
|
94
96
|
}
|
|
95
97
|
}
|
|
96
|
-
|
|
97
|
-
const decryptResults = await Promise.allSettled(decryptTasks.map(async (task) => await this.wallet.decrypt({
|
|
98
|
-
ciphertext: task.ciphertext,
|
|
99
|
-
protocolID: CONTACT_PROTOCOL_ID,
|
|
100
|
-
keyID: task.keyID,
|
|
101
|
-
counterparty: 'self'
|
|
102
|
-
}, this.originator)));
|
|
98
|
+
const decryptResults = await Promise.allSettled(decryptTasks.map(async (task) => await this.wallet.decrypt({ ciphertext: task.ciphertext, protocolID: CONTACT_PROTOCOL_ID, keyID: task.keyID, counterparty: 'self' }, this.originator)));
|
|
103
99
|
const contacts = [];
|
|
104
|
-
for (
|
|
105
|
-
const result = decryptResults[i];
|
|
100
|
+
for (const result of decryptResults) {
|
|
106
101
|
if (result.status === 'fulfilled') {
|
|
107
102
|
try {
|
|
108
|
-
|
|
109
|
-
contacts.push(contactData);
|
|
103
|
+
contacts.push(JSON.parse(index_js_2.Utils.toUTF8(result.value.plaintext)));
|
|
110
104
|
}
|
|
111
105
|
catch (error) {
|
|
112
106
|
console.warn('ContactsManager: Failed to parse contact data:', error);
|
|
@@ -116,12 +110,7 @@ class ContactsManager {
|
|
|
116
110
|
console.warn('ContactsManager: Failed to decrypt contact output:', result.reason);
|
|
117
111
|
}
|
|
118
112
|
}
|
|
119
|
-
|
|
120
|
-
this.cache.setItem(this.CONTACTS_CACHE_KEY, JSON.stringify(contacts));
|
|
121
|
-
const filteredContacts = identityKey != null
|
|
122
|
-
? contacts.filter(c => c.identityKey === identityKey)
|
|
123
|
-
: contacts;
|
|
124
|
-
return filteredContacts;
|
|
113
|
+
return contacts;
|
|
125
114
|
}
|
|
126
115
|
/**
|
|
127
116
|
* Save or update a Metanet contact
|
|
@@ -129,136 +118,110 @@ class ContactsManager {
|
|
|
129
118
|
* @param metadata Optional metadata to store with the contact (ex. notes, aliases, etc)
|
|
130
119
|
*/
|
|
131
120
|
async saveContact(contact, metadata) {
|
|
132
|
-
// Get current contacts from cache or blockchain
|
|
133
121
|
const cached = this.cache.getItem(this.CONTACTS_CACHE_KEY);
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
contacts = JSON.parse(cached);
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
// If cache is empty, get current data from blockchain
|
|
140
|
-
contacts = await this.getContacts();
|
|
141
|
-
}
|
|
122
|
+
const contacts = (cached != null && cached !== '') ? JSON.parse(cached) : await this.getContacts();
|
|
123
|
+
const contactToStore = { ...contact, metadata };
|
|
142
124
|
const existingIndex = contacts.findIndex(c => c.identityKey === contact.identityKey);
|
|
143
|
-
|
|
144
|
-
...contact,
|
|
145
|
-
metadata
|
|
146
|
-
};
|
|
147
|
-
if (existingIndex >= 0) {
|
|
125
|
+
if (existingIndex >= 0)
|
|
148
126
|
contacts[existingIndex] = contactToStore;
|
|
127
|
+
else
|
|
128
|
+
contacts.push(contactToStore);
|
|
129
|
+
const hashedIdentityKey = await this.hashIdentityKey(contact.identityKey);
|
|
130
|
+
const outputs = await this.wallet.listOutputs({
|
|
131
|
+
basket: 'contacts', include: 'entire transactions', includeCustomInstructions: true,
|
|
132
|
+
tags: [`identityKey ${index_js_2.Utils.toHex(hashedIdentityKey)}`], limit: 100
|
|
133
|
+
}, this.originator);
|
|
134
|
+
const { existingOutput, keyID } = await this.findExistingOutput(outputs, contact.identityKey);
|
|
135
|
+
const lockingScript = await this.encryptAndLock(contactToStore, keyID);
|
|
136
|
+
if (existingOutput != null) {
|
|
137
|
+
await this.updateContactOutput(outputs, existingOutput, lockingScript, keyID, hashedIdentityKey, contact);
|
|
149
138
|
}
|
|
150
139
|
else {
|
|
151
|
-
|
|
140
|
+
await this.createContactOutput(lockingScript, keyID, hashedIdentityKey, contact);
|
|
152
141
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const outputs = await this.wallet.listOutputs({
|
|
161
|
-
basket: 'contacts',
|
|
162
|
-
include: 'entire transactions',
|
|
163
|
-
includeCustomInstructions: true,
|
|
164
|
-
tags: [`identityKey ${index_js_2.Utils.toHex(hashedIdentityKey)}`],
|
|
165
|
-
limit: 100 // Should only be one contact!
|
|
142
|
+
this.cache.setItem(this.CONTACTS_CACHE_KEY, JSON.stringify(contacts));
|
|
143
|
+
}
|
|
144
|
+
/** Computes the HMAC-based hash of an identity key for tag indexing. */
|
|
145
|
+
async hashIdentityKey(identityKey) {
|
|
146
|
+
const { hmac } = await this.wallet.createHmac({
|
|
147
|
+
protocolID: CONTACT_PROTOCOL_ID, keyID: identityKey, counterparty: 'self',
|
|
148
|
+
data: index_js_2.Utils.toArray(identityKey, 'utf8')
|
|
166
149
|
}, this.originator);
|
|
150
|
+
return hmac;
|
|
151
|
+
}
|
|
152
|
+
/** Scans existing outputs to find the one matching the given identity key; returns output + keyID. */
|
|
153
|
+
async findExistingOutput(outputs, identityKey) {
|
|
167
154
|
let existingOutput = null;
|
|
168
155
|
let keyID = index_js_2.Utils.toBase64((0, index_js_2.Random)(32));
|
|
169
|
-
if (outputs.outputs
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}, this.originator);
|
|
185
|
-
const storedContact = JSON.parse(index_js_2.Utils.toUTF8(plaintext));
|
|
186
|
-
if (storedContact.identityKey === contact.identityKey) {
|
|
187
|
-
// Found the right output
|
|
188
|
-
existingOutput = output;
|
|
189
|
-
break;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
catch (e) {
|
|
193
|
-
// Skip malformed or undecryptable outputs
|
|
156
|
+
if (outputs.outputs == null)
|
|
157
|
+
return { existingOutput, keyID };
|
|
158
|
+
for (const output of outputs.outputs) {
|
|
159
|
+
try {
|
|
160
|
+
const [txid, outputIndex] = output.outpoint.split('.');
|
|
161
|
+
const tx = index_js_4.Transaction.fromBEEF(outputs.BEEF, txid);
|
|
162
|
+
const decoded = index_js_3.PushDrop.decode(tx.outputs[Number(outputIndex)].lockingScript);
|
|
163
|
+
if (output.customInstructions == null)
|
|
164
|
+
continue;
|
|
165
|
+
keyID = JSON.parse(output.customInstructions).keyID;
|
|
166
|
+
const { plaintext } = await this.wallet.decrypt({ ciphertext: decoded.fields[0], protocolID: CONTACT_PROTOCOL_ID, keyID, counterparty: 'self' }, this.originator);
|
|
167
|
+
const storedContact = JSON.parse(index_js_2.Utils.toUTF8(plaintext));
|
|
168
|
+
if (storedContact.identityKey === identityKey) {
|
|
169
|
+
existingOutput = output;
|
|
170
|
+
break;
|
|
194
171
|
}
|
|
195
172
|
}
|
|
173
|
+
catch (_malformedOrUndecryptableOutput) { /* skip */ }
|
|
196
174
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
};
|
|
175
|
+
return { existingOutput, keyID };
|
|
176
|
+
}
|
|
177
|
+
/** Encrypts a contact and produces its PushDrop locking script. */
|
|
178
|
+
async encryptAndLock(contactData, keyID) {
|
|
202
179
|
const { ciphertext } = await this.wallet.encrypt({
|
|
203
|
-
plaintext: index_js_2.Utils.toArray(JSON.stringify(
|
|
204
|
-
protocolID: CONTACT_PROTOCOL_ID,
|
|
205
|
-
keyID,
|
|
206
|
-
counterparty: 'self'
|
|
180
|
+
plaintext: index_js_2.Utils.toArray(JSON.stringify(contactData), 'utf8'),
|
|
181
|
+
protocolID: CONTACT_PROTOCOL_ID, keyID, counterparty: 'self'
|
|
207
182
|
}, this.originator);
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}],
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
satoshis: 1,
|
|
251
|
-
lockingScript: lockingScript.toHex(),
|
|
252
|
-
outputDescription: `Contact: ${contact.name ?? contact.identityKey.slice(0, 10)}`,
|
|
253
|
-
tags: [`identityKey ${index_js_2.Utils.toHex(hashedIdentityKey)}`],
|
|
254
|
-
customInstructions: JSON.stringify({ keyID })
|
|
255
|
-
}],
|
|
256
|
-
options: { acceptDelayedBroadcast: false, randomizeOutputs: false } // TODO: Support custom config as needed.
|
|
257
|
-
}, this.originator);
|
|
258
|
-
if (tx == null)
|
|
259
|
-
throw new Error('Failed to create contact output');
|
|
260
|
-
}
|
|
261
|
-
this.cache.setItem(this.CONTACTS_CACHE_KEY, JSON.stringify(contacts));
|
|
183
|
+
return await new index_js_3.PushDrop(this.wallet, this.originator).lock([ciphertext], CONTACT_PROTOCOL_ID, keyID, 'self');
|
|
184
|
+
}
|
|
185
|
+
/** Spends an existing contact output and creates a replacement with updated data. */
|
|
186
|
+
async updateContactOutput(outputs, existingOutput, lockingScript, keyID, hashedIdentityKey, contact) {
|
|
187
|
+
const [txid, outputIndex] = String(existingOutput.outpoint).split('.');
|
|
188
|
+
const prevOutpoint = `${txid}.${outputIndex}`;
|
|
189
|
+
const pushdrop = new index_js_3.PushDrop(this.wallet, this.originator);
|
|
190
|
+
const { signableTransaction } = await this.wallet.createAction({
|
|
191
|
+
description: 'Update Contact',
|
|
192
|
+
inputBEEF: outputs.BEEF,
|
|
193
|
+
inputs: [{ outpoint: prevOutpoint, unlockingScriptLength: 74, inputDescription: 'Spend previous contact output' }],
|
|
194
|
+
outputs: [{
|
|
195
|
+
basket: 'contacts', satoshis: 1, lockingScript: lockingScript.toHex(),
|
|
196
|
+
outputDescription: `Updated Contact: ${contact.name ?? contact.identityKey.slice(0, 10)}`,
|
|
197
|
+
tags: [`identityKey ${index_js_2.Utils.toHex(hashedIdentityKey)}`], customInstructions: JSON.stringify({ keyID })
|
|
198
|
+
}],
|
|
199
|
+
options: { acceptDelayedBroadcast: false, randomizeOutputs: false }
|
|
200
|
+
}, this.originator);
|
|
201
|
+
if (signableTransaction == null)
|
|
202
|
+
throw new Error('Unable to update contact');
|
|
203
|
+
const unlockingScript = await pushdrop.unlock(CONTACT_PROTOCOL_ID, keyID, 'self')
|
|
204
|
+
.sign(index_js_4.Transaction.fromBEEF(signableTransaction.tx), 0);
|
|
205
|
+
const { tx } = await this.wallet.signAction({
|
|
206
|
+
reference: signableTransaction.reference,
|
|
207
|
+
spends: { 0: { unlockingScript: unlockingScript.toHex() } }
|
|
208
|
+
}, this.originator);
|
|
209
|
+
if (tx == null)
|
|
210
|
+
throw new Error('Failed to update contact output');
|
|
211
|
+
}
|
|
212
|
+
/** Creates a new on-chain contact output. */
|
|
213
|
+
async createContactOutput(lockingScript, keyID, hashedIdentityKey, contact) {
|
|
214
|
+
const { tx } = await this.wallet.createAction({
|
|
215
|
+
description: 'Add Contact',
|
|
216
|
+
outputs: [{
|
|
217
|
+
basket: 'contacts', satoshis: 1, lockingScript: lockingScript.toHex(),
|
|
218
|
+
outputDescription: `Contact: ${contact.name ?? contact.identityKey.slice(0, 10)}`,
|
|
219
|
+
tags: [`identityKey ${index_js_2.Utils.toHex(hashedIdentityKey)}`], customInstructions: JSON.stringify({ keyID })
|
|
220
|
+
}],
|
|
221
|
+
options: { acceptDelayedBroadcast: false, randomizeOutputs: false }
|
|
222
|
+
}, this.originator);
|
|
223
|
+
if (tx == null)
|
|
224
|
+
throw new Error('Failed to create contact output');
|
|
262
225
|
}
|
|
263
226
|
/**
|
|
264
227
|
* Remove a contact from the contacts basket
|
|
@@ -270,81 +233,58 @@ class ContactsManager {
|
|
|
270
233
|
if (cached != null && cached !== '') {
|
|
271
234
|
try {
|
|
272
235
|
const contacts = JSON.parse(cached);
|
|
273
|
-
|
|
274
|
-
this.cache.setItem(this.CONTACTS_CACHE_KEY, JSON.stringify(filteredContacts));
|
|
236
|
+
this.cache.setItem(this.CONTACTS_CACHE_KEY, JSON.stringify(contacts.filter(c => c.identityKey !== identityKey)));
|
|
275
237
|
}
|
|
276
238
|
catch (e) {
|
|
277
239
|
console.warn('Failed to update cache after contact removal:', e);
|
|
278
240
|
}
|
|
279
241
|
}
|
|
280
|
-
|
|
281
|
-
const
|
|
282
|
-
const { hmac: hashedIdentityKey } = await this.wallet.createHmac({
|
|
283
|
-
protocolID: CONTACT_PROTOCOL_ID,
|
|
284
|
-
keyID: identityKey,
|
|
285
|
-
counterparty: 'self',
|
|
286
|
-
data: index_js_2.Utils.toArray(identityKey, 'utf8')
|
|
287
|
-
}, this.originator);
|
|
288
|
-
tags.push(`identityKey ${index_js_2.Utils.toHex(hashedIdentityKey)}`);
|
|
289
|
-
// Find and spend the contact's output
|
|
290
|
-
const outputs = await this.wallet.listOutputs({
|
|
291
|
-
basket: 'contacts',
|
|
292
|
-
include: 'entire transactions',
|
|
293
|
-
includeCustomInstructions: true,
|
|
294
|
-
tags,
|
|
295
|
-
limit: 100 // Should only be one contact!
|
|
296
|
-
}, this.originator);
|
|
242
|
+
const tags = await this.buildIdentityKeyTags(identityKey);
|
|
243
|
+
const outputs = await this.wallet.listOutputs({ basket: 'contacts', include: 'entire transactions', includeCustomInstructions: true, tags, limit: 100 }, this.originator);
|
|
297
244
|
if (outputs.outputs == null)
|
|
298
245
|
return;
|
|
299
|
-
// Find the output for this specific contact by decrypting and checking identityKey
|
|
300
246
|
for (const output of outputs.outputs) {
|
|
301
247
|
try {
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
const decoded = index_js_3.PushDrop.decode(tx.outputs[Number(outputIndex)].lockingScript);
|
|
305
|
-
if (output.customInstructions == null)
|
|
306
|
-
continue;
|
|
307
|
-
const keyID = JSON.parse(output.customInstructions).keyID;
|
|
308
|
-
const { plaintext } = await this.wallet.decrypt({
|
|
309
|
-
ciphertext: decoded.fields[0],
|
|
310
|
-
protocolID: CONTACT_PROTOCOL_ID,
|
|
311
|
-
keyID,
|
|
312
|
-
counterparty: 'self'
|
|
313
|
-
}, this.originator);
|
|
314
|
-
const storedContact = JSON.parse(index_js_2.Utils.toUTF8(plaintext));
|
|
315
|
-
if (storedContact.identityKey === identityKey) {
|
|
316
|
-
// Found the contact's output, spend it without creating a new one
|
|
317
|
-
const prevOutpoint = `${txid}.${outputIndex}`;
|
|
318
|
-
const pushdrop = new index_js_3.PushDrop(this.wallet, this.originator);
|
|
319
|
-
const { signableTransaction } = await this.wallet.createAction({
|
|
320
|
-
description: 'Delete Contact',
|
|
321
|
-
inputBEEF: outputs.BEEF,
|
|
322
|
-
inputs: [{
|
|
323
|
-
outpoint: prevOutpoint,
|
|
324
|
-
unlockingScriptLength: 74,
|
|
325
|
-
inputDescription: 'Spend contact output to delete'
|
|
326
|
-
}],
|
|
327
|
-
outputs: [], // No outputs = deletion
|
|
328
|
-
options: { acceptDelayedBroadcast: false, randomizeOutputs: false } // TODO: Support custom config as needed.
|
|
329
|
-
}, this.originator);
|
|
330
|
-
if (signableTransaction == null)
|
|
331
|
-
throw new Error('Unable to delete contact');
|
|
332
|
-
const unlocker = pushdrop.unlock(CONTACT_PROTOCOL_ID, keyID, 'self');
|
|
333
|
-
const unlockingScript = await unlocker.sign(index_js_4.Transaction.fromBEEF(signableTransaction.tx), 0);
|
|
334
|
-
const { tx: deleteTx } = await this.wallet.signAction({
|
|
335
|
-
reference: signableTransaction.reference,
|
|
336
|
-
spends: { 0: { unlockingScript: unlockingScript.toHex() } }
|
|
337
|
-
}, this.originator);
|
|
338
|
-
if (deleteTx == null)
|
|
339
|
-
throw new Error('Failed to delete contact output');
|
|
248
|
+
const spent = await this.trySpendContactOutput(output, outputs, identityKey);
|
|
249
|
+
if (spent)
|
|
340
250
|
return;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
catch (e) {
|
|
344
|
-
// Skip malformed or undecryptable outputs
|
|
345
251
|
}
|
|
252
|
+
catch (_malformedOrUndecryptableOutput) { /* skip */ }
|
|
346
253
|
}
|
|
347
254
|
}
|
|
255
|
+
/** Attempts to decrypt and spend a single output if it matches the given identity key. Returns true if spent. */
|
|
256
|
+
async trySpendContactOutput(output, outputs, identityKey) {
|
|
257
|
+
const [txid, outputIndex] = String(output.outpoint).split('.');
|
|
258
|
+
const tx = index_js_4.Transaction.fromBEEF(outputs.BEEF, txid);
|
|
259
|
+
const decoded = index_js_3.PushDrop.decode(tx.outputs[Number(outputIndex)].lockingScript);
|
|
260
|
+
if (output.customInstructions == null)
|
|
261
|
+
return false;
|
|
262
|
+
const keyID = JSON.parse(output.customInstructions).keyID;
|
|
263
|
+
const { plaintext } = await this.wallet.decrypt({ ciphertext: decoded.fields[0], protocolID: CONTACT_PROTOCOL_ID, keyID, counterparty: 'self' }, this.originator);
|
|
264
|
+
const storedContact = JSON.parse(index_js_2.Utils.toUTF8(plaintext));
|
|
265
|
+
if (storedContact.identityKey !== identityKey)
|
|
266
|
+
return false;
|
|
267
|
+
const prevOutpoint = `${txid}.${outputIndex}`;
|
|
268
|
+
const pushdrop = new index_js_3.PushDrop(this.wallet, this.originator);
|
|
269
|
+
const { signableTransaction } = await this.wallet.createAction({
|
|
270
|
+
description: 'Delete Contact',
|
|
271
|
+
inputBEEF: outputs.BEEF,
|
|
272
|
+
inputs: [{ outpoint: prevOutpoint, unlockingScriptLength: 74, inputDescription: 'Spend contact output to delete' }],
|
|
273
|
+
outputs: [],
|
|
274
|
+
options: { acceptDelayedBroadcast: false, randomizeOutputs: false }
|
|
275
|
+
}, this.originator);
|
|
276
|
+
if (signableTransaction == null)
|
|
277
|
+
throw new Error('Unable to delete contact');
|
|
278
|
+
const unlockingScript = await pushdrop.unlock(CONTACT_PROTOCOL_ID, keyID, 'self')
|
|
279
|
+
.sign(index_js_4.Transaction.fromBEEF(signableTransaction.tx), 0);
|
|
280
|
+
const { tx: deleteTx } = await this.wallet.signAction({
|
|
281
|
+
reference: signableTransaction.reference,
|
|
282
|
+
spends: { 0: { unlockingScript: unlockingScript.toHex() } }
|
|
283
|
+
}, this.originator);
|
|
284
|
+
if (deleteTx == null)
|
|
285
|
+
throw new Error('Failed to delete contact output');
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
348
288
|
}
|
|
349
289
|
exports.ContactsManager = ContactsManager;
|
|
350
290
|
//# sourceMappingURL=ContactsManager.js.map
|