@bsv/sdk 2.1.0 → 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 +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 +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/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 +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
|
@@ -12,11 +12,11 @@ export default class XDMSubstrate extends InvokableWalletBase {
|
|
|
12
12
|
|
|
13
13
|
constructor(domain: string = '*') {
|
|
14
14
|
super()
|
|
15
|
-
if (typeof window !== 'object') {
|
|
16
|
-
throw new
|
|
15
|
+
if (typeof globalThis.window !== 'object') {
|
|
16
|
+
throw new TypeError('The XDM substrate requires a global window object.')
|
|
17
17
|
}
|
|
18
|
-
if (typeof window.postMessage !== 'function') {
|
|
19
|
-
throw new
|
|
18
|
+
if (typeof globalThis.window.postMessage !== 'function') {
|
|
19
|
+
throw new TypeError(
|
|
20
20
|
'The window object does not seem to support postMessage calls.'
|
|
21
21
|
)
|
|
22
22
|
}
|
|
@@ -7,6 +7,10 @@ import { WERR_REVIEW_ACTIONS } from '../../WERR_REVIEW_ACTIONS'
|
|
|
7
7
|
// Helpers
|
|
8
8
|
// ---------------------------------------------------------------------------
|
|
9
9
|
|
|
10
|
+
const TEST_ORIGINATOR = 'example.com'
|
|
11
|
+
const TEST_ORIGIN_HEADER = 'http://example.com'
|
|
12
|
+
const BASE_URL = 'http://localhost:3321'
|
|
13
|
+
|
|
10
14
|
/** Build a minimal fetch mock that resolves with a JSON-shaped Response. */
|
|
11
15
|
function makeFetch(
|
|
12
16
|
body: unknown,
|
|
@@ -24,19 +28,23 @@ function makeNetworkErrorFetch(message = 'Network failure'): jest.Mock {
|
|
|
24
28
|
return jest.fn().mockRejectedValue(new Error(message))
|
|
25
29
|
}
|
|
26
30
|
|
|
31
|
+
function makeClient(mockFetch: jest.Mock): HTTPWalletJSON {
|
|
32
|
+
return new HTTPWalletJSON(TEST_ORIGINATOR, BASE_URL, mockFetch as unknown as typeof fetch)
|
|
33
|
+
}
|
|
34
|
+
|
|
27
35
|
// ---------------------------------------------------------------------------
|
|
28
36
|
// Constructor
|
|
29
37
|
// ---------------------------------------------------------------------------
|
|
30
38
|
|
|
31
39
|
describe('HTTPWalletJSON – constructor', () => {
|
|
32
40
|
it('stores the provided baseUrl', () => {
|
|
33
|
-
const client = new HTTPWalletJSON(
|
|
41
|
+
const client = new HTTPWalletJSON(TEST_ORIGINATOR, 'http://my-server:9000')
|
|
34
42
|
expect(client.baseUrl).toBe('http://my-server:9000')
|
|
35
43
|
})
|
|
36
44
|
|
|
37
45
|
it('uses http://localhost:3321 as the default baseUrl', () => {
|
|
38
|
-
const client = new HTTPWalletJSON(
|
|
39
|
-
expect(client.baseUrl).toBe(
|
|
46
|
+
const client = new HTTPWalletJSON(TEST_ORIGINATOR)
|
|
47
|
+
expect(client.baseUrl).toBe(BASE_URL)
|
|
40
48
|
})
|
|
41
49
|
|
|
42
50
|
it('stores the originator', () => {
|
|
@@ -44,14 +52,9 @@ describe('HTTPWalletJSON – constructor', () => {
|
|
|
44
52
|
expect(client.originator).toBe('wallet.example.com')
|
|
45
53
|
})
|
|
46
54
|
|
|
47
|
-
it('accepts undefined originator', () => {
|
|
48
|
-
const client = new HTTPWalletJSON(undefined)
|
|
49
|
-
expect(client.originator).toBeUndefined()
|
|
50
|
-
})
|
|
51
|
-
|
|
52
55
|
it('stores the custom httpClient', () => {
|
|
53
56
|
const mockFetch = jest.fn()
|
|
54
|
-
const client = new HTTPWalletJSON(
|
|
57
|
+
const client = new HTTPWalletJSON(TEST_ORIGINATOR, BASE_URL, mockFetch as unknown as typeof fetch)
|
|
55
58
|
expect(client.httpClient).toBe(mockFetch)
|
|
56
59
|
})
|
|
57
60
|
})
|
|
@@ -63,13 +66,13 @@ describe('HTTPWalletJSON – constructor', () => {
|
|
|
63
66
|
describe('HTTPWalletJSON – api() successful responses', () => {
|
|
64
67
|
it('POSTs to the correct URL and returns the parsed body', async () => {
|
|
65
68
|
const mockFetch = makeFetch({ version: '1.0.0.0.0.0.0' })
|
|
66
|
-
const client =
|
|
69
|
+
const client = makeClient(mockFetch)
|
|
67
70
|
|
|
68
71
|
const result = await client.getVersion({})
|
|
69
72
|
|
|
70
73
|
expect(mockFetch).toHaveBeenCalledTimes(1)
|
|
71
74
|
const [url, init] = mockFetch.mock.calls[0] as [string, RequestInit]
|
|
72
|
-
expect(url).toBe(
|
|
75
|
+
expect(url).toBe(`${BASE_URL}/getVersion`)
|
|
73
76
|
expect(init.method).toBe('POST')
|
|
74
77
|
expect(JSON.parse(init.body as string)).toEqual({})
|
|
75
78
|
expect(result).toEqual({ version: '1.0.0.0.0.0.0' })
|
|
@@ -77,7 +80,7 @@ describe('HTTPWalletJSON – api() successful responses', () => {
|
|
|
77
80
|
|
|
78
81
|
it('sets Accept and Content-Type headers', async () => {
|
|
79
82
|
const mockFetch = makeFetch({ height: 800000 })
|
|
80
|
-
const client =
|
|
83
|
+
const client = makeClient(mockFetch)
|
|
81
84
|
|
|
82
85
|
await client.getHeight({})
|
|
83
86
|
|
|
@@ -85,17 +88,27 @@ describe('HTTPWalletJSON – api() successful responses', () => {
|
|
|
85
88
|
const headers = init.headers as Record<string, string>
|
|
86
89
|
expect(headers['Accept']).toBe('application/json')
|
|
87
90
|
expect(headers['Content-Type']).toBe('application/json')
|
|
91
|
+
expect(headers['Origin']).toBe(TEST_ORIGIN_HEADER)
|
|
92
|
+
expect(headers['Originator']).toBe(TEST_ORIGIN_HEADER)
|
|
88
93
|
})
|
|
89
94
|
|
|
90
95
|
it('serialises args as JSON in the request body', async () => {
|
|
91
96
|
const mockFetch = makeFetch({ actions: [], totalActions: 0 })
|
|
92
|
-
const client =
|
|
97
|
+
const client = makeClient(mockFetch)
|
|
93
98
|
|
|
94
99
|
await client.listActions({ labels: ['test-label'] })
|
|
95
100
|
|
|
96
101
|
const [, init] = mockFetch.mock.calls[0] as [string, RequestInit]
|
|
97
102
|
expect(JSON.parse(init.body as string)).toEqual({ labels: ['test-label'] })
|
|
98
103
|
})
|
|
104
|
+
|
|
105
|
+
it('throws before making a request in Node when originator is missing', async () => {
|
|
106
|
+
const mockFetch = makeFetch({ version: '1.0.0.0.0.0.0' })
|
|
107
|
+
const client = new HTTPWalletJSON(undefined, BASE_URL, mockFetch as unknown as typeof fetch)
|
|
108
|
+
|
|
109
|
+
await expect(client.getVersion({})).rejects.toThrow('HTTPWalletJSON: originator is required')
|
|
110
|
+
expect(mockFetch).not.toHaveBeenCalled()
|
|
111
|
+
})
|
|
99
112
|
})
|
|
100
113
|
|
|
101
114
|
// ---------------------------------------------------------------------------
|
|
@@ -111,7 +124,7 @@ describe('HTTPWalletJSON – api() error responses', () => {
|
|
|
111
124
|
message: 'The description parameter must be at least 5 length.',
|
|
112
125
|
}
|
|
113
126
|
const mockFetch = makeFetch(errorBody, { ok: false, status: 400 })
|
|
114
|
-
const client =
|
|
127
|
+
const client = makeClient(mockFetch)
|
|
115
128
|
|
|
116
129
|
await expect(client.createAction({ description: 'x' })).rejects.toThrow(WERR_INVALID_PARAMETER)
|
|
117
130
|
|
|
@@ -133,7 +146,7 @@ describe('HTTPWalletJSON – api() error responses', () => {
|
|
|
133
146
|
message: 'Custom server message for lockingScript.',
|
|
134
147
|
}
|
|
135
148
|
const mockFetch = makeFetch(errorBody, { ok: false, status: 400 })
|
|
136
|
-
const client =
|
|
149
|
+
const client = makeClient(mockFetch)
|
|
137
150
|
|
|
138
151
|
try {
|
|
139
152
|
await client.createAction({ description: 'hello world' })
|
|
@@ -151,7 +164,7 @@ describe('HTTPWalletJSON – api() error responses', () => {
|
|
|
151
164
|
moreSatoshisNeeded: 2000,
|
|
152
165
|
}
|
|
153
166
|
const mockFetch = makeFetch(errorBody, { ok: false, status: 400 })
|
|
154
|
-
const client =
|
|
167
|
+
const client = makeClient(mockFetch)
|
|
155
168
|
|
|
156
169
|
await expect(client.createAction({ description: 'hello world' })).rejects.toThrow(WERR_INSUFFICIENT_FUNDS)
|
|
157
170
|
|
|
@@ -174,7 +187,7 @@ describe('HTTPWalletJSON – api() error responses', () => {
|
|
|
174
187
|
txid: 'abc123',
|
|
175
188
|
}
|
|
176
189
|
const mockFetch = makeFetch(errorBody, { ok: false, status: 400 })
|
|
177
|
-
const client =
|
|
190
|
+
const client = makeClient(mockFetch)
|
|
178
191
|
|
|
179
192
|
await expect(client.createAction({ description: 'hello world' })).rejects.toThrow(WERR_REVIEW_ACTIONS)
|
|
180
193
|
|
|
@@ -190,7 +203,7 @@ describe('HTTPWalletJSON – api() error responses', () => {
|
|
|
190
203
|
|
|
191
204
|
it('throws a generic Error when the server returns a non-400 error status', async () => {
|
|
192
205
|
const mockFetch = makeFetch({ message: 'Internal Server Error' }, { ok: false, status: 500 })
|
|
193
|
-
const client =
|
|
206
|
+
const client = makeClient(mockFetch)
|
|
194
207
|
|
|
195
208
|
await expect(client.getVersion({})).rejects.toThrow(Error)
|
|
196
209
|
|
|
@@ -205,7 +218,7 @@ describe('HTTPWalletJSON – api() error responses', () => {
|
|
|
205
218
|
|
|
206
219
|
it('falls back to "HTTP Client error <status>" when the 500 body has no message', async () => {
|
|
207
220
|
const mockFetch = makeFetch({}, { ok: false, status: 503 })
|
|
208
|
-
const client =
|
|
221
|
+
const client = makeClient(mockFetch)
|
|
209
222
|
|
|
210
223
|
try {
|
|
211
224
|
await client.getVersion({})
|
|
@@ -219,7 +232,7 @@ describe('HTTPWalletJSON – api() error responses', () => {
|
|
|
219
232
|
// code 99 is unrecognised – falls through to the generic error path
|
|
220
233
|
const errorBody = { isError: true, code: 99, message: 'Unknown problem' }
|
|
221
234
|
const mockFetch = makeFetch(errorBody, { ok: false, status: 400 })
|
|
222
|
-
const client =
|
|
235
|
+
const client = makeClient(mockFetch)
|
|
223
236
|
|
|
224
237
|
await expect(client.getVersion({})).rejects.toThrow(Error)
|
|
225
238
|
})
|
|
@@ -232,7 +245,7 @@ describe('HTTPWalletJSON – api() error responses', () => {
|
|
|
232
245
|
describe('HTTPWalletJSON – network errors', () => {
|
|
233
246
|
it('propagates a fetch rejection as-is', async () => {
|
|
234
247
|
const mockFetch = makeNetworkErrorFetch('Failed to fetch')
|
|
235
|
-
const client =
|
|
248
|
+
const client = makeClient(mockFetch)
|
|
236
249
|
|
|
237
250
|
await expect(client.getVersion({})).rejects.toThrow('Failed to fetch')
|
|
238
251
|
})
|
|
@@ -248,7 +261,7 @@ describe('HTTPWalletJSON – method routing', () => {
|
|
|
248
261
|
|
|
249
262
|
beforeEach(() => {
|
|
250
263
|
mockFetch = makeFetch({})
|
|
251
|
-
client =
|
|
264
|
+
client = makeClient(mockFetch)
|
|
252
265
|
})
|
|
253
266
|
|
|
254
267
|
const expectCallName = async (method: () => Promise<unknown>, expectedPath: string) => {
|
|
@@ -470,7 +483,7 @@ describe('HTTPWalletJSON – response body passthrough', () => {
|
|
|
470
483
|
it('returns the exact JSON body from a successful getVersion call', async () => {
|
|
471
484
|
const expected = { version: '1.0.0.0.0.0.0' }
|
|
472
485
|
const mockFetch = makeFetch(expected)
|
|
473
|
-
const client =
|
|
486
|
+
const client = makeClient(mockFetch)
|
|
474
487
|
|
|
475
488
|
const result = await client.getVersion({})
|
|
476
489
|
expect(result).toEqual(expected)
|
|
@@ -479,7 +492,7 @@ describe('HTTPWalletJSON – response body passthrough', () => {
|
|
|
479
492
|
it('returns the exact JSON body from a successful listActions call', async () => {
|
|
480
493
|
const expected = { totalActions: 2, actions: [{ txid: 'aa', status: 'completed' }] }
|
|
481
494
|
const mockFetch = makeFetch(expected)
|
|
482
|
-
const client =
|
|
495
|
+
const client = makeClient(mockFetch)
|
|
483
496
|
|
|
484
497
|
const result = await client.listActions({ labels: [] })
|
|
485
498
|
expect(result).toEqual(expected)
|
|
@@ -488,7 +501,7 @@ describe('HTTPWalletJSON – response body passthrough', () => {
|
|
|
488
501
|
it('returns the exact JSON body from a successful getNetwork call', async () => {
|
|
489
502
|
const expected = { network: 'mainnet' as const }
|
|
490
503
|
const mockFetch = makeFetch(expected)
|
|
491
|
-
const client =
|
|
504
|
+
const client = makeClient(mockFetch)
|
|
492
505
|
|
|
493
506
|
const result = await client.getNetwork({})
|
|
494
507
|
expect(result).toEqual(expected)
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import ReactNativeWebView from '../ReactNativeWebView'
|
|
2
|
+
import { WalletError } from '../../WalletError'
|
|
3
|
+
import * as Utils from '../../../primitives/utils'
|
|
4
|
+
|
|
5
|
+
describe('ReactNativeWebView', () => {
|
|
6
|
+
let originalWindow: typeof global.window
|
|
7
|
+
let addEventListenerMock: jest.Mock
|
|
8
|
+
let removeEventListenerMock: jest.Mock
|
|
9
|
+
let postMessageMock: jest.Mock
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
originalWindow = global.window
|
|
13
|
+
addEventListenerMock = jest.fn()
|
|
14
|
+
removeEventListenerMock = jest.fn()
|
|
15
|
+
postMessageMock = jest.fn()
|
|
16
|
+
|
|
17
|
+
global.window = {
|
|
18
|
+
ReactNativeWebView: {
|
|
19
|
+
postMessage: postMessageMock
|
|
20
|
+
},
|
|
21
|
+
addEventListener: addEventListenerMock,
|
|
22
|
+
removeEventListener: removeEventListenerMock
|
|
23
|
+
} as unknown as Window & typeof globalThis
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
global.window = originalWindow
|
|
28
|
+
jest.restoreAllMocks()
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
const getMessageListener = (): ((event: { data: string }) => void) => {
|
|
32
|
+
const call = addEventListenerMock.mock.calls.at(-1)
|
|
33
|
+
if (call == null) {
|
|
34
|
+
throw new Error('No message listener registered.')
|
|
35
|
+
}
|
|
36
|
+
return call[1] as (event: { data: string }) => void
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const dispatchMessage = (data: unknown): void => {
|
|
40
|
+
getMessageListener()({ data: JSON.stringify(data) })
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
describe('constructor', () => {
|
|
44
|
+
it('throws if window is not available', () => {
|
|
45
|
+
;(global as any).window = undefined
|
|
46
|
+
|
|
47
|
+
expect(() => new ReactNativeWebView()).toThrow(
|
|
48
|
+
'The XDM substrate requires a global window object.'
|
|
49
|
+
)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('throws if ReactNativeWebView is not bound to window', () => {
|
|
53
|
+
delete (global.window as any).ReactNativeWebView
|
|
54
|
+
|
|
55
|
+
expect(() => new ReactNativeWebView()).toThrow(
|
|
56
|
+
'The window object does not have a ReactNativeWebView property.'
|
|
57
|
+
)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('throws if ReactNativeWebView does not support postMessage', () => {
|
|
61
|
+
;(global.window as any).ReactNativeWebView.postMessage = undefined
|
|
62
|
+
|
|
63
|
+
expect(() => new ReactNativeWebView()).toThrow(
|
|
64
|
+
'The window.ReactNativeWebView property does not seem to support postMessage calls.'
|
|
65
|
+
)
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
describe('invoke', () => {
|
|
70
|
+
it('posts an invocation message to the React Native bridge', () => {
|
|
71
|
+
jest.spyOn(Utils, 'toBase64').mockReturnValue('request-id')
|
|
72
|
+
const substrate = new ReactNativeWebView()
|
|
73
|
+
|
|
74
|
+
void substrate.invoke('getVersion', {})
|
|
75
|
+
|
|
76
|
+
expect(addEventListenerMock).toHaveBeenCalledWith('message', expect.any(Function))
|
|
77
|
+
expect(postMessageMock).toHaveBeenCalledWith(
|
|
78
|
+
JSON.stringify({
|
|
79
|
+
type: 'CWI',
|
|
80
|
+
isInvocation: true,
|
|
81
|
+
id: 'request-id',
|
|
82
|
+
call: 'getVersion',
|
|
83
|
+
args: {}
|
|
84
|
+
})
|
|
85
|
+
)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('resolves the result from a matching response', async () => {
|
|
89
|
+
jest.spyOn(Utils, 'toBase64').mockReturnValue('request-id')
|
|
90
|
+
const substrate = new ReactNativeWebView()
|
|
91
|
+
|
|
92
|
+
const promise = substrate.invoke('getVersion', {})
|
|
93
|
+
dispatchMessage({
|
|
94
|
+
type: 'CWI',
|
|
95
|
+
isInvocation: false,
|
|
96
|
+
id: 'request-id',
|
|
97
|
+
status: 'success',
|
|
98
|
+
result: { version: '1.0.0' }
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
await expect(promise).resolves.toEqual({ version: '1.0.0' })
|
|
102
|
+
expect(removeEventListenerMock).toHaveBeenCalledWith('message', expect.any(Function))
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
it('rejects matching error responses as WalletError', async () => {
|
|
106
|
+
jest.spyOn(Utils, 'toBase64').mockReturnValue('request-id')
|
|
107
|
+
const substrate = new ReactNativeWebView()
|
|
108
|
+
|
|
109
|
+
const promise = substrate.invoke('createAction', { description: 'Test action' })
|
|
110
|
+
dispatchMessage({
|
|
111
|
+
type: 'CWI',
|
|
112
|
+
isInvocation: false,
|
|
113
|
+
id: 'request-id',
|
|
114
|
+
status: 'error',
|
|
115
|
+
description: 'Action was rejected',
|
|
116
|
+
code: 123
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
await expect(promise).rejects.toThrow(WalletError)
|
|
120
|
+
await expect(promise).rejects.toThrow('Action was rejected')
|
|
121
|
+
await promise.catch((err) => {
|
|
122
|
+
expect(err.code).toBe(123)
|
|
123
|
+
})
|
|
124
|
+
expect(removeEventListenerMock).toHaveBeenCalledWith('message', expect.any(Function))
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
it('ignores unrelated response messages', async () => {
|
|
128
|
+
jest.spyOn(Utils, 'toBase64').mockReturnValue('request-id')
|
|
129
|
+
const substrate = new ReactNativeWebView()
|
|
130
|
+
const promise = substrate.invoke('getVersion', {})
|
|
131
|
+
let settled = false
|
|
132
|
+
promise.then(
|
|
133
|
+
() => { settled = true },
|
|
134
|
+
() => { settled = true }
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
dispatchMessage({
|
|
138
|
+
type: 'other',
|
|
139
|
+
isInvocation: false,
|
|
140
|
+
id: 'request-id',
|
|
141
|
+
status: 'success',
|
|
142
|
+
result: {}
|
|
143
|
+
})
|
|
144
|
+
dispatchMessage({
|
|
145
|
+
type: 'CWI',
|
|
146
|
+
isInvocation: false,
|
|
147
|
+
id: 'other-id',
|
|
148
|
+
status: 'success',
|
|
149
|
+
result: {}
|
|
150
|
+
})
|
|
151
|
+
dispatchMessage({
|
|
152
|
+
type: 'CWI',
|
|
153
|
+
isInvocation: true,
|
|
154
|
+
id: 'request-id',
|
|
155
|
+
status: 'success',
|
|
156
|
+
result: {}
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
await new Promise((resolve) => setTimeout(resolve, 1))
|
|
160
|
+
expect(settled).toBe(false)
|
|
161
|
+
expect(removeEventListenerMock).not.toHaveBeenCalled()
|
|
162
|
+
|
|
163
|
+
dispatchMessage({
|
|
164
|
+
type: 'CWI',
|
|
165
|
+
isInvocation: false,
|
|
166
|
+
id: 'request-id',
|
|
167
|
+
status: 'success',
|
|
168
|
+
result: { version: '1.0.0' }
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
await expect(promise).resolves.toEqual({ version: '1.0.0' })
|
|
172
|
+
})
|
|
173
|
+
})
|
|
174
|
+
})
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import WindowCWISubstrate from '../window.CWI'
|
|
2
|
+
|
|
3
|
+
const originator = 'example.com'
|
|
4
|
+
|
|
5
|
+
const methodCases = [
|
|
6
|
+
{
|
|
7
|
+
methodName: 'createAction',
|
|
8
|
+
args: { description: 'Test description', inputs: [], outputs: [] },
|
|
9
|
+
result: { txid: 'abc123' }
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
methodName: 'signAction',
|
|
13
|
+
args: { spends: {}, reference: 'someReference' },
|
|
14
|
+
result: { txid: 'abc123' }
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
methodName: 'abortAction',
|
|
18
|
+
args: { reference: 'someReference' },
|
|
19
|
+
result: { aborted: true }
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
methodName: 'listActions',
|
|
23
|
+
args: { labels: [] },
|
|
24
|
+
result: { totalActions: 0, actions: [] }
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
methodName: 'internalizeAction',
|
|
28
|
+
args: { tx: 'someTx', outputs: [], description: 'Test description' },
|
|
29
|
+
result: { accepted: true }
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
methodName: 'listOutputs',
|
|
33
|
+
args: { basket: 'someBasket' },
|
|
34
|
+
result: { totalOutputs: 0, outputs: [] }
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
methodName: 'relinquishOutput',
|
|
38
|
+
args: { basket: 'someBasket', output: 'someOutput' },
|
|
39
|
+
result: { relinquished: true }
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
methodName: 'getPublicKey',
|
|
43
|
+
args: { identityKey: true },
|
|
44
|
+
result: { publicKey: 'somePubKey' }
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
methodName: 'revealCounterpartyKeyLinkage',
|
|
48
|
+
args: { counterparty: 'someCounterparty', verifier: 'someVerifier' },
|
|
49
|
+
result: {
|
|
50
|
+
prover: 'someProver',
|
|
51
|
+
verifier: 'someVerifier',
|
|
52
|
+
counterparty: 'someCounterparty',
|
|
53
|
+
revelationTime: 'someTime',
|
|
54
|
+
encryptedLinkage: [],
|
|
55
|
+
encryptedLinkageProof: []
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
methodName: 'revealSpecificKeyLinkage',
|
|
60
|
+
args: {
|
|
61
|
+
counterparty: 'someCounterparty',
|
|
62
|
+
verifier: 'someVerifier',
|
|
63
|
+
protocolID: [0, 'someProtocol'],
|
|
64
|
+
keyID: 'someKeyID'
|
|
65
|
+
},
|
|
66
|
+
result: {
|
|
67
|
+
prover: 'someProver',
|
|
68
|
+
verifier: 'someVerifier',
|
|
69
|
+
counterparty: 'someCounterparty',
|
|
70
|
+
protocolID: [0, 'someProtocol'],
|
|
71
|
+
keyID: 'someKeyID',
|
|
72
|
+
encryptedLinkage: [],
|
|
73
|
+
encryptedLinkageProof: [],
|
|
74
|
+
proofType: 1
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
methodName: 'encrypt',
|
|
79
|
+
args: { plaintext: [], protocolID: [0, 'someProtocol'], keyID: 'someKeyID' },
|
|
80
|
+
result: { ciphertext: [] }
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
methodName: 'decrypt',
|
|
84
|
+
args: { ciphertext: [], protocolID: [0, 'someProtocol'], keyID: 'someKeyID' },
|
|
85
|
+
result: { plaintext: [] }
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
methodName: 'createHmac',
|
|
89
|
+
args: { data: [], protocolID: [0, 'someProtocol'], keyID: 'someKeyID' },
|
|
90
|
+
result: { hmac: [] }
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
methodName: 'verifyHmac',
|
|
94
|
+
args: { data: [], hmac: [], protocolID: [0, 'someProtocol'], keyID: 'someKeyID' },
|
|
95
|
+
result: { valid: true }
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
methodName: 'createSignature',
|
|
99
|
+
args: { data: [], protocolID: [0, 'someProtocol'], keyID: 'someKeyID' },
|
|
100
|
+
result: { signature: [] }
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
methodName: 'verifySignature',
|
|
104
|
+
args: { data: [], signature: [], protocolID: [0, 'someProtocol'], keyID: 'someKeyID' },
|
|
105
|
+
result: { valid: true }
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
methodName: 'acquireCertificate',
|
|
109
|
+
args: {
|
|
110
|
+
type: 'someType',
|
|
111
|
+
subject: 'someSubject',
|
|
112
|
+
serialNumber: 'someSerialNumber',
|
|
113
|
+
revocationOutpoint: 'someOutpoint',
|
|
114
|
+
signature: 'someSignature',
|
|
115
|
+
fields: {},
|
|
116
|
+
certifier: 'someCertifier',
|
|
117
|
+
keyringRevealer: 'certifier',
|
|
118
|
+
keyringForSubject: {},
|
|
119
|
+
acquisitionProtocol: 'direct'
|
|
120
|
+
},
|
|
121
|
+
result: {
|
|
122
|
+
type: 'someType',
|
|
123
|
+
subject: 'someSubject',
|
|
124
|
+
serialNumber: 'someSerialNumber',
|
|
125
|
+
certifier: 'someCertifier',
|
|
126
|
+
revocationOutpoint: 'someOutpoint',
|
|
127
|
+
signature: 'someSignature',
|
|
128
|
+
fields: {}
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
methodName: 'listCertificates',
|
|
133
|
+
args: { certifiers: [], types: [] },
|
|
134
|
+
result: { totalCertificates: 0, certificates: [] }
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
methodName: 'proveCertificate',
|
|
138
|
+
args: {
|
|
139
|
+
certificate: {
|
|
140
|
+
type: 'someType',
|
|
141
|
+
subject: 'someSubject',
|
|
142
|
+
serialNumber: 'someSerialNumber',
|
|
143
|
+
certifier: 'someCertifier',
|
|
144
|
+
revocationOutpoint: 'someOutpoint',
|
|
145
|
+
signature: 'someSignature',
|
|
146
|
+
fields: {}
|
|
147
|
+
},
|
|
148
|
+
fieldsToReveal: [],
|
|
149
|
+
verifier: 'someVerifier'
|
|
150
|
+
},
|
|
151
|
+
result: { keyringForVerifier: {} }
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
methodName: 'relinquishCertificate',
|
|
155
|
+
args: { type: 'someType', serialNumber: 'someSerialNumber', certifier: 'someCertifier' },
|
|
156
|
+
result: { relinquished: true }
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
methodName: 'discoverByIdentityKey',
|
|
160
|
+
args: { identityKey: 'someIdentityKey' },
|
|
161
|
+
result: { totalCertificates: 0, certificates: [] }
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
methodName: 'discoverByAttributes',
|
|
165
|
+
args: { attributes: {} },
|
|
166
|
+
result: { totalCertificates: 0, certificates: [] }
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
methodName: 'isAuthenticated',
|
|
170
|
+
args: {},
|
|
171
|
+
result: { authenticated: true }
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
methodName: 'waitForAuthentication',
|
|
175
|
+
args: {},
|
|
176
|
+
result: { authenticated: true }
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
methodName: 'getHeight',
|
|
180
|
+
args: {},
|
|
181
|
+
result: { height: 1000 }
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
methodName: 'getHeaderForHeight',
|
|
185
|
+
args: { height: 1000 },
|
|
186
|
+
result: { header: 'someHeader' }
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
methodName: 'getNetwork',
|
|
190
|
+
args: {},
|
|
191
|
+
result: { network: 'mainnet' }
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
methodName: 'getVersion',
|
|
195
|
+
args: {},
|
|
196
|
+
result: { version: '1.0.0' }
|
|
197
|
+
}
|
|
198
|
+
]
|
|
199
|
+
|
|
200
|
+
describe('WindowCWISubstrate', () => {
|
|
201
|
+
let originalWindow: typeof global.window
|
|
202
|
+
let mockCWI: Record<string, jest.Mock>
|
|
203
|
+
|
|
204
|
+
beforeEach(() => {
|
|
205
|
+
originalWindow = global.window
|
|
206
|
+
mockCWI = Object.fromEntries(
|
|
207
|
+
methodCases.map(({ methodName, result }) => [
|
|
208
|
+
methodName,
|
|
209
|
+
jest.fn().mockResolvedValue(result)
|
|
210
|
+
])
|
|
211
|
+
)
|
|
212
|
+
global.window = {
|
|
213
|
+
CWI: mockCWI
|
|
214
|
+
} as unknown as Window & typeof globalThis
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
afterEach(() => {
|
|
218
|
+
global.window = originalWindow
|
|
219
|
+
jest.restoreAllMocks()
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
it('throws if window is not available', () => {
|
|
223
|
+
;(global as any).window = undefined
|
|
224
|
+
|
|
225
|
+
expect(() => new WindowCWISubstrate()).toThrow(
|
|
226
|
+
'The window.CWI substrate requires a global window object.'
|
|
227
|
+
)
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
it('throws if window.CWI is not bound', () => {
|
|
231
|
+
delete (global.window as any).CWI
|
|
232
|
+
|
|
233
|
+
expect(() => new WindowCWISubstrate()).toThrow(
|
|
234
|
+
'The window.CWI interface does not appear to be bound to the window object.'
|
|
235
|
+
)
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
it('binds the CWI object that exists at construction time', async () => {
|
|
239
|
+
const substrate = new WindowCWISubstrate()
|
|
240
|
+
const replacement = {
|
|
241
|
+
getVersion: jest.fn().mockResolvedValue({ version: '2.0.0' })
|
|
242
|
+
}
|
|
243
|
+
;(global.window as any).CWI = replacement
|
|
244
|
+
|
|
245
|
+
await expect(substrate.getVersion({})).resolves.toEqual({ version: '1.0.0' })
|
|
246
|
+
expect(mockCWI.getVersion).toHaveBeenCalledWith({}, undefined)
|
|
247
|
+
expect(replacement.getVersion).not.toHaveBeenCalled()
|
|
248
|
+
})
|
|
249
|
+
|
|
250
|
+
test.each(methodCases)('delegates $methodName to window.CWI', async ({ methodName, args, result }) => {
|
|
251
|
+
const substrate = new WindowCWISubstrate()
|
|
252
|
+
|
|
253
|
+
await expect((substrate as any)[methodName](args, originator)).resolves.toEqual(result)
|
|
254
|
+
expect(mockCWI[methodName]).toHaveBeenCalledWith(args, originator)
|
|
255
|
+
})
|
|
256
|
+
})
|