@bsv/wallet-toolbox 1.1.60 → 1.1.61
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/.prettierrc +1 -1
- package/docs/client.md +39 -5
- package/docs/services.md +1 -0
- package/docs/setup.md +9 -26
- package/docs/storage.md +35 -0
- package/docs/wallet.md +39 -5
- package/out/src/Setup.d.ts.map +1 -1
- package/out/src/Setup.js +6 -16
- package/out/src/Setup.js.map +1 -1
- package/out/src/Wallet.d.ts.map +1 -1
- package/out/src/Wallet.js +4 -11
- package/out/src/Wallet.js.map +1 -1
- package/out/src/monitor/Monitor.d.ts.map +1 -1
- package/out/src/monitor/Monitor.js.map +1 -1
- package/out/src/monitor/MonitorDaemon.d.ts.map +1 -1
- package/out/src/monitor/MonitorDaemon.js +1 -3
- package/out/src/monitor/MonitorDaemon.js.map +1 -1
- package/out/src/monitor/tasks/TaskCheckForProofs.d.ts.map +1 -1
- package/out/src/monitor/tasks/TaskCheckForProofs.js +2 -10
- package/out/src/monitor/tasks/TaskCheckForProofs.js.map +1 -1
- package/out/src/monitor/tasks/TaskClock.d.ts.map +1 -1
- package/out/src/monitor/tasks/TaskClock.js +1 -1
- package/out/src/monitor/tasks/TaskClock.js.map +1 -1
- package/out/src/monitor/tasks/TaskFailAbandoned.d.ts.map +1 -1
- package/out/src/monitor/tasks/TaskFailAbandoned.js.map +1 -1
- package/out/src/monitor/tasks/TaskNewHeader.d.ts.map +1 -1
- package/out/src/monitor/tasks/TaskNewHeader.js +1 -2
- package/out/src/monitor/tasks/TaskNewHeader.js.map +1 -1
- package/out/src/monitor/tasks/TaskPurge.d.ts.map +1 -1
- package/out/src/monitor/tasks/TaskPurge.js +1 -2
- package/out/src/monitor/tasks/TaskPurge.js.map +1 -1
- package/out/src/monitor/tasks/TaskReviewStatus.d.ts.map +1 -1
- package/out/src/monitor/tasks/TaskReviewStatus.js +1 -2
- package/out/src/monitor/tasks/TaskReviewStatus.js.map +1 -1
- package/out/src/monitor/tasks/TaskSendWaiting.d.ts.map +1 -1
- package/out/src/monitor/tasks/TaskSendWaiting.js.map +1 -1
- package/out/src/sdk/CertOps.d.ts.map +1 -1
- package/out/src/sdk/CertOps.js +4 -12
- package/out/src/sdk/CertOps.js.map +1 -1
- package/out/src/sdk/PrivilegedKeyManager.d.ts.map +1 -1
- package/out/src/sdk/PrivilegedKeyManager.js.map +1 -1
- package/out/src/sdk/WERR_errors.d.ts.map +1 -1
- package/out/src/sdk/WERR_errors.js.map +1 -1
- package/out/src/sdk/WalletError.d.ts.map +1 -1
- package/out/src/sdk/WalletError.js +1 -4
- package/out/src/sdk/WalletError.js.map +1 -1
- package/out/src/sdk/WalletServices.interfaces.d.ts +2 -0
- package/out/src/sdk/WalletServices.interfaces.d.ts.map +1 -1
- package/out/src/sdk/WalletStorage.interfaces.d.ts.map +1 -1
- package/out/src/sdk/__test/CertificateLifeCycle.test.js +1 -3
- package/out/src/sdk/__test/CertificateLifeCycle.test.js.map +1 -1
- package/out/src/sdk/__test/PrivilegedKeyManager.test.js +13 -26
- package/out/src/sdk/__test/PrivilegedKeyManager.test.js.map +1 -1
- package/out/src/sdk/types.d.ts.map +1 -1
- package/out/src/sdk/types.js +2 -10
- package/out/src/sdk/types.js.map +1 -1
- package/out/src/sdk/validationHelpers.d.ts.map +1 -1
- package/out/src/sdk/validationHelpers.js +5 -12
- package/out/src/sdk/validationHelpers.js.map +1 -1
- package/out/src/services/Services.d.ts +1 -0
- package/out/src/services/Services.d.ts.map +1 -1
- package/out/src/services/Services.js +29 -38
- package/out/src/services/Services.js.map +1 -1
- package/out/src/services/__tests/bitrails.test.js.map +1 -1
- package/out/src/services/__tests/getMerklePath.test.js.map +1 -1
- package/out/src/services/__tests/getRawTx.test.js.map +1 -1
- package/out/src/services/__tests/verifyBeef.test.js +2 -1
- package/out/src/services/__tests/verifyBeef.test.js.map +1 -1
- package/out/src/services/chaintracker/ChaintracksChainTracker.d.ts.map +1 -1
- package/out/src/services/chaintracker/ChaintracksChainTracker.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/BlockHeaderApi.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/BlockHeaderApi.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.js +1 -3
- package/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.js.map +1 -1
- package/out/src/services/createDefaultWalletServicesOptions.d.ts.map +1 -1
- package/out/src/services/createDefaultWalletServicesOptions.js.map +1 -1
- package/out/src/services/providers/ARC.d.ts.map +1 -1
- package/out/src/services/providers/ARC.js +1 -2
- package/out/src/services/providers/ARC.js.map +1 -1
- package/out/src/services/providers/Bitails.d.ts.map +1 -1
- package/out/src/services/providers/Bitails.js +62 -134
- package/out/src/services/providers/Bitails.js.map +1 -1
- package/out/src/services/providers/SdkWhatsOnChain.d.ts.map +1 -1
- package/out/src/services/providers/SdkWhatsOnChain.js.map +1 -1
- package/out/src/services/providers/WhatsOnChain.d.ts.map +1 -1
- package/out/src/services/providers/WhatsOnChain.js +6 -21
- package/out/src/services/providers/WhatsOnChain.js.map +1 -1
- package/out/src/services/providers/__tests/WhatsOnChain.test.js +1 -2
- package/out/src/services/providers/__tests/WhatsOnChain.test.js.map +1 -1
- package/out/src/services/providers/echangeRates.d.ts.map +1 -1
- package/out/src/services/providers/echangeRates.js.map +1 -1
- package/out/src/signer/WalletSigner.d.ts.map +1 -1
- package/out/src/signer/WalletSigner.js.map +1 -1
- package/out/src/signer/methods/acquireDirectCertificate.d.ts.map +1 -1
- package/out/src/signer/methods/acquireDirectCertificate.js +1 -3
- package/out/src/signer/methods/acquireDirectCertificate.js.map +1 -1
- package/out/src/signer/methods/buildSignableTransaction.d.ts.map +1 -1
- package/out/src/signer/methods/buildSignableTransaction.js +3 -11
- package/out/src/signer/methods/buildSignableTransaction.js.map +1 -1
- package/out/src/signer/methods/createAction.d.ts.map +1 -1
- package/out/src/signer/methods/createAction.js +3 -10
- package/out/src/signer/methods/createAction.js.map +1 -1
- package/out/src/signer/methods/internalizeAction.d.ts.map +1 -1
- package/out/src/signer/methods/internalizeAction.js.map +1 -1
- package/out/src/signer/methods/proveCertificate.d.ts.map +1 -1
- package/out/src/signer/methods/proveCertificate.js.map +1 -1
- package/out/src/signer/methods/signAction.d.ts.map +1 -1
- package/out/src/signer/methods/signAction.js +2 -7
- package/out/src/signer/methods/signAction.js.map +1 -1
- package/out/src/storage/StorageKnex.d.ts.map +1 -1
- package/out/src/storage/StorageKnex.js +15 -44
- package/out/src/storage/StorageKnex.js.map +1 -1
- package/out/src/storage/StorageProvider.d.ts.map +1 -1
- package/out/src/storage/StorageProvider.js +9 -34
- package/out/src/storage/StorageProvider.js.map +1 -1
- package/out/src/storage/StorageReader.d.ts.map +1 -1
- package/out/src/storage/StorageReader.js.map +1 -1
- package/out/src/storage/StorageReaderWriter.d.ts.map +1 -1
- package/out/src/storage/StorageReaderWriter.js.map +1 -1
- package/out/src/storage/StorageSyncReader.d.ts.map +1 -1
- package/out/src/storage/StorageSyncReader.js.map +1 -1
- package/out/src/storage/WalletStorageManager.d.ts.map +1 -1
- package/out/src/storage/WalletStorageManager.js +5 -10
- package/out/src/storage/WalletStorageManager.js.map +1 -1
- package/out/src/storage/__test/WalletStorageManager.test.js +2 -8
- package/out/src/storage/__test/WalletStorageManager.test.js.map +1 -1
- package/out/src/storage/methods/__test/GenerateChange/generateChangeSdk.test.js +10 -30
- package/out/src/storage/methods/__test/GenerateChange/generateChangeSdk.test.js.map +1 -1
- package/out/src/storage/methods/__test/GenerateChange/randomValsUsed1.d.ts.map +1 -1
- package/out/src/storage/methods/__test/GenerateChange/randomValsUsed1.js +17 -28
- package/out/src/storage/methods/__test/GenerateChange/randomValsUsed1.js.map +1 -1
- package/out/src/storage/methods/attemptToPostReqsToNetwork.d.ts.map +1 -1
- package/out/src/storage/methods/attemptToPostReqsToNetwork.js +6 -20
- package/out/src/storage/methods/attemptToPostReqsToNetwork.js.map +1 -1
- package/out/src/storage/methods/createAction.d.ts.map +1 -1
- package/out/src/storage/methods/createAction.js +4 -9
- package/out/src/storage/methods/createAction.js.map +1 -1
- package/out/src/storage/methods/generateChange.d.ts.map +1 -1
- package/out/src/storage/methods/generateChange.js +7 -18
- package/out/src/storage/methods/generateChange.js.map +1 -1
- package/out/src/storage/methods/getBeefForTransaction.d.ts.map +1 -1
- package/out/src/storage/methods/getBeefForTransaction.js +1 -3
- package/out/src/storage/methods/getBeefForTransaction.js.map +1 -1
- package/out/src/storage/methods/getSyncChunk.d.ts.map +1 -1
- package/out/src/storage/methods/getSyncChunk.js.map +1 -1
- package/out/src/storage/methods/internalizeAction.d.ts.map +1 -1
- package/out/src/storage/methods/internalizeAction.js +2 -9
- package/out/src/storage/methods/internalizeAction.js.map +1 -1
- package/out/src/storage/methods/listActions.d.ts.map +1 -1
- package/out/src/storage/methods/listActions.js +3 -15
- package/out/src/storage/methods/listActions.js.map +1 -1
- package/out/src/storage/methods/listCertificates.d.ts.map +1 -1
- package/out/src/storage/methods/listCertificates.js.map +1 -1
- package/out/src/storage/methods/listOutputs.d.ts.map +1 -1
- package/out/src/storage/methods/listOutputs.js +4 -11
- package/out/src/storage/methods/listOutputs.js.map +1 -1
- package/out/src/storage/methods/processAction.d.ts.map +1 -1
- package/out/src/storage/methods/processAction.js +4 -10
- package/out/src/storage/methods/processAction.js.map +1 -1
- package/out/src/storage/methods/purgeData.d.ts.map +1 -1
- package/out/src/storage/methods/purgeData.js +8 -32
- package/out/src/storage/methods/purgeData.js.map +1 -1
- package/out/src/storage/methods/reviewStatus.d.ts.map +1 -1
- package/out/src/storage/methods/reviewStatus.js +1 -3
- package/out/src/storage/methods/reviewStatus.js.map +1 -1
- package/out/src/storage/remoting/StorageClient.d.ts.map +1 -1
- package/out/src/storage/remoting/StorageClient.js +15 -41
- package/out/src/storage/remoting/StorageClient.js.map +1 -1
- package/out/src/storage/remoting/StorageServer.d.ts.map +1 -1
- package/out/src/storage/remoting/StorageServer.js +2 -5
- package/out/src/storage/remoting/StorageServer.js.map +1 -1
- package/out/src/storage/schema/KnexMigrations.d.ts.map +1 -1
- package/out/src/storage/schema/KnexMigrations.js +24 -130
- package/out/src/storage/schema/KnexMigrations.js.map +1 -1
- package/out/src/storage/schema/entities/Certificate.d.ts.map +1 -1
- package/out/src/storage/schema/entities/Certificate.js +1 -1
- package/out/src/storage/schema/entities/Certificate.js.map +1 -1
- package/out/src/storage/schema/entities/CertificateField.d.ts.map +1 -1
- package/out/src/storage/schema/entities/CertificateField.js +2 -5
- package/out/src/storage/schema/entities/CertificateField.js.map +1 -1
- package/out/src/storage/schema/entities/Commission.d.ts.map +1 -1
- package/out/src/storage/schema/entities/Commission.js +2 -5
- package/out/src/storage/schema/entities/Commission.js.map +1 -1
- package/out/src/storage/schema/entities/EntityBase.d.ts.map +1 -1
- package/out/src/storage/schema/entities/EntityBase.js.map +1 -1
- package/out/src/storage/schema/entities/MergeEntity.d.ts.map +1 -1
- package/out/src/storage/schema/entities/MergeEntity.js +14 -9
- package/out/src/storage/schema/entities/MergeEntity.js.map +1 -1
- package/out/src/storage/schema/entities/Output.d.ts.map +1 -1
- package/out/src/storage/schema/entities/Output.js +8 -25
- package/out/src/storage/schema/entities/Output.js.map +1 -1
- package/out/src/storage/schema/entities/OutputBasket.d.ts.map +1 -1
- package/out/src/storage/schema/entities/OutputBasket.js +1 -1
- package/out/src/storage/schema/entities/OutputBasket.js.map +1 -1
- package/out/src/storage/schema/entities/OutputTag.d.ts.map +1 -1
- package/out/src/storage/schema/entities/OutputTag.js +1 -1
- package/out/src/storage/schema/entities/OutputTag.js.map +1 -1
- package/out/src/storage/schema/entities/OutputTagMap.d.ts.map +1 -1
- package/out/src/storage/schema/entities/OutputTagMap.js +3 -7
- package/out/src/storage/schema/entities/OutputTagMap.js.map +1 -1
- package/out/src/storage/schema/entities/ProvenTx.d.ts.map +1 -1
- package/out/src/storage/schema/entities/ProvenTx.js +10 -20
- package/out/src/storage/schema/entities/ProvenTx.js.map +1 -1
- package/out/src/storage/schema/entities/ProvenTxReq.d.ts.map +1 -1
- package/out/src/storage/schema/entities/ProvenTxReq.js +8 -18
- package/out/src/storage/schema/entities/ProvenTxReq.js.map +1 -1
- package/out/src/storage/schema/entities/SyncState.d.ts +1 -0
- package/out/src/storage/schema/entities/SyncState.d.ts.map +1 -1
- package/out/src/storage/schema/entities/SyncState.js +41 -6
- package/out/src/storage/schema/entities/SyncState.js.map +1 -1
- package/out/src/storage/schema/entities/Transaction.d.ts.map +1 -1
- package/out/src/storage/schema/entities/Transaction.js +4 -13
- package/out/src/storage/schema/entities/Transaction.js.map +1 -1
- package/out/src/storage/schema/entities/TxLabel.d.ts.map +1 -1
- package/out/src/storage/schema/entities/TxLabel.js +1 -1
- package/out/src/storage/schema/entities/TxLabel.js.map +1 -1
- package/out/src/storage/schema/entities/TxLabelMap.d.ts.map +1 -1
- package/out/src/storage/schema/entities/TxLabelMap.js +3 -9
- package/out/src/storage/schema/entities/TxLabelMap.js.map +1 -1
- package/out/src/storage/schema/entities/User.d.ts.map +1 -1
- package/out/src/storage/schema/entities/User.js +3 -5
- package/out/src/storage/schema/entities/User.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/CertificateFieldTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/CertificateTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/CommissionTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/OutputBasketTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/OutputTagMapTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/OutputTagTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/OutputTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/ProvenTxReqTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/ProvenTxTests.test.js +1 -2
- package/out/src/storage/schema/entities/__tests/ProvenTxTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/SyncStateTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/TransactionTests.test.js +2 -2
- package/out/src/storage/schema/entities/__tests/TransactionTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/TxLabelMapTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/TxLabelTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/stampLogTests.test.js.map +1 -1
- package/out/src/storage/schema/entities/__tests/usersTests.test.js.map +1 -1
- package/out/src/storage/schema/tables/TableSettings.d.ts.map +1 -1
- package/out/src/storage/sync/StorageMySQLDojoReader.d.ts.map +1 -1
- package/out/src/storage/sync/StorageMySQLDojoReader.js +1 -3
- package/out/src/storage/sync/StorageMySQLDojoReader.js.map +1 -1
- package/out/src/utility/ScriptTemplateBRC29.d.ts.map +1 -1
- package/out/src/utility/ScriptTemplateBRC29.js +1 -2
- package/out/src/utility/ScriptTemplateBRC29.js.map +1 -1
- package/out/src/utility/stampLog.d.ts.map +1 -1
- package/out/src/utility/stampLog.js.map +1 -1
- package/out/src/utility/tscProofToMerklePath.d.ts.map +1 -1
- package/out/src/utility/tscProofToMerklePath.js.map +1 -1
- package/out/src/utility/utilityHelpers.buffer.d.ts.map +1 -1
- package/out/src/utility/utilityHelpers.buffer.js.map +1 -1
- package/out/src/utility/utilityHelpers.d.ts.map +1 -1
- package/out/src/utility/utilityHelpers.js +1 -3
- package/out/src/utility/utilityHelpers.js.map +1 -1
- package/out/test/Wallet/StorageClient/storageClient.man.test.js.map +1 -1
- package/out/test/Wallet/action/internalizeAction.a.test.js.map +1 -1
- package/out/test/Wallet/certificate/acquireCertificate.test.js.map +1 -1
- package/out/test/Wallet/certificate/listCertificates.test.js.map +1 -1
- package/out/test/Wallet/get/getHeaderForHeight.test.js +2 -6
- package/out/test/Wallet/get/getHeaderForHeight.test.js.map +1 -1
- package/out/test/Wallet/get/getHeight.test.js.map +1 -1
- package/out/test/Wallet/get/getKnownTxids.test.js.map +1 -1
- package/out/test/Wallet/get/getNetwork.test.js.map +1 -1
- package/out/test/Wallet/get/getVersion.test.js.map +1 -1
- package/out/test/Wallet/live/walletLive.man.test.d.ts.map +1 -1
- package/out/test/Wallet/live/walletLive.man.test.js +3 -9
- package/out/test/Wallet/live/walletLive.man.test.js.map +1 -1
- package/out/test/Wallet/local/localWallet.man.test.d.ts.map +1 -1
- package/out/test/Wallet/local/localWallet.man.test.js +15 -22
- package/out/test/Wallet/local/localWallet.man.test.js.map +1 -1
- package/out/test/Wallet/specOps/specOps.man.test.js +1 -4
- package/out/test/Wallet/specOps/specOps.man.test.js.map +1 -1
- package/out/test/Wallet/support/janitor.man.test.js.map +1 -1
- package/out/test/Wallet/sync/Wallet.updateWalletLegacyTestData.man.test.js.map +1 -1
- package/out/test/Wallet/sync/setActive.test.js +73 -50
- package/out/test/Wallet/sync/setActive.test.js.map +1 -1
- package/out/test/checkDB.d.ts.map +1 -1
- package/out/test/checkDB.js.map +1 -1
- package/out/test/examples/backup.man.test.d.ts.map +1 -1
- package/out/test/examples/backup.man.test.js.map +1 -1
- package/out/test/examples/pushdrop.test.d.ts.map +1 -1
- package/out/test/examples/pushdrop.test.js +5 -4
- package/out/test/examples/pushdrop.test.js.map +1 -1
- package/out/test/monitor/Monitor.test.js.map +1 -1
- package/out/test/services/Services.test.js.map +1 -1
- package/out/test/storage/KnexMigrations.test.js.map +1 -1
- package/out/test/storage/StorageMySQLDojoReader.man.test.js +1 -3
- package/out/test/storage/StorageMySQLDojoReader.man.test.js.map +1 -1
- package/out/test/storage/count.test.js.map +1 -1
- package/out/test/storage/find.test.js +5 -10
- package/out/test/storage/find.test.js.map +1 -1
- package/out/test/storage/findLegacy.test.js.map +1 -1
- package/out/test/storage/insert.test.js.map +1 -1
- package/out/test/storage/update.test.js +7 -19
- package/out/test/storage/update.test.js.map +1 -1
- package/out/test/storage/update2.test.js +22 -24
- package/out/test/storage/update2.test.js.map +1 -1
- package/out/test/utils/TestUtilsWalletStorage.d.ts +3 -1
- package/out/test/utils/TestUtilsWalletStorage.d.ts.map +1 -1
- package/out/test/utils/TestUtilsWalletStorage.js +52 -76
- package/out/test/utils/TestUtilsWalletStorage.js.map +1 -1
- package/out/test/wallet/action/abortAction.test.js.map +1 -1
- package/out/test/wallet/action/createAction.test.js +1 -2
- package/out/test/wallet/action/createAction.test.js.map +1 -1
- package/out/test/wallet/action/createAction2.test.d.ts.map +1 -1
- package/out/test/wallet/action/createAction2.test.js +6 -16
- package/out/test/wallet/action/createAction2.test.js.map +1 -1
- package/out/test/wallet/action/createActionToGenerateBeefs.man.test.js.map +1 -1
- package/out/test/wallet/action/internalizeAction.test.js.map +1 -1
- package/out/test/wallet/action/relinquishOutput.test.js.map +1 -1
- package/out/test/wallet/list/listActions.test.js.map +1 -1
- package/out/test/wallet/list/listActions2.test.js.map +1 -1
- package/out/test/wallet/list/listCertificates.test.js +2 -6
- package/out/test/wallet/list/listCertificates.test.js.map +1 -1
- package/out/test/wallet/list/listOutputs.test.js +2 -10
- package/out/test/wallet/list/listOutputs.test.js.map +1 -1
- package/out/test/wallet/sync/Wallet.sync.test.js +4 -6
- package/out/test/wallet/sync/Wallet.sync.test.js.map +1 -1
- package/out/tsconfig.all.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/Setup.ts +15 -52
- package/src/Wallet.ts +58 -161
- package/src/monitor/Monitor.ts +7 -22
- package/src/monitor/MonitorDaemon.ts +6 -23
- package/src/monitor/tasks/TaskCheckForProofs.ts +4 -23
- package/src/monitor/tasks/TaskClock.ts +1 -3
- package/src/monitor/tasks/TaskFailAbandoned.ts +1 -3
- package/src/monitor/tasks/TaskNewHeader.ts +1 -4
- package/src/monitor/tasks/TaskPurge.ts +1 -2
- package/src/monitor/tasks/TaskReviewStatus.ts +1 -3
- package/src/monitor/tasks/TaskSendWaiting.ts +3 -10
- package/src/sdk/CertOps.ts +31 -103
- package/src/sdk/PrivilegedKeyManager.ts +18 -48
- package/src/sdk/WERR_errors.ts +6 -25
- package/src/sdk/WalletError.ts +5 -21
- package/src/sdk/WalletServices.interfaces.ts +11 -33
- package/src/sdk/WalletStorage.interfaces.ts +25 -91
- package/src/sdk/__test/CertificateLifeCycle.test.ts +9 -27
- package/src/sdk/__test/PrivilegedKeyManager.test.ts +29 -66
- package/src/sdk/types.ts +6 -26
- package/src/sdk/validationHelpers.ts +111 -402
- package/src/services/Services.ts +51 -114
- package/src/services/__tests/bitrails.test.ts +4 -15
- package/src/services/__tests/getMerklePath.test.ts +1 -2
- package/src/services/__tests/getRawTx.test.ts +1 -3
- package/src/services/__tests/verifyBeef.test.ts +2 -1
- package/src/services/chaintracker/ChaintracksChainTracker.ts +3 -13
- package/src/services/chaintracker/chaintracks/BlockHeaderApi.ts +4 -12
- package/src/services/chaintracker/chaintracks/ChaintracksServiceClient.ts +9 -27
- package/src/services/createDefaultWalletServicesOptions.ts +2 -5
- package/src/services/providers/ARC.ts +5 -24
- package/src/services/providers/Bitails.ts +61 -159
- package/src/services/providers/SdkWhatsOnChain.ts +4 -17
- package/src/services/providers/WhatsOnChain.ts +31 -100
- package/src/services/providers/__tests/WhatsOnChain.test.ts +5 -15
- package/src/services/providers/echangeRates.ts +7 -22
- package/src/signer/WalletSigner.ts +1 -5
- package/src/signer/methods/acquireDirectCertificate.ts +1 -4
- package/src/signer/methods/buildSignableTransaction.ts +5 -20
- package/src/signer/methods/createAction.ts +15 -54
- package/src/signer/methods/internalizeAction.ts +10 -39
- package/src/signer/methods/proveCertificate.ts +2 -5
- package/src/signer/methods/signAction.ts +9 -39
- package/src/storage/StorageKnex.ts +166 -499
- package/src/storage/StorageProvider.ts +75 -291
- package/src/storage/StorageReader.ts +20 -65
- package/src/storage/StorageReaderWriter.ts +67 -264
- package/src/storage/StorageSyncReader.ts +2 -5
- package/src/storage/WalletStorageManager.ts +33 -108
- package/src/storage/__test/WalletStorageManager.test.ts +6 -23
- package/src/storage/methods/__test/GenerateChange/generateChangeSdk.test.ts +53 -171
- package/src/storage/methods/__test/GenerateChange/randomValsUsed1.ts +17 -28
- package/src/storage/methods/attemptToPostReqsToNetwork.ts +9 -37
- package/src/storage/methods/createAction.ts +45 -181
- package/src/storage/methods/generateChange.ts +33 -114
- package/src/storage/methods/getBeefForTransaction.ts +7 -37
- package/src/storage/methods/getSyncChunk.ts +18 -69
- package/src/storage/methods/internalizeAction.ts +18 -70
- package/src/storage/methods/listActions.ts +6 -23
- package/src/storage/methods/listCertificates.ts +5 -14
- package/src/storage/methods/listOutputs.ts +14 -68
- package/src/storage/methods/processAction.ts +29 -104
- package/src/storage/methods/purgeData.ts +11 -45
- package/src/storage/methods/reviewStatus.ts +3 -9
- package/src/storage/remoting/StorageClient.ts +43 -146
- package/src/storage/remoting/StorageServer.ts +21 -59
- package/src/storage/schema/KnexMigrations.ts +34 -165
- package/src/storage/schema/entities/Certificate.ts +3 -14
- package/src/storage/schema/entities/CertificateField.ts +6 -28
- package/src/storage/schema/entities/Commission.ts +6 -23
- package/src/storage/schema/entities/EntityBase.ts +1 -6
- package/src/storage/schema/entities/MergeEntity.ts +14 -21
- package/src/storage/schema/entities/Output.ts +10 -39
- package/src/storage/schema/entities/OutputBasket.ts +4 -16
- package/src/storage/schema/entities/OutputTag.ts +4 -17
- package/src/storage/schema/entities/OutputTagMap.ts +7 -30
- package/src/storage/schema/entities/ProvenTx.ts +16 -57
- package/src/storage/schema/entities/ProvenTxReq.ts +29 -93
- package/src/storage/schema/entities/SyncState.ts +64 -116
- package/src/storage/schema/entities/Transaction.ts +10 -35
- package/src/storage/schema/entities/TxLabel.ts +4 -17
- package/src/storage/schema/entities/TxLabelMap.ts +6 -28
- package/src/storage/schema/entities/User.ts +8 -31
- package/src/storage/schema/entities/__tests/CertificateFieldTests.test.ts +23 -54
- package/src/storage/schema/entities/__tests/CertificateTests.test.ts +26 -59
- package/src/storage/schema/entities/__tests/CommissionTests.test.ts +2 -11
- package/src/storage/schema/entities/__tests/OutputBasketTests.test.ts +2 -10
- package/src/storage/schema/entities/__tests/OutputTagMapTests.test.ts +2 -10
- package/src/storage/schema/entities/__tests/OutputTagTests.test.ts +1 -4
- package/src/storage/schema/entities/__tests/OutputTests.test.ts +3 -14
- package/src/storage/schema/entities/__tests/ProvenTxReqTests.test.ts +4 -16
- package/src/storage/schema/entities/__tests/ProvenTxTests.test.ts +5 -18
- package/src/storage/schema/entities/__tests/SyncStateTests.test.ts +5 -26
- package/src/storage/schema/entities/__tests/TransactionTests.test.ts +12 -48
- package/src/storage/schema/entities/__tests/TxLabelMapTests.test.ts +4 -22
- package/src/storage/schema/entities/__tests/TxLabelTests.test.ts +2 -10
- package/src/storage/schema/entities/__tests/stampLogTests.test.ts +3 -10
- package/src/storage/schema/entities/__tests/usersTests.test.ts +4 -7
- package/src/storage/schema/tables/TableSettings.ts +1 -3
- package/src/storage/sync/StorageMySQLDojoReader.ts +47 -148
- package/src/utility/ScriptTemplateBRC29.ts +2 -11
- package/src/utility/stampLog.ts +2 -6
- package/src/utility/tscProofToMerklePath.ts +1 -4
- package/src/utility/utilityHelpers.buffer.ts +3 -12
- package/src/utility/utilityHelpers.ts +14 -49
- package/test/Wallet/StorageClient/storageClient.man.test.ts +2 -8
- package/test/Wallet/action/internalizeAction.a.test.ts +8 -23
- package/test/Wallet/certificate/acquireCertificate.test.ts +10 -24
- package/test/Wallet/certificate/listCertificates.test.ts +8 -18
- package/test/Wallet/get/getHeaderForHeight.test.ts +4 -15
- package/test/Wallet/get/getHeight.test.ts +2 -6
- package/test/Wallet/get/getKnownTxids.test.ts +1 -5
- package/test/Wallet/get/getNetwork.test.ts +1 -2
- package/test/Wallet/get/getVersion.test.ts +1 -2
- package/test/Wallet/live/walletLive.man.test.ts +14 -41
- package/test/Wallet/local/localWallet.man.test.ts +26 -99
- package/test/Wallet/specOps/specOps.man.test.ts +4 -13
- package/test/Wallet/support/janitor.man.test.ts +2 -7
- package/test/Wallet/sync/Wallet.updateWalletLegacyTestData.man.test.ts +11 -34
- package/test/Wallet/sync/setActive.test.ts +75 -61
- package/test/checkDB.ts +2 -8
- package/test/examples/backup.man.test.ts +2 -9
- package/test/examples/pushdrop.test.ts +7 -20
- package/test/monitor/Monitor.test.ts +33 -87
- package/test/services/Services.test.ts +8 -19
- package/test/storage/KnexMigrations.test.ts +3 -18
- package/test/storage/StorageMySQLDojoReader.man.test.ts +4 -15
- package/test/storage/count.test.ts +7 -24
- package/test/storage/find.test.ts +7 -29
- package/test/storage/findLegacy.test.ts +2 -5
- package/test/storage/insert.test.ts +3 -19
- package/test/storage/update.test.ts +47 -179
- package/test/storage/update2.test.ts +54 -176
- package/test/utils/TestUtilsWalletStorage.ts +139 -372
- package/test/wallet/action/abortAction.test.ts +4 -12
- package/test/wallet/action/createAction.test.ts +4 -14
- package/test/wallet/action/createAction2.test.ts +74 -208
- package/test/wallet/action/createActionToGenerateBeefs.man.test.ts +8 -11
- package/test/wallet/action/internalizeAction.test.ts +20 -72
- package/test/wallet/action/relinquishOutput.test.ts +3 -9
- package/test/wallet/list/listActions.test.ts +2 -9
- package/test/wallet/list/listActions2.test.ts +8 -34
- package/test/wallet/list/listCertificates.test.ts +5 -16
- package/test/wallet/list/listOutputs.test.ts +15 -54
- package/test/wallet/sync/Wallet.sync.test.ts +18 -49
|
@@ -71,11 +71,7 @@ export async function generateChangeSdk(
|
|
|
71
71
|
* @returns a random integer betweenn min and max, inclussive.
|
|
72
72
|
*/
|
|
73
73
|
const rand = (min: number, max: number): number => {
|
|
74
|
-
if (max < min)
|
|
75
|
-
throw new sdk.WERR_INVALID_PARAMETER(
|
|
76
|
-
'max',
|
|
77
|
-
`less than min (${min}). max is (${max})`
|
|
78
|
-
)
|
|
74
|
+
if (max < min) throw new sdk.WERR_INVALID_PARAMETER('max', `less than min (${min}). max is (${max})`)
|
|
79
75
|
return Math.floor(nextRandomVal() * (max - min + 1) + min)
|
|
80
76
|
}
|
|
81
77
|
|
|
@@ -87,8 +83,7 @@ export async function generateChangeSdk(
|
|
|
87
83
|
*/
|
|
88
84
|
const funding = (): number => {
|
|
89
85
|
return (
|
|
90
|
-
fixedInputs.reduce((a, e) => a + e.satoshis, 0) +
|
|
91
|
-
r.allocatedChangeInputs.reduce((a, e) => a + e.satoshis, 0)
|
|
86
|
+
fixedInputs.reduce((a, e) => a + e.satoshis, 0) + r.allocatedChangeInputs.reduce((a, e) => a + e.satoshis, 0)
|
|
92
87
|
)
|
|
93
88
|
}
|
|
94
89
|
|
|
@@ -108,21 +103,14 @@ export async function generateChangeSdk(
|
|
|
108
103
|
|
|
109
104
|
const fee = (): number => funding() - spending() - change()
|
|
110
105
|
|
|
111
|
-
const size = (
|
|
112
|
-
addedChangeInputs?: number,
|
|
113
|
-
addedChangeOutputs?: number
|
|
114
|
-
): number => {
|
|
106
|
+
const size = (addedChangeInputs?: number, addedChangeOutputs?: number): number => {
|
|
115
107
|
const inputScriptLengths = [
|
|
116
108
|
...fixedInputs.map(x => x.unlockingScriptLength),
|
|
117
|
-
...Array(
|
|
118
|
-
r.allocatedChangeInputs.length + (addedChangeInputs || 0)
|
|
119
|
-
).fill(params.changeUnlockingScriptLength)
|
|
109
|
+
...Array(r.allocatedChangeInputs.length + (addedChangeInputs || 0)).fill(params.changeUnlockingScriptLength)
|
|
120
110
|
]
|
|
121
111
|
const outputScriptLengths = [
|
|
122
112
|
...fixedOutputs.map(x => x.lockingScriptLength),
|
|
123
|
-
...Array(r.changeOutputs.length + (addedChangeOutputs || 0)).fill(
|
|
124
|
-
params.changeLockingScriptLength
|
|
125
|
-
)
|
|
113
|
+
...Array(r.changeOutputs.length + (addedChangeOutputs || 0)).fill(params.changeLockingScriptLength)
|
|
126
114
|
]
|
|
127
115
|
const size = transactionSize(inputScriptLengths, outputScriptLengths)
|
|
128
116
|
return size
|
|
@@ -131,13 +119,8 @@ export async function generateChangeSdk(
|
|
|
131
119
|
/**
|
|
132
120
|
* @returns the target fee required for the transaction as currently configured under feeModel.
|
|
133
121
|
*/
|
|
134
|
-
const feeTarget = (
|
|
135
|
-
addedChangeInputs
|
|
136
|
-
addedChangeOutputs?: number
|
|
137
|
-
): number => {
|
|
138
|
-
const fee = Math.ceil(
|
|
139
|
-
(size(addedChangeInputs, addedChangeOutputs) / 1000) * satsPerKb
|
|
140
|
-
)
|
|
122
|
+
const feeTarget = (addedChangeInputs?: number, addedChangeOutputs?: number): number => {
|
|
123
|
+
const fee = Math.ceil((size(addedChangeInputs, addedChangeOutputs) / 1000) * satsPerKb)
|
|
141
124
|
return fee
|
|
142
125
|
}
|
|
143
126
|
|
|
@@ -152,15 +135,8 @@ export async function generateChangeSdk(
|
|
|
152
135
|
*
|
|
153
136
|
* A negative value means the transaction is under funded, or over spends, and may be rejected.
|
|
154
137
|
*/
|
|
155
|
-
const feeExcess = (
|
|
156
|
-
addedChangeInputs
|
|
157
|
-
addedChangeOutputs?: number
|
|
158
|
-
): number => {
|
|
159
|
-
const fe =
|
|
160
|
-
funding() -
|
|
161
|
-
spending() -
|
|
162
|
-
change() -
|
|
163
|
-
feeTarget(addedChangeInputs, addedChangeOutputs)
|
|
138
|
+
const feeExcess = (addedChangeInputs?: number, addedChangeOutputs?: number): number => {
|
|
139
|
+
const fe = funding() - spending() - change() - feeTarget(addedChangeInputs, addedChangeOutputs)
|
|
164
140
|
if (!addedChangeInputs && !addedChangeOutputs) feeExcessNow = fe
|
|
165
141
|
return fe
|
|
166
142
|
}
|
|
@@ -199,10 +175,7 @@ export async function generateChangeSdk(
|
|
|
199
175
|
(r.changeOutputs.length === 0 && feeExcess() > 0)
|
|
200
176
|
) {
|
|
201
177
|
r.changeOutputs.push({
|
|
202
|
-
satoshis:
|
|
203
|
-
r.changeOutputs.length === 0
|
|
204
|
-
? params.changeFirstSatoshis
|
|
205
|
-
: params.changeInitialSatoshis,
|
|
178
|
+
satoshis: r.changeOutputs.length === 0 ? params.changeFirstSatoshis : params.changeInitialSatoshis,
|
|
206
179
|
lockingScriptLength: params.changeLockingScriptLength
|
|
207
180
|
})
|
|
208
181
|
}
|
|
@@ -218,13 +191,9 @@ export async function generateChangeSdk(
|
|
|
218
191
|
exactSatoshis = -feeExcess(1)
|
|
219
192
|
}
|
|
220
193
|
const ao = addOutputToBalanceNewInput() ? 1 : 0
|
|
221
|
-
const targetSatoshis =
|
|
222
|
-
-feeExcess(1, ao) + (ao === 1 ? 2 * params.changeInitialSatoshis : 0)
|
|
194
|
+
const targetSatoshis = -feeExcess(1, ao) + (ao === 1 ? 2 * params.changeInitialSatoshis : 0)
|
|
223
195
|
|
|
224
|
-
const allocatedChangeInput = await allocateChangeInput(
|
|
225
|
-
targetSatoshis,
|
|
226
|
-
exactSatoshis
|
|
227
|
-
)
|
|
196
|
+
const allocatedChangeInput = await allocateChangeInput(targetSatoshis, exactSatoshis)
|
|
228
197
|
|
|
229
198
|
if (!allocatedChangeInput) {
|
|
230
199
|
// Unable to add another funding change input
|
|
@@ -238,9 +207,7 @@ export async function generateChangeSdk(
|
|
|
238
207
|
r.changeOutputs.push({
|
|
239
208
|
satoshis: Math.min(
|
|
240
209
|
feeExcess(),
|
|
241
|
-
r.changeOutputs.length === 0
|
|
242
|
-
? params.changeFirstSatoshis
|
|
243
|
-
: params.changeInitialSatoshis
|
|
210
|
+
r.changeOutputs.length === 0 ? params.changeFirstSatoshis : params.changeInitialSatoshis
|
|
244
211
|
),
|
|
245
212
|
lockingScriptLength: params.changeLockingScriptLength
|
|
246
213
|
})
|
|
@@ -280,11 +247,7 @@ export async function generateChangeSdk(
|
|
|
280
247
|
|
|
281
248
|
if (feeExcess() < 0 && vgcpr.hasMaxPossibleOutput !== undefined) {
|
|
282
249
|
// Reduce the fixed output with satoshis of maxPossibleSatoshis to what will just fund the transaction...
|
|
283
|
-
if (
|
|
284
|
-
fixedOutputs[vgcpr.hasMaxPossibleOutput].satoshis !==
|
|
285
|
-
maxPossibleSatoshis
|
|
286
|
-
)
|
|
287
|
-
throw new sdk.WERR_INTERNAL()
|
|
250
|
+
if (fixedOutputs[vgcpr.hasMaxPossibleOutput].satoshis !== maxPossibleSatoshis) throw new sdk.WERR_INTERNAL()
|
|
288
251
|
fixedOutputs[vgcpr.hasMaxPossibleOutput].satoshis += feeExcess()
|
|
289
252
|
r.maxPossibleSatoshisAdjustment = {
|
|
290
253
|
fixedOutputIndex: vgcpr.hasMaxPossibleOutput,
|
|
@@ -296,20 +259,14 @@ export async function generateChangeSdk(
|
|
|
296
259
|
* Trigger an account funding event if we don't have enough to cover this transaction.
|
|
297
260
|
*/
|
|
298
261
|
if (feeExcess() < 0) {
|
|
299
|
-
throw new sdk.WERR_INSUFFICIENT_FUNDS(
|
|
300
|
-
spending() + feeTarget(),
|
|
301
|
-
-feeExcessNow
|
|
302
|
-
)
|
|
262
|
+
throw new sdk.WERR_INSUFFICIENT_FUNDS(spending() + feeTarget(), -feeExcessNow)
|
|
303
263
|
}
|
|
304
264
|
|
|
305
265
|
/**
|
|
306
266
|
* If needed, seek funding to avoid overspending on fees without a change output to recapture it.
|
|
307
267
|
*/
|
|
308
268
|
if (r.changeOutputs.length === 0 && feeExcessNow > 0) {
|
|
309
|
-
throw new sdk.WERR_INSUFFICIENT_FUNDS(
|
|
310
|
-
spending() + feeTarget(),
|
|
311
|
-
params.changeFirstSatoshis
|
|
312
|
-
)
|
|
269
|
+
throw new sdk.WERR_INSUFFICIENT_FUNDS(spending() + feeTarget(), params.changeFirstSatoshis)
|
|
313
270
|
}
|
|
314
271
|
|
|
315
272
|
/**
|
|
@@ -320,18 +277,12 @@ export async function generateChangeSdk(
|
|
|
320
277
|
r.changeOutputs[0].satoshis += feeExcessNow
|
|
321
278
|
feeExcessNow = 0
|
|
322
279
|
} else if (r.changeOutputs[0].satoshis < params.changeInitialSatoshis) {
|
|
323
|
-
const sats = Math.min(
|
|
324
|
-
feeExcessNow,
|
|
325
|
-
params.changeInitialSatoshis - r.changeOutputs[0].satoshis
|
|
326
|
-
)
|
|
280
|
+
const sats = Math.min(feeExcessNow, params.changeInitialSatoshis - r.changeOutputs[0].satoshis)
|
|
327
281
|
feeExcessNow -= sats
|
|
328
282
|
r.changeOutputs[0].satoshis += sats
|
|
329
283
|
} else {
|
|
330
284
|
// Distribute a random percentage between 25% and 50% but at least one satoshi
|
|
331
|
-
const sats = Math.max(
|
|
332
|
-
1,
|
|
333
|
-
Math.floor((rand(2500, 5000) / 10000) * feeExcessNow)
|
|
334
|
-
)
|
|
285
|
+
const sats = Math.max(1, Math.floor((rand(2500, 5000) / 10000) * feeExcessNow))
|
|
335
286
|
feeExcessNow -= sats
|
|
336
287
|
const index = rand(0, r.changeOutputs.length - 1)
|
|
337
288
|
r.changeOutputs[index].satoshis += sats
|
|
@@ -370,11 +321,9 @@ export function validateGenerateChangeSdkResult(
|
|
|
370
321
|
let ok = true
|
|
371
322
|
let log = ''
|
|
372
323
|
const sumIn =
|
|
373
|
-
params.fixedInputs.reduce((a, e) => a + e.satoshis, 0) +
|
|
374
|
-
r.allocatedChangeInputs.reduce((a, e) => a + e.satoshis, 0)
|
|
324
|
+
params.fixedInputs.reduce((a, e) => a + e.satoshis, 0) + r.allocatedChangeInputs.reduce((a, e) => a + e.satoshis, 0)
|
|
375
325
|
const sumOut =
|
|
376
|
-
params.fixedOutputs.reduce((a, e) => a + e.satoshis, 0) +
|
|
377
|
-
r.changeOutputs.reduce((a, e) => a + e.satoshis, 0)
|
|
326
|
+
params.fixedOutputs.reduce((a, e) => a + e.satoshis, 0) + r.changeOutputs.reduce((a, e) => a + e.satoshis, 0)
|
|
378
327
|
if (r.fee && Number.isInteger(r.fee) && r.fee < 0) {
|
|
379
328
|
log += `basic fee error ${r.fee};`
|
|
380
329
|
ok = false
|
|
@@ -393,14 +342,9 @@ export function validateGenerateChangeSdkResult(
|
|
|
393
342
|
return { ok, log }
|
|
394
343
|
}
|
|
395
344
|
|
|
396
|
-
function logGenerateChangeSdkParams(
|
|
397
|
-
params: GenerateChangeSdkParams,
|
|
398
|
-
eu?: unknown
|
|
399
|
-
) {
|
|
345
|
+
function logGenerateChangeSdkParams(params: GenerateChangeSdkParams, eu?: unknown) {
|
|
400
346
|
let s = JSON.stringify(params)
|
|
401
|
-
console.log(
|
|
402
|
-
`generateChangeSdk params length ${s.length}${eu ? ` error: ${eu}` : ''}`
|
|
403
|
-
)
|
|
347
|
+
console.log(`generateChangeSdk params length ${s.length}${eu ? ` error: ${eu}` : ''}`)
|
|
404
348
|
let i = -1
|
|
405
349
|
const maxlen = 99900
|
|
406
350
|
for (;;) {
|
|
@@ -478,31 +422,19 @@ export interface ValidateGenerateChangeSdkParamsResult {
|
|
|
478
422
|
export function validateGenerateChangeSdkParams(
|
|
479
423
|
params: GenerateChangeSdkParams
|
|
480
424
|
): ValidateGenerateChangeSdkParamsResult {
|
|
481
|
-
if (!Array.isArray(params.fixedInputs))
|
|
482
|
-
throw new sdk.WERR_INVALID_PARAMETER('fixedInputs', 'an array of objects')
|
|
425
|
+
if (!Array.isArray(params.fixedInputs)) throw new sdk.WERR_INVALID_PARAMETER('fixedInputs', 'an array of objects')
|
|
483
426
|
|
|
484
427
|
const r: ValidateGenerateChangeSdkParamsResult = {}
|
|
485
428
|
|
|
486
429
|
params.fixedInputs.forEach((x, i) => {
|
|
487
430
|
sdk.validateSatoshis(x.satoshis, `fixedInputs[${i}].satoshis`)
|
|
488
|
-
sdk.validateInteger(
|
|
489
|
-
x.unlockingScriptLength,
|
|
490
|
-
`fixedInputs[${i}].unlockingScriptLength`,
|
|
491
|
-
undefined,
|
|
492
|
-
0
|
|
493
|
-
)
|
|
431
|
+
sdk.validateInteger(x.unlockingScriptLength, `fixedInputs[${i}].unlockingScriptLength`, undefined, 0)
|
|
494
432
|
})
|
|
495
433
|
|
|
496
|
-
if (!Array.isArray(params.fixedOutputs))
|
|
497
|
-
throw new sdk.WERR_INVALID_PARAMETER('fixedOutputs', 'an array of objects')
|
|
434
|
+
if (!Array.isArray(params.fixedOutputs)) throw new sdk.WERR_INVALID_PARAMETER('fixedOutputs', 'an array of objects')
|
|
498
435
|
params.fixedOutputs.forEach((x, i) => {
|
|
499
436
|
sdk.validateSatoshis(x.satoshis, `fixedOutputs[${i}].satoshis`)
|
|
500
|
-
sdk.validateInteger(
|
|
501
|
-
x.lockingScriptLength,
|
|
502
|
-
`fixedOutputs[${i}].lockingScriptLength`,
|
|
503
|
-
undefined,
|
|
504
|
-
0
|
|
505
|
-
)
|
|
437
|
+
sdk.validateInteger(x.lockingScriptLength, `fixedOutputs[${i}].lockingScriptLength`, undefined, 0)
|
|
506
438
|
if (x.satoshis === maxPossibleSatoshis) {
|
|
507
439
|
if (r.hasMaxPossibleOutput !== undefined)
|
|
508
440
|
throw new sdk.WERR_INVALID_PARAMETER(
|
|
@@ -514,34 +446,24 @@ export function validateGenerateChangeSdkParams(
|
|
|
514
446
|
})
|
|
515
447
|
|
|
516
448
|
params.feeModel = validateStorageFeeModel(params.feeModel)
|
|
517
|
-
if (params.feeModel.model !== 'sat/kb')
|
|
518
|
-
throw new sdk.WERR_INVALID_PARAMETER('feeModel.model', `'sat/kb'`)
|
|
449
|
+
if (params.feeModel.model !== 'sat/kb') throw new sdk.WERR_INVALID_PARAMETER('feeModel.model', `'sat/kb'`)
|
|
519
450
|
|
|
520
451
|
sdk.validateOptionalInteger(params.targetNetCount, `targetNetCount`)
|
|
521
452
|
|
|
522
453
|
sdk.validateSatoshis(params.changeFirstSatoshis, 'changeFirstSatoshis', 1)
|
|
523
454
|
sdk.validateSatoshis(params.changeInitialSatoshis, 'changeInitialSatoshis', 1)
|
|
524
455
|
|
|
525
|
-
sdk.validateInteger(
|
|
526
|
-
|
|
527
|
-
`changeLockingScriptLength`
|
|
528
|
-
)
|
|
529
|
-
sdk.validateInteger(
|
|
530
|
-
params.changeUnlockingScriptLength,
|
|
531
|
-
`changeUnlockingScriptLength`
|
|
532
|
-
)
|
|
456
|
+
sdk.validateInteger(params.changeLockingScriptLength, `changeLockingScriptLength`)
|
|
457
|
+
sdk.validateInteger(params.changeUnlockingScriptLength, `changeUnlockingScriptLength`)
|
|
533
458
|
|
|
534
459
|
return r
|
|
535
460
|
}
|
|
536
461
|
|
|
537
|
-
export interface GenerateChangeSdkStorageChange
|
|
538
|
-
extends GenerateChangeSdkChangeInput {
|
|
462
|
+
export interface GenerateChangeSdkStorageChange extends GenerateChangeSdkChangeInput {
|
|
539
463
|
spendable: boolean
|
|
540
464
|
}
|
|
541
465
|
|
|
542
|
-
export function generateChangeSdkMakeStorage(
|
|
543
|
-
availableChange: GenerateChangeSdkChangeInput[]
|
|
544
|
-
): {
|
|
466
|
+
export function generateChangeSdkMakeStorage(availableChange: GenerateChangeSdkChangeInput[]): {
|
|
545
467
|
allocateChangeInput: (
|
|
546
468
|
targetSatoshis: number,
|
|
547
469
|
exactSatoshis?: number
|
|
@@ -583,9 +505,7 @@ export function generateChangeSdkMakeStorage(
|
|
|
583
505
|
log += `allocate target ${targetSatoshis} exact ${exactSatoshis}`
|
|
584
506
|
|
|
585
507
|
if (exactSatoshis !== undefined) {
|
|
586
|
-
const exact = change.find(
|
|
587
|
-
c => c.spendable && c.satoshis === exactSatoshis
|
|
588
|
-
)
|
|
508
|
+
const exact = change.find(c => c.spendable && c.satoshis === exactSatoshis)
|
|
589
509
|
if (exact) return allocate(exact)
|
|
590
510
|
}
|
|
591
511
|
const over = change.find(c => c.spendable && c.satoshis >= targetSatoshis)
|
|
@@ -606,8 +526,7 @@ export function generateChangeSdkMakeStorage(
|
|
|
606
526
|
log += `release id ${outputId}\n`
|
|
607
527
|
const c = change.find(x => x.outputId === outputId)
|
|
608
528
|
if (!c) throw new sdk.WERR_INTERNAL(`unknown outputId ${outputId}`)
|
|
609
|
-
if (c.spendable)
|
|
610
|
-
throw new sdk.WERR_INTERNAL(`release of spendable outputId ${outputId}`)
|
|
529
|
+
if (c.spendable) throw new sdk.WERR_INTERNAL(`release of spendable outputId ${outputId}`)
|
|
611
530
|
c.spendable = true
|
|
612
531
|
}
|
|
613
532
|
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { Beef } from '@bsv/sdk'
|
|
2
|
-
import {
|
|
3
|
-
asBsvSdkTx,
|
|
4
|
-
EntityProvenTx,
|
|
5
|
-
sdk,
|
|
6
|
-
StorageProvider,
|
|
7
|
-
verifyTruthy
|
|
8
|
-
} from '../../index.client'
|
|
2
|
+
import { asBsvSdkTx, EntityProvenTx, sdk, StorageProvider, verifyTruthy } from '../../index.client'
|
|
9
3
|
|
|
10
4
|
/**
|
|
11
5
|
* Creates a `Beef` to support the validity of a transaction identified by its `txid`.
|
|
@@ -67,9 +61,7 @@ async function mergeBeefForTransactionRecurse(
|
|
|
67
61
|
): Promise<Beef> {
|
|
68
62
|
const maxDepth = storage.maxRecursionDepth
|
|
69
63
|
if (maxDepth && maxDepth <= recursionDepth)
|
|
70
|
-
throw new sdk.WERR_INVALID_OPERATION(
|
|
71
|
-
`Maximum BEEF depth exceeded. Limit is ${storage.maxRecursionDepth}`
|
|
72
|
-
)
|
|
64
|
+
throw new sdk.WERR_INVALID_OPERATION(`Maximum BEEF depth exceeded. Limit is ${storage.maxRecursionDepth}`)
|
|
73
65
|
|
|
74
66
|
if (options.knownTxids && options.knownTxids.indexOf(txid) > -1) {
|
|
75
67
|
// This txid is one of the txids the caller claims to already know are valid...
|
|
@@ -79,30 +71,18 @@ async function mergeBeefForTransactionRecurse(
|
|
|
79
71
|
|
|
80
72
|
if (!options.ignoreStorage) {
|
|
81
73
|
// if we can use storage, ask storage if it has the txid
|
|
82
|
-
const knownBeef = await storage.getValidBeefForTxid(
|
|
83
|
-
txid,
|
|
84
|
-
beef,
|
|
85
|
-
options.trustSelf,
|
|
86
|
-
options.knownTxids
|
|
87
|
-
)
|
|
74
|
+
const knownBeef = await storage.getValidBeefForTxid(txid, beef, options.trustSelf, options.knownTxids)
|
|
88
75
|
if (knownBeef) return knownBeef
|
|
89
76
|
}
|
|
90
77
|
|
|
91
78
|
if (options.ignoreServices)
|
|
92
|
-
throw new sdk.WERR_INVALID_PARAMETER(
|
|
93
|
-
`txid ${txid}`,
|
|
94
|
-
`valid transaction on chain ${storage.chain}`
|
|
95
|
-
)
|
|
79
|
+
throw new sdk.WERR_INVALID_PARAMETER(`txid ${txid}`, `valid transaction on chain ${storage.chain}`)
|
|
96
80
|
|
|
97
81
|
// if storage doesn't know about txid, use services
|
|
98
82
|
// to find it and if it has a proof, remember it.
|
|
99
83
|
const r = await getProvenOrRawTxFromServices(storage, txid, options)
|
|
100
84
|
|
|
101
|
-
if (
|
|
102
|
-
r.proven &&
|
|
103
|
-
options.minProofLevel &&
|
|
104
|
-
options.minProofLevel > recursionDepth
|
|
105
|
-
) {
|
|
85
|
+
if (r.proven && options.minProofLevel && options.minProofLevel > recursionDepth) {
|
|
106
86
|
// ignore proof at this recursion depth
|
|
107
87
|
r.proven = undefined
|
|
108
88
|
}
|
|
@@ -115,11 +95,7 @@ async function mergeBeefForTransactionRecurse(
|
|
|
115
95
|
return beef
|
|
116
96
|
}
|
|
117
97
|
|
|
118
|
-
if (!r.rawTx)
|
|
119
|
-
throw new sdk.WERR_INVALID_PARAMETER(
|
|
120
|
-
`txid ${txid}`,
|
|
121
|
-
`valid transaction on chain ${storage.chain}`
|
|
122
|
-
)
|
|
98
|
+
if (!r.rawTx) throw new sdk.WERR_INVALID_PARAMETER(`txid ${txid}`, `valid transaction on chain ${storage.chain}`)
|
|
123
99
|
|
|
124
100
|
// merge the raw transaction and recurse over its inputs.
|
|
125
101
|
beef.mergeRawTx(r.rawTx!)
|
|
@@ -129,13 +105,7 @@ async function mergeBeefForTransactionRecurse(
|
|
|
129
105
|
const inputTxid = verifyTruthy(input.sourceTXID)
|
|
130
106
|
if (!beef.findTxid(inputTxid)) {
|
|
131
107
|
// Only if the txid is not already in the list of beef transactions.
|
|
132
|
-
await mergeBeefForTransactionRecurse(
|
|
133
|
-
beef,
|
|
134
|
-
storage,
|
|
135
|
-
inputTxid,
|
|
136
|
-
options,
|
|
137
|
-
recursionDepth + 1
|
|
138
|
-
)
|
|
108
|
+
await mergeBeefForTransactionRecurse(beef, storage, inputTxid, options, recursionDepth + 1)
|
|
139
109
|
}
|
|
140
110
|
}
|
|
141
111
|
|
|
@@ -22,10 +22,7 @@ import { StorageReader } from '../StorageReader'
|
|
|
22
22
|
* @param args
|
|
23
23
|
* @returns
|
|
24
24
|
*/
|
|
25
|
-
export async function getSyncChunk(
|
|
26
|
-
storage: StorageReader,
|
|
27
|
-
args: sdk.RequestSyncChunkArgs
|
|
28
|
-
): Promise<sdk.SyncChunk> {
|
|
25
|
+
export async function getSyncChunk(storage: StorageReader, args: sdk.RequestSyncChunkArgs): Promise<sdk.SyncChunk> {
|
|
29
26
|
const r: sdk.SyncChunk = {
|
|
30
27
|
fromStorageIdentityKey: args.fromStorageIdentityKey,
|
|
31
28
|
toStorageIdentityKey: args.toStorageIdentityKey,
|
|
@@ -37,9 +34,7 @@ export async function getSyncChunk(
|
|
|
37
34
|
let i = 0
|
|
38
35
|
let done = false
|
|
39
36
|
|
|
40
|
-
const user = verifyTruthy(
|
|
41
|
-
await storage.findUserByIdentityKey(args.identityKey)
|
|
42
|
-
)
|
|
37
|
+
const user = verifyTruthy(await storage.findUserByIdentityKey(args.identityKey))
|
|
43
38
|
if (!args.since || user.updated_at > new Date(args.since)) r.user = user
|
|
44
39
|
|
|
45
40
|
const chunkers: ChunkerArgs[] = [
|
|
@@ -52,10 +47,7 @@ export async function getSyncChunk(
|
|
|
52
47
|
addItem: (i: TableProvenTx) => {
|
|
53
48
|
r.provenTxs!.push(i)
|
|
54
49
|
},
|
|
55
|
-
findItems: async (
|
|
56
|
-
storage: StorageReader,
|
|
57
|
-
args: sdk.FindForUserSincePagedArgs
|
|
58
|
-
) => {
|
|
50
|
+
findItems: async (storage: StorageReader, args: sdk.FindForUserSincePagedArgs) => {
|
|
59
51
|
return await storage.getProvenTxsForUser(args)
|
|
60
52
|
}
|
|
61
53
|
},
|
|
@@ -68,10 +60,7 @@ export async function getSyncChunk(
|
|
|
68
60
|
addItem: (i: TableOutputBasket) => {
|
|
69
61
|
r.outputBaskets!.push(i)
|
|
70
62
|
},
|
|
71
|
-
findItems: async (
|
|
72
|
-
storage: StorageReader,
|
|
73
|
-
args: sdk.FindForUserSincePagedArgs
|
|
74
|
-
) => {
|
|
63
|
+
findItems: async (storage: StorageReader, args: sdk.FindForUserSincePagedArgs) => {
|
|
75
64
|
return await storage.findOutputBaskets({
|
|
76
65
|
partial: { userId: args.userId },
|
|
77
66
|
since: args.since,
|
|
@@ -88,10 +77,7 @@ export async function getSyncChunk(
|
|
|
88
77
|
addItem: (i: TableOutputTag) => {
|
|
89
78
|
r.outputTags!.push(i)
|
|
90
79
|
},
|
|
91
|
-
findItems: async (
|
|
92
|
-
storage: StorageReader,
|
|
93
|
-
args: sdk.FindForUserSincePagedArgs
|
|
94
|
-
) => {
|
|
80
|
+
findItems: async (storage: StorageReader, args: sdk.FindForUserSincePagedArgs) => {
|
|
95
81
|
return await storage.findOutputTags({
|
|
96
82
|
partial: { userId: args.userId },
|
|
97
83
|
since: args.since,
|
|
@@ -108,10 +94,7 @@ export async function getSyncChunk(
|
|
|
108
94
|
addItem: (i: TableTxLabel) => {
|
|
109
95
|
r.txLabels!.push(i)
|
|
110
96
|
},
|
|
111
|
-
findItems: async (
|
|
112
|
-
storage: StorageReader,
|
|
113
|
-
args: sdk.FindForUserSincePagedArgs
|
|
114
|
-
) => {
|
|
97
|
+
findItems: async (storage: StorageReader, args: sdk.FindForUserSincePagedArgs) => {
|
|
115
98
|
return await storage.findTxLabels({
|
|
116
99
|
partial: { userId: args.userId },
|
|
117
100
|
since: args.since,
|
|
@@ -128,10 +111,7 @@ export async function getSyncChunk(
|
|
|
128
111
|
addItem: (i: TableTransaction) => {
|
|
129
112
|
r.transactions!.push(i)
|
|
130
113
|
},
|
|
131
|
-
findItems: async (
|
|
132
|
-
storage: StorageReader,
|
|
133
|
-
args: sdk.FindForUserSincePagedArgs
|
|
134
|
-
) => {
|
|
114
|
+
findItems: async (storage: StorageReader, args: sdk.FindForUserSincePagedArgs) => {
|
|
135
115
|
return await storage.findTransactions({
|
|
136
116
|
partial: { userId: args.userId },
|
|
137
117
|
since: args.since,
|
|
@@ -148,10 +128,7 @@ export async function getSyncChunk(
|
|
|
148
128
|
addItem: (i: TableOutput) => {
|
|
149
129
|
r.outputs!.push(i)
|
|
150
130
|
},
|
|
151
|
-
findItems: async (
|
|
152
|
-
storage: StorageReader,
|
|
153
|
-
args: sdk.FindForUserSincePagedArgs
|
|
154
|
-
) => {
|
|
131
|
+
findItems: async (storage: StorageReader, args: sdk.FindForUserSincePagedArgs) => {
|
|
155
132
|
return await storage.findOutputs({
|
|
156
133
|
partial: { userId: args.userId },
|
|
157
134
|
since: args.since,
|
|
@@ -168,10 +145,7 @@ export async function getSyncChunk(
|
|
|
168
145
|
addItem: (i: TableTxLabelMap) => {
|
|
169
146
|
r.txLabelMaps!.push(i)
|
|
170
147
|
},
|
|
171
|
-
findItems: async (
|
|
172
|
-
storage: StorageReader,
|
|
173
|
-
args: sdk.FindForUserSincePagedArgs
|
|
174
|
-
) => {
|
|
148
|
+
findItems: async (storage: StorageReader, args: sdk.FindForUserSincePagedArgs) => {
|
|
175
149
|
return await storage.getTxLabelMapsForUser(args)
|
|
176
150
|
}
|
|
177
151
|
},
|
|
@@ -184,10 +158,7 @@ export async function getSyncChunk(
|
|
|
184
158
|
addItem: (i: TableOutputTagMap) => {
|
|
185
159
|
r.outputTagMaps!.push(i)
|
|
186
160
|
},
|
|
187
|
-
findItems: async (
|
|
188
|
-
storage: StorageReader,
|
|
189
|
-
args: sdk.FindForUserSincePagedArgs
|
|
190
|
-
) => {
|
|
161
|
+
findItems: async (storage: StorageReader, args: sdk.FindForUserSincePagedArgs) => {
|
|
191
162
|
return await storage.getOutputTagMapsForUser(args)
|
|
192
163
|
}
|
|
193
164
|
},
|
|
@@ -200,10 +171,7 @@ export async function getSyncChunk(
|
|
|
200
171
|
addItem: (i: TableCertificate) => {
|
|
201
172
|
r.certificates!.push(i)
|
|
202
173
|
},
|
|
203
|
-
findItems: async (
|
|
204
|
-
storage: StorageReader,
|
|
205
|
-
args: sdk.FindForUserSincePagedArgs
|
|
206
|
-
) => {
|
|
174
|
+
findItems: async (storage: StorageReader, args: sdk.FindForUserSincePagedArgs) => {
|
|
207
175
|
return await storage.findCertificates({
|
|
208
176
|
partial: { userId: args.userId },
|
|
209
177
|
since: args.since,
|
|
@@ -220,10 +188,7 @@ export async function getSyncChunk(
|
|
|
220
188
|
addItem: (i: TableCertificateField) => {
|
|
221
189
|
r.certificateFields!.push(i)
|
|
222
190
|
},
|
|
223
|
-
findItems: async (
|
|
224
|
-
storage: StorageReader,
|
|
225
|
-
args: sdk.FindForUserSincePagedArgs
|
|
226
|
-
) => {
|
|
191
|
+
findItems: async (storage: StorageReader, args: sdk.FindForUserSincePagedArgs) => {
|
|
227
192
|
return await storage.findCertificateFields({
|
|
228
193
|
partial: { userId: args.userId },
|
|
229
194
|
since: args.since,
|
|
@@ -240,10 +205,7 @@ export async function getSyncChunk(
|
|
|
240
205
|
addItem: (i: TableCommission) => {
|
|
241
206
|
r.commissions!.push(i)
|
|
242
207
|
},
|
|
243
|
-
findItems: async (
|
|
244
|
-
storage: StorageReader,
|
|
245
|
-
args: sdk.FindForUserSincePagedArgs
|
|
246
|
-
) => {
|
|
208
|
+
findItems: async (storage: StorageReader, args: sdk.FindForUserSincePagedArgs) => {
|
|
247
209
|
return await storage.findCommissions({
|
|
248
210
|
partial: { userId: args.userId },
|
|
249
211
|
since: args.since,
|
|
@@ -260,10 +222,7 @@ export async function getSyncChunk(
|
|
|
260
222
|
addItem: (i: TableProvenTxReq) => {
|
|
261
223
|
r.provenTxReqs!.push(i)
|
|
262
224
|
},
|
|
263
|
-
findItems: async (
|
|
264
|
-
storage: StorageReader,
|
|
265
|
-
args: sdk.FindForUserSincePagedArgs
|
|
266
|
-
) => {
|
|
225
|
+
findItems: async (storage: StorageReader, args: sdk.FindForUserSincePagedArgs) => {
|
|
267
226
|
return await storage.getProvenTxReqsForUser(args)
|
|
268
227
|
}
|
|
269
228
|
}
|
|
@@ -276,16 +235,10 @@ export async function getSyncChunk(
|
|
|
276
235
|
}
|
|
277
236
|
let { offset, name: oname } = args.offsets[i++]
|
|
278
237
|
if (a.name !== oname)
|
|
279
|
-
throw new sdk.WERR_INVALID_PARAMETER(
|
|
280
|
-
'offsets',
|
|
281
|
-
`in dependency order. '${a.name}' expected, found ${oname}.`
|
|
282
|
-
)
|
|
238
|
+
throw new sdk.WERR_INVALID_PARAMETER('offsets', `in dependency order. '${a.name}' expected, found ${oname}.`)
|
|
283
239
|
let preAddCalled = false
|
|
284
240
|
for (; !done; ) {
|
|
285
|
-
const limit = Math.min(
|
|
286
|
-
itemCount,
|
|
287
|
-
Math.max(10, args.maxItems / a.maxDivider)
|
|
288
|
-
)
|
|
241
|
+
const limit = Math.min(itemCount, Math.max(10, args.maxItems / a.maxDivider))
|
|
289
242
|
if (limit <= 0) break
|
|
290
243
|
const items = await a.findItems(storage, {
|
|
291
244
|
userId: user.userId,
|
|
@@ -325,10 +278,7 @@ type ChunkerArgs = {
|
|
|
325
278
|
maxDivider: number
|
|
326
279
|
preAdd: () => void
|
|
327
280
|
addItem: (i: any) => void
|
|
328
|
-
findItems: (
|
|
329
|
-
storage: StorageReader,
|
|
330
|
-
args: sdk.FindForUserSincePagedArgs
|
|
331
|
-
) => Promise<any[]>
|
|
281
|
+
findItems: (storage: StorageReader, args: sdk.FindForUserSincePagedArgs) => Promise<any[]>
|
|
332
282
|
}
|
|
333
283
|
|
|
334
284
|
function checkIsDate(v: any) {
|
|
@@ -339,7 +289,6 @@ function checkEntityValues(es: object[]) {
|
|
|
339
289
|
for (const e of es) {
|
|
340
290
|
checkIsDate(e['created_at'])
|
|
341
291
|
checkIsDate(e['updated_at'])
|
|
342
|
-
for (const key of Object.keys(e))
|
|
343
|
-
if (e[key] === null) throw new sdk.WERR_INVALID_OPERATION()
|
|
292
|
+
for (const key of Object.keys(e)) if (e[key] === null) throw new sdk.WERR_INVALID_OPERATION()
|
|
344
293
|
}
|
|
345
294
|
}
|