@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
|
@@ -69,11 +69,7 @@ export async function createAction(
|
|
|
69
69
|
*/
|
|
70
70
|
|
|
71
71
|
const userId = auth.userId!
|
|
72
|
-
const { storageBeef, beef, xinputs } = await validateRequiredInputs(
|
|
73
|
-
storage,
|
|
74
|
-
userId,
|
|
75
|
-
vargs
|
|
76
|
-
)
|
|
72
|
+
const { storageBeef, beef, xinputs } = await validateRequiredInputs(storage, userId, vargs)
|
|
77
73
|
const xoutputs = validateRequiredOutputs(storage, userId, vargs)
|
|
78
74
|
|
|
79
75
|
const changeBasketName = 'default'
|
|
@@ -84,18 +80,9 @@ export async function createAction(
|
|
|
84
80
|
`Invalid outputGeneration basket "${changeBasketName}"`
|
|
85
81
|
)
|
|
86
82
|
|
|
87
|
-
const noSendChangeIn = await validateNoSendChange(
|
|
88
|
-
storage,
|
|
89
|
-
userId,
|
|
90
|
-
vargs,
|
|
91
|
-
changeBasket
|
|
92
|
-
)
|
|
83
|
+
const noSendChangeIn = await validateNoSendChange(storage, userId, vargs, changeBasket)
|
|
93
84
|
|
|
94
|
-
const availableChangeCount = await storage.countChangeInputs(
|
|
95
|
-
userId,
|
|
96
|
-
changeBasket.basketId,
|
|
97
|
-
!vargs.isDelayed
|
|
98
|
-
)
|
|
85
|
+
const availableChangeCount = await storage.countChangeInputs(userId, changeBasket.basketId, !vargs.isDelayed)
|
|
99
86
|
|
|
100
87
|
const feeModel = validateStorageFeeModel(storage.feeModel)
|
|
101
88
|
|
|
@@ -111,49 +98,25 @@ export async function createAction(
|
|
|
111
98
|
transactionId: newTx.transactionId!
|
|
112
99
|
}
|
|
113
100
|
|
|
114
|
-
const {
|
|
115
|
-
|
|
116
|
-
changeOutputs,
|
|
117
|
-
derivationPrefix,
|
|
118
|
-
maxPossibleSatoshisAdjustment
|
|
119
|
-
} = await fundNewTransactionSdk(storage, userId, vargs, ctx)
|
|
101
|
+
const { allocatedChange, changeOutputs, derivationPrefix, maxPossibleSatoshisAdjustment } =
|
|
102
|
+
await fundNewTransactionSdk(storage, userId, vargs, ctx)
|
|
120
103
|
|
|
121
104
|
if (maxPossibleSatoshisAdjustment) {
|
|
122
105
|
const a = maxPossibleSatoshisAdjustment
|
|
123
|
-
if (ctx.xoutputs[a.fixedOutputIndex].satoshis !== maxPossibleSatoshis)
|
|
124
|
-
throw new sdk.WERR_INTERNAL()
|
|
106
|
+
if (ctx.xoutputs[a.fixedOutputIndex].satoshis !== maxPossibleSatoshis) throw new sdk.WERR_INTERNAL()
|
|
125
107
|
ctx.xoutputs[a.fixedOutputIndex].satoshis = a.satoshis
|
|
126
108
|
}
|
|
127
109
|
|
|
128
110
|
// The satoshis of the transaction is the satoshis we get back in change minus the satoshis we spend.
|
|
129
111
|
const satoshis =
|
|
130
|
-
changeOutputs.reduce((a, e) => a + e.satoshis!, 0) -
|
|
131
|
-
allocatedChange.reduce((a, e) => a + e.satoshis!, 0)
|
|
112
|
+
changeOutputs.reduce((a, e) => a + e.satoshis!, 0) - allocatedChange.reduce((a, e) => a + e.satoshis!, 0)
|
|
132
113
|
await storage.updateTransaction(newTx.transactionId!, { satoshis })
|
|
133
114
|
|
|
134
|
-
const { outputs, changeVouts } = await createNewOutputs(
|
|
135
|
-
storage,
|
|
136
|
-
userId,
|
|
137
|
-
vargs,
|
|
138
|
-
ctx,
|
|
139
|
-
changeOutputs
|
|
140
|
-
)
|
|
115
|
+
const { outputs, changeVouts } = await createNewOutputs(storage, userId, vargs, ctx, changeOutputs)
|
|
141
116
|
|
|
142
|
-
const inputBeef = await mergeAllocatedChangeBeefs(
|
|
143
|
-
storage,
|
|
144
|
-
userId,
|
|
145
|
-
vargs,
|
|
146
|
-
allocatedChange,
|
|
147
|
-
beef
|
|
148
|
-
)
|
|
117
|
+
const inputBeef = await mergeAllocatedChangeBeefs(storage, userId, vargs, allocatedChange, beef)
|
|
149
118
|
|
|
150
|
-
const inputs = await createNewInputs(
|
|
151
|
-
storage,
|
|
152
|
-
userId,
|
|
153
|
-
vargs,
|
|
154
|
-
ctx,
|
|
155
|
-
allocatedChange
|
|
156
|
-
)
|
|
119
|
+
const inputs = await createNewInputs(storage, userId, vargs, ctx, allocatedChange)
|
|
157
120
|
|
|
158
121
|
const r: sdk.StorageCreateActionResult = {
|
|
159
122
|
reference: newTx.reference!,
|
|
@@ -195,12 +158,7 @@ export interface XValidCreateActionOutput extends sdk.ValidCreateActionOutput {
|
|
|
195
158
|
keyOffset?: string
|
|
196
159
|
}
|
|
197
160
|
|
|
198
|
-
function makeDefaultOutput(
|
|
199
|
-
userId: number,
|
|
200
|
-
transactionId: number,
|
|
201
|
-
satoshis: number,
|
|
202
|
-
vout: number
|
|
203
|
-
): TableOutput {
|
|
161
|
+
function makeDefaultOutput(userId: number, transactionId: number, satoshis: number, vout: number): TableOutput {
|
|
204
162
|
const now = new Date()
|
|
205
163
|
const output: TableOutput = {
|
|
206
164
|
created_at: now,
|
|
@@ -264,10 +222,7 @@ async function createNewInputs(
|
|
|
264
222
|
for (const { i, o, unlockLen } of newInputs) {
|
|
265
223
|
vin++
|
|
266
224
|
if (o) {
|
|
267
|
-
if (!i && !unlockLen)
|
|
268
|
-
throw new sdk.WERR_INTERNAL(
|
|
269
|
-
`vin ${vin} non-fixedInput without unlockLen`
|
|
270
|
-
)
|
|
225
|
+
if (!i && !unlockLen) throw new sdk.WERR_INTERNAL(`vin ${vin} non-fixedInput without unlockLen`)
|
|
271
226
|
const sourceTransaction =
|
|
272
227
|
vargs.includeAllSourceTransactions && vargs.isSignAction
|
|
273
228
|
? await storage.getRawTxOfKnownValidTransaction(o.txid!)
|
|
@@ -280,10 +235,7 @@ async function createNewInputs(
|
|
|
280
235
|
sourceLockingScript: asString(o.lockingScript!),
|
|
281
236
|
sourceTransaction,
|
|
282
237
|
unlockingScriptLength: unlockLen ? unlockLen : i!.unlockingScriptLength,
|
|
283
|
-
providedBy:
|
|
284
|
-
i && o.providedBy === 'storage'
|
|
285
|
-
? 'you-and-storage'
|
|
286
|
-
: (o.providedBy! as sdk.StorageProvidedBy),
|
|
238
|
+
providedBy: i && o.providedBy === 'storage' ? 'you-and-storage' : (o.providedBy! as sdk.StorageProvidedBy),
|
|
287
239
|
type: o.type,
|
|
288
240
|
spendingDescription: o.spendingDescription || undefined,
|
|
289
241
|
derivationPrefix: o.derivationPrefix || undefined,
|
|
@@ -330,10 +282,7 @@ async function createNewOutputs(
|
|
|
330
282
|
const txBaskets: Record<string, TableOutputBasket> = {}
|
|
331
283
|
for (const xo of ctx.xoutputs) {
|
|
332
284
|
if (xo.basket !== undefined && !txBaskets[xo.basket])
|
|
333
|
-
txBaskets[xo.basket] = await storage.findOrInsertOutputBasket(
|
|
334
|
-
userId,
|
|
335
|
-
xo.basket!
|
|
336
|
-
)
|
|
285
|
+
txBaskets[xo.basket] = await storage.findOrInsertOutputBasket(userId, xo.basket!)
|
|
337
286
|
}
|
|
338
287
|
// Lookup output tags
|
|
339
288
|
const txTags: Record<string, TableOutputTag> = {}
|
|
@@ -361,12 +310,7 @@ async function createNewOutputs(
|
|
|
361
310
|
commissionId: 0
|
|
362
311
|
})
|
|
363
312
|
|
|
364
|
-
const o = makeDefaultOutput(
|
|
365
|
-
userId,
|
|
366
|
-
ctx.transactionId,
|
|
367
|
-
xo.satoshis,
|
|
368
|
-
xo.vout
|
|
369
|
-
)
|
|
313
|
+
const o = makeDefaultOutput(userId, ctx.transactionId, xo.satoshis, xo.vout)
|
|
370
314
|
o.lockingScript = lockingScript
|
|
371
315
|
o.providedBy = 'storage'
|
|
372
316
|
o.purpose = 'storage-commission'
|
|
@@ -378,12 +322,7 @@ async function createNewOutputs(
|
|
|
378
322
|
// The user wants tracking if they put their output in a basket
|
|
379
323
|
const basketId = !xo.basket ? undefined : txBaskets[xo.basket].basketId!
|
|
380
324
|
|
|
381
|
-
const o = makeDefaultOutput(
|
|
382
|
-
userId,
|
|
383
|
-
ctx.transactionId,
|
|
384
|
-
xo.satoshis,
|
|
385
|
-
xo.vout
|
|
386
|
-
)
|
|
325
|
+
const o = makeDefaultOutput(userId, ctx.transactionId, xo.satoshis, xo.vout)
|
|
387
326
|
o.lockingScript = lockingScript
|
|
388
327
|
o.basketId = basketId
|
|
389
328
|
o.customInstructions = xo.customInstructions
|
|
@@ -436,10 +375,7 @@ async function createNewOutputs(
|
|
|
436
375
|
shuffleArray(newVouts)
|
|
437
376
|
for (const no of newOutputs) {
|
|
438
377
|
vout++
|
|
439
|
-
if (no.o.vout !== vout)
|
|
440
|
-
throw new sdk.WERR_INTERNAL(
|
|
441
|
-
`new output ${vout} has out of order vout ${no.o.vout}`
|
|
442
|
-
)
|
|
378
|
+
if (no.o.vout !== vout) throw new sdk.WERR_INTERNAL(`new output ${vout} has out of order vout ${no.o.vout}`)
|
|
443
379
|
no.o.vout = newVouts[vout]
|
|
444
380
|
}
|
|
445
381
|
}
|
|
@@ -448,16 +384,12 @@ async function createNewOutputs(
|
|
|
448
384
|
for (const { o, tags } of newOutputs) {
|
|
449
385
|
o.outputId = await storage.insertOutput(o)
|
|
450
386
|
|
|
451
|
-
if (o.change && o.purpose === 'change' && o.providedBy === 'storage')
|
|
452
|
-
changeVouts.push(o.vout!)
|
|
387
|
+
if (o.change && o.purpose === 'change' && o.providedBy === 'storage') changeVouts.push(o.vout!)
|
|
453
388
|
|
|
454
389
|
// Add tags to the output
|
|
455
390
|
for (const tagName of tags) {
|
|
456
391
|
const tag = txTags[tagName]!
|
|
457
|
-
await storage.findOrInsertOutputTagMap(
|
|
458
|
-
verifyId(o.outputId),
|
|
459
|
-
verifyId(tag.outputTagId)
|
|
460
|
-
)
|
|
392
|
+
await storage.findOrInsertOutputTagMap(verifyId(o.outputId), verifyId(tag.outputTagId))
|
|
461
393
|
}
|
|
462
394
|
|
|
463
395
|
const ro: sdk.StorageCreateTransactionSdkOutput = {
|
|
@@ -466,8 +398,7 @@ async function createNewOutputs(
|
|
|
466
398
|
lockingScript: !o.lockingScript ? '' : asString(o.lockingScript),
|
|
467
399
|
providedBy: verifyTruthy(o.providedBy) as sdk.StorageProvidedBy,
|
|
468
400
|
purpose: o.purpose || undefined,
|
|
469
|
-
basket: Object.values(txBaskets).find(b => b.basketId === o.basketId)
|
|
470
|
-
?.name,
|
|
401
|
+
basket: Object.values(txBaskets).find(b => b.basketId === o.basketId)?.name,
|
|
471
402
|
tags: tags,
|
|
472
403
|
outputDescription: o.outputDescription,
|
|
473
404
|
derivationSuffix: o.derivationSuffix,
|
|
@@ -506,10 +437,7 @@ async function createNewTxRecord(
|
|
|
506
437
|
|
|
507
438
|
for (const label of vargs.labels) {
|
|
508
439
|
const txLabel = await storage.findOrInsertTxLabel(userId, label)
|
|
509
|
-
await storage.findOrInsertTxLabelMap(
|
|
510
|
-
verifyId(newTx.transactionId),
|
|
511
|
-
verifyId(txLabel.txLabelId)
|
|
512
|
-
)
|
|
440
|
+
await storage.findOrInsertTxLabelMap(verifyId(newTx.transactionId), verifyId(txLabel.txLabelId))
|
|
513
441
|
}
|
|
514
442
|
|
|
515
443
|
return newTx
|
|
@@ -559,9 +487,7 @@ function validateRequiredOutputs(
|
|
|
559
487
|
|
|
560
488
|
if (storage.commissionSatoshis > 0 && storage.commissionPubKeyHex) {
|
|
561
489
|
vout++
|
|
562
|
-
const { script, keyOffset } = createStorageServiceChargeScript(
|
|
563
|
-
storage.commissionPubKeyHex
|
|
564
|
-
)
|
|
490
|
+
const { script, keyOffset } = createStorageServiceChargeScript(storage.commissionPubKeyHex)
|
|
565
491
|
xoutputs.push({
|
|
566
492
|
lockingScript: script,
|
|
567
493
|
satoshis: storage.commissionSatoshis,
|
|
@@ -635,10 +561,7 @@ async function validateRequiredInputs(
|
|
|
635
561
|
for (const btx of beef.txs) {
|
|
636
562
|
if (btx.isTxidOnly) {
|
|
637
563
|
if (!trustSelf)
|
|
638
|
-
throw new sdk.WERR_INVALID_PARAMETER(
|
|
639
|
-
'inputBEEF',
|
|
640
|
-
`valid and contain complete proof data for ${btx.txid}`
|
|
641
|
-
)
|
|
564
|
+
throw new sdk.WERR_INVALID_PARAMETER('inputBEEF', `valid and contain complete proof data for ${btx.txid}`)
|
|
642
565
|
if (!inputTxids[btx.txid]) {
|
|
643
566
|
// inputTxids are checked next
|
|
644
567
|
const isKnown = await storage.verifyKnownValidTransaction(btx.txid)
|
|
@@ -655,27 +578,16 @@ async function validateRequiredInputs(
|
|
|
655
578
|
for (const txid of Object.keys(inputTxids)) {
|
|
656
579
|
let btx = beef.findTxid(txid)
|
|
657
580
|
if (!btx && trustSelf) {
|
|
658
|
-
if (await storage.verifyKnownValidTransaction(txid))
|
|
659
|
-
btx = beef.mergeTxidOnly(txid)
|
|
581
|
+
if (await storage.verifyKnownValidTransaction(txid)) btx = beef.mergeTxidOnly(txid)
|
|
660
582
|
}
|
|
661
583
|
if (!btx)
|
|
662
|
-
throw new sdk.WERR_INVALID_PARAMETER(
|
|
663
|
-
'inputBEEF',
|
|
664
|
-
`valid and contain proof data for possibly known ${txid}`
|
|
665
|
-
)
|
|
584
|
+
throw new sdk.WERR_INVALID_PARAMETER('inputBEEF', `valid and contain proof data for possibly known ${txid}`)
|
|
666
585
|
}
|
|
667
586
|
|
|
668
|
-
if (
|
|
669
|
-
|
|
670
|
-
) {
|
|
671
|
-
console.log(
|
|
672
|
-
`verifyInputBeef failed, inputBEEF failed to verify.\n${beef.toLogString()}\n`
|
|
673
|
-
)
|
|
587
|
+
if (!(await beef.verify(await storage.getServices().getChainTracker(), true))) {
|
|
588
|
+
console.log(`verifyInputBeef failed, inputBEEF failed to verify.\n${beef.toLogString()}\n`)
|
|
674
589
|
//console.log(`verifyInputBeef failed, inputBEEF failed to verify.\n${stampLogFormat(vargs.log)}\n${beef.toLogString()}\n`)
|
|
675
|
-
throw new sdk.WERR_INVALID_PARAMETER(
|
|
676
|
-
'inputBEEF',
|
|
677
|
-
'valid Beef when factoring options.trustSelf'
|
|
678
|
-
)
|
|
590
|
+
throw new sdk.WERR_INVALID_PARAMETER('inputBEEF', 'valid Beef when factoring options.trustSelf')
|
|
679
591
|
}
|
|
680
592
|
|
|
681
593
|
// beef may now be trusted and has a BeefTx for every input txid.
|
|
@@ -684,24 +596,13 @@ async function validateRequiredInputs(
|
|
|
684
596
|
|
|
685
597
|
for (const input of xinputs) {
|
|
686
598
|
const { txid, vout } = input.outpoint
|
|
687
|
-
const output = verifyOneOrNone(
|
|
688
|
-
await storage.findOutputs({ partial: { userId, txid, vout } })
|
|
689
|
-
)
|
|
599
|
+
const output = verifyOneOrNone(await storage.findOutputs({ partial: { userId, txid, vout } }))
|
|
690
600
|
if (output) {
|
|
691
601
|
input.output = output
|
|
692
|
-
if (
|
|
693
|
-
|
|
694
|
-
!Number.isInteger(output.satoshis)
|
|
695
|
-
)
|
|
696
|
-
throw new sdk.WERR_INVALID_PARAMETER(
|
|
697
|
-
`${txid}.${vout}`,
|
|
698
|
-
'output with valid lockingScript and satoshis'
|
|
699
|
-
)
|
|
602
|
+
if (!Array.isArray(output.lockingScript) || !Number.isInteger(output.satoshis))
|
|
603
|
+
throw new sdk.WERR_INVALID_PARAMETER(`${txid}.${vout}`, 'output with valid lockingScript and satoshis')
|
|
700
604
|
if (!output.spendable && !vargs.isNoSend)
|
|
701
|
-
throw new sdk.WERR_INVALID_PARAMETER(
|
|
702
|
-
`${txid}.${vout}`,
|
|
703
|
-
'spendable output unless noSend is true'
|
|
704
|
-
)
|
|
605
|
+
throw new sdk.WERR_INVALID_PARAMETER(`${txid}.${vout}`, 'spendable output unless noSend is true')
|
|
705
606
|
// input is spending an existing user output which has an lockingScript
|
|
706
607
|
input.satoshis = verifyNumber(output.satoshis)
|
|
707
608
|
input.lockingScript = Script.fromBinary(asArray(output.lockingScript!))
|
|
@@ -710,20 +611,12 @@ async function validateRequiredInputs(
|
|
|
710
611
|
if (btx.isTxidOnly) {
|
|
711
612
|
const { rawTx, proven } = await storage.getProvenOrRawTx(txid)
|
|
712
613
|
//stampLog(vargs, `... storage verifyInputBeef getProvenOrRawTx ${txid} ${proven ? 'proven' : rawTx ? 'rawTx' : 'unknown'}`)
|
|
713
|
-
if (!rawTx)
|
|
714
|
-
throw new sdk.WERR_INVALID_PARAMETER(
|
|
715
|
-
'inputBEEF',
|
|
716
|
-
`valid and contain proof data for ${txid}`
|
|
717
|
-
)
|
|
614
|
+
if (!rawTx) throw new sdk.WERR_INVALID_PARAMETER('inputBEEF', `valid and contain proof data for ${txid}`)
|
|
718
615
|
btx = beef.mergeRawTx(asArray(rawTx))
|
|
719
616
|
if (proven) beef.mergeBump(new EntityProvenTx(proven).getMerklePath())
|
|
720
617
|
}
|
|
721
618
|
// btx is valid has parsed transaction data.
|
|
722
|
-
if (vout >= btx.tx!.outputs.length)
|
|
723
|
-
throw new sdk.WERR_INVALID_PARAMETER(
|
|
724
|
-
`${txid}.${vout}`,
|
|
725
|
-
'valid outpoint'
|
|
726
|
-
)
|
|
619
|
+
if (vout >= btx.tx!.outputs.length) throw new sdk.WERR_INVALID_PARAMETER(`${txid}.${vout}`, 'valid outpoint')
|
|
727
620
|
const so = btx.tx!.outputs[vout]
|
|
728
621
|
input.satoshis = verifyTruthy(so.satoshis)
|
|
729
622
|
input.lockingScript = so.lockingScript
|
|
@@ -765,10 +658,7 @@ async function validateNoSendChange(
|
|
|
765
658
|
throw new sdk.WERR_INVALID_PARAMETER('noSendChange outpoint', 'valid')
|
|
766
659
|
if (-1 < r.findIndex(o => o.outputId === output.outputId))
|
|
767
660
|
// noSendChange duplicate OutPoints are not allowed.
|
|
768
|
-
throw new sdk.WERR_INVALID_PARAMETER(
|
|
769
|
-
'noSendChange outpoint',
|
|
770
|
-
'unique. Duplicates are not allowed.'
|
|
771
|
-
)
|
|
661
|
+
throw new sdk.WERR_INVALID_PARAMETER('noSendChange outpoint', 'unique. Duplicates are not allowed.')
|
|
772
662
|
r.push(output)
|
|
773
663
|
}
|
|
774
664
|
}
|
|
@@ -801,14 +691,10 @@ async function fundNewTransactionSdk(
|
|
|
801
691
|
})),
|
|
802
692
|
feeModel: ctx.feeModel,
|
|
803
693
|
changeInitialSatoshis: ctx.changeBasket.minimumDesiredUTXOValue,
|
|
804
|
-
changeFirstSatoshis: Math.max(
|
|
805
|
-
1,
|
|
806
|
-
Math.round(ctx.changeBasket.minimumDesiredUTXOValue / 4)
|
|
807
|
-
),
|
|
694
|
+
changeFirstSatoshis: Math.max(1, Math.round(ctx.changeBasket.minimumDesiredUTXOValue / 4)),
|
|
808
695
|
changeLockingScriptLength: 25,
|
|
809
696
|
changeUnlockingScriptLength: 107,
|
|
810
|
-
targetNetCount:
|
|
811
|
-
ctx.changeBasket.numberOfDesiredUTXOs - ctx.availableChangeCount,
|
|
697
|
+
targetNetCount: ctx.changeBasket.numberOfDesiredUTXOs - ctx.availableChangeCount,
|
|
812
698
|
randomVals: vargs.randomVals
|
|
813
699
|
}
|
|
814
700
|
|
|
@@ -867,11 +753,7 @@ async function fundNewTransactionSdk(
|
|
|
867
753
|
})
|
|
868
754
|
}
|
|
869
755
|
|
|
870
|
-
const gcr = await generateChangeSdk(
|
|
871
|
-
params,
|
|
872
|
-
allocateChangeInput,
|
|
873
|
-
releaseChangeInput
|
|
874
|
-
)
|
|
756
|
+
const gcr = await generateChangeSdk(params, allocateChangeInput, releaseChangeInput)
|
|
875
757
|
|
|
876
758
|
const nextRandomVal = (): number => {
|
|
877
759
|
let val = 0
|
|
@@ -888,11 +770,7 @@ async function fundNewTransactionSdk(
|
|
|
888
770
|
* @returns a random integer betweenn min and max, inclussive.
|
|
889
771
|
*/
|
|
890
772
|
const rand = (min: number, max: number): number => {
|
|
891
|
-
if (max < min)
|
|
892
|
-
throw new sdk.WERR_INVALID_PARAMETER(
|
|
893
|
-
'max',
|
|
894
|
-
`less than min (${min}). max is (${max})`
|
|
895
|
-
)
|
|
773
|
+
if (max < min) throw new sdk.WERR_INVALID_PARAMETER('max', `less than min (${min}). max is (${max})`)
|
|
896
774
|
return Math.floor(nextRandomVal() * (max - min + 1) + min)
|
|
897
775
|
}
|
|
898
776
|
|
|
@@ -963,15 +841,11 @@ async function fundNewTransactionSdk(
|
|
|
963
841
|
* in the `beef` to txidOnly.
|
|
964
842
|
* @returns undefined if `vargs.options.returnTXIDOnly` or trimmed `Beef`
|
|
965
843
|
*/
|
|
966
|
-
function trimInputBeef(
|
|
967
|
-
beef: Beef,
|
|
968
|
-
vargs: sdk.ValidCreateActionArgs
|
|
969
|
-
): number[] | undefined {
|
|
844
|
+
function trimInputBeef(beef: Beef, vargs: sdk.ValidCreateActionArgs): number[] | undefined {
|
|
970
845
|
if (vargs.options.returnTXIDOnly) return undefined
|
|
971
846
|
const knownTxids: Record<string, boolean> = {}
|
|
972
847
|
for (const txid of vargs.options.knownTxids) knownTxids[txid] = true
|
|
973
|
-
for (const txid of beef.txs.map(btx => btx.txid))
|
|
974
|
-
if (knownTxids[txid]) beef.makeTxidOnly(txid)
|
|
848
|
+
for (const txid of beef.txs.map(btx => btx.txid)) if (knownTxids[txid]) beef.makeTxidOnly(txid)
|
|
975
849
|
return beef.toBinary()
|
|
976
850
|
}
|
|
977
851
|
|
|
@@ -993,24 +867,17 @@ async function mergeAllocatedChangeBeefs(
|
|
|
993
867
|
}
|
|
994
868
|
if (vargs.options.returnTXIDOnly) return undefined
|
|
995
869
|
for (const o of allocatedChange) {
|
|
996
|
-
if (
|
|
997
|
-
!beef.findTxid(o.txid!) &&
|
|
998
|
-
!vargs.options.knownTxids.find(txid => txid === o.txid)
|
|
999
|
-
) {
|
|
870
|
+
if (!beef.findTxid(o.txid!) && !vargs.options.knownTxids.find(txid => txid === o.txid)) {
|
|
1000
871
|
await storage.getBeefForTransaction(o.txid!, options)
|
|
1001
872
|
}
|
|
1002
873
|
}
|
|
1003
874
|
return trimInputBeef(beef, vargs)
|
|
1004
875
|
}
|
|
1005
876
|
|
|
1006
|
-
function keyOffsetToHashedSecret(
|
|
1007
|
-
pub: PublicKey,
|
|
1008
|
-
keyOffset?: string
|
|
1009
|
-
): { hashedSecret: BigNumber; keyOffset: string } {
|
|
877
|
+
function keyOffsetToHashedSecret(pub: PublicKey, keyOffset?: string): { hashedSecret: BigNumber; keyOffset: string } {
|
|
1010
878
|
let offset: PrivateKey
|
|
1011
879
|
if (keyOffset !== undefined && typeof keyOffset === 'string') {
|
|
1012
|
-
if (keyOffset.length === 64)
|
|
1013
|
-
offset = PrivateKey.fromString(keyOffset, 'hex')
|
|
880
|
+
if (keyOffset.length === 64) offset = PrivateKey.fromString(keyOffset, 'hex')
|
|
1014
881
|
else offset = PrivateKey.fromWif(keyOffset)
|
|
1015
882
|
} else {
|
|
1016
883
|
offset = PrivateKey.fromRandom()
|
|
@@ -1023,10 +890,7 @@ function keyOffsetToHashedSecret(
|
|
|
1023
890
|
return { hashedSecret: new BigNumber(hashedSecret), keyOffset }
|
|
1024
891
|
}
|
|
1025
892
|
|
|
1026
|
-
export function offsetPubKey(
|
|
1027
|
-
pubKey: string,
|
|
1028
|
-
keyOffset?: string
|
|
1029
|
-
): { offsetPubKey: string; keyOffset: string } {
|
|
893
|
+
export function offsetPubKey(pubKey: string, keyOffset?: string): { offsetPubKey: string; keyOffset: string } {
|
|
1030
894
|
const pub = PublicKey.fromString(pubKey)
|
|
1031
895
|
|
|
1032
896
|
const r = keyOffsetToHashedSecret(pub, keyOffset)
|