@bsv/wallet-toolbox 1.1.0
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/.env.template +22 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +40 -0
- package/.github/ISSUE_TEMPLATE/discussion.md +24 -0
- package/.github/pull_request_template.md +24 -0
- package/.github/workflows/push.yaml +66 -0
- package/.prettierrc +10 -0
- package/CONTRIBUTING.md +89 -0
- package/LICENSE.txt +28 -0
- package/README.md +124 -0
- package/dev.sqlite3 +0 -0
- package/docs/README.md +15 -0
- package/docs/client.md +6812 -0
- package/docs/monitor.md +648 -0
- package/docs/services.md +496 -0
- package/docs/storage.md +1884 -0
- package/docs/wallet.md +6812 -0
- package/jest.config.ts +29 -0
- package/knexfile.js +9 -0
- package/license.md +1 -0
- package/out/src/Wallet.d.ts +83 -0
- package/out/src/Wallet.d.ts.map +1 -0
- package/out/src/Wallet.js +415 -0
- package/out/src/Wallet.js.map +1 -0
- package/out/src/index.all.d.ts +9 -0
- package/out/src/index.all.d.ts.map +1 -0
- package/out/src/index.all.js +48 -0
- package/out/src/index.all.js.map +1 -0
- package/out/src/index.client.d.ts +8 -0
- package/out/src/index.client.d.ts.map +1 -0
- package/out/src/index.client.js +47 -0
- package/out/src/index.client.js.map +1 -0
- package/out/src/index.d.ts +3 -0
- package/out/src/index.d.ts.map +1 -0
- package/out/src/index.js +42 -0
- package/out/src/index.js.map +1 -0
- package/out/src/monitor/Monitor.d.ts +89 -0
- package/out/src/monitor/Monitor.d.ts.map +1 -0
- package/out/src/monitor/Monitor.js +253 -0
- package/out/src/monitor/Monitor.js.map +1 -0
- package/out/src/monitor/MonitorDaemon.d.ts +30 -0
- package/out/src/monitor/MonitorDaemon.d.ts.map +1 -0
- package/out/src/monitor/MonitorDaemon.js +135 -0
- package/out/src/monitor/MonitorDaemon.js.map +1 -0
- package/out/src/monitor/__test/MonitorDaemon.man.test.d.ts +2 -0
- package/out/src/monitor/__test/MonitorDaemon.man.test.d.ts.map +1 -0
- package/out/src/monitor/__test/MonitorDaemon.man.test.js +50 -0
- package/out/src/monitor/__test/MonitorDaemon.man.test.js.map +1 -0
- package/out/src/monitor/tasks/TaskCheckForProofs.d.ts +53 -0
- package/out/src/monitor/tasks/TaskCheckForProofs.d.ts.map +1 -0
- package/out/src/monitor/tasks/TaskCheckForProofs.js +197 -0
- package/out/src/monitor/tasks/TaskCheckForProofs.js.map +1 -0
- package/out/src/monitor/tasks/TaskClock.d.ts +14 -0
- package/out/src/monitor/tasks/TaskClock.d.ts.map +1 -0
- package/out/src/monitor/tasks/TaskClock.js +27 -0
- package/out/src/monitor/tasks/TaskClock.js.map +1 -0
- package/out/src/monitor/tasks/TaskFailAbandoned.d.ts +20 -0
- package/out/src/monitor/tasks/TaskFailAbandoned.d.ts.map +1 -0
- package/out/src/monitor/tasks/TaskFailAbandoned.js +52 -0
- package/out/src/monitor/tasks/TaskFailAbandoned.js.map +1 -0
- package/out/src/monitor/tasks/TaskNewHeader.d.ts +15 -0
- package/out/src/monitor/tasks/TaskNewHeader.d.ts.map +1 -0
- package/out/src/monitor/tasks/TaskNewHeader.js +45 -0
- package/out/src/monitor/tasks/TaskNewHeader.js.map +1 -0
- package/out/src/monitor/tasks/TaskPurge.d.ts +45 -0
- package/out/src/monitor/tasks/TaskPurge.d.ts.map +1 -0
- package/out/src/monitor/tasks/TaskPurge.js +35 -0
- package/out/src/monitor/tasks/TaskPurge.js.map +1 -0
- package/out/src/monitor/tasks/TaskReviewStatus.d.ts +26 -0
- package/out/src/monitor/tasks/TaskReviewStatus.d.ts.map +1 -0
- package/out/src/monitor/tasks/TaskReviewStatus.js +44 -0
- package/out/src/monitor/tasks/TaskReviewStatus.js.map +1 -0
- package/out/src/monitor/tasks/TaskSendWaiting.d.ts +32 -0
- package/out/src/monitor/tasks/TaskSendWaiting.d.ts.map +1 -0
- package/out/src/monitor/tasks/TaskSendWaiting.js +99 -0
- package/out/src/monitor/tasks/TaskSendWaiting.js.map +1 -0
- package/out/src/monitor/tasks/TaskSyncWhenIdle.d.ts +12 -0
- package/out/src/monitor/tasks/TaskSyncWhenIdle.d.ts.map +1 -0
- package/out/src/monitor/tasks/TaskSyncWhenIdle.js +22 -0
- package/out/src/monitor/tasks/TaskSyncWhenIdle.js.map +1 -0
- package/out/src/monitor/tasks/WalletMonitorTask.d.ts +40 -0
- package/out/src/monitor/tasks/WalletMonitorTask.d.ts.map +1 -0
- package/out/src/monitor/tasks/WalletMonitorTask.js +37 -0
- package/out/src/monitor/tasks/WalletMonitorTask.js.map +1 -0
- package/out/src/sdk/CertOps.d.ts +66 -0
- package/out/src/sdk/CertOps.d.ts.map +1 -0
- package/out/src/sdk/CertOps.js +198 -0
- package/out/src/sdk/CertOps.js.map +1 -0
- package/out/src/sdk/PrivilegedKeyManager.d.ts +125 -0
- package/out/src/sdk/PrivilegedKeyManager.d.ts.map +1 -0
- package/out/src/sdk/PrivilegedKeyManager.js +293 -0
- package/out/src/sdk/PrivilegedKeyManager.js.map +1 -0
- package/out/src/sdk/StorageSyncReader.d.ts +121 -0
- package/out/src/sdk/StorageSyncReader.d.ts.map +1 -0
- package/out/src/sdk/StorageSyncReader.js +3 -0
- package/out/src/sdk/StorageSyncReader.js.map +1 -0
- package/out/src/sdk/StorageSyncReaderWriter.d.ts +89 -0
- package/out/src/sdk/StorageSyncReaderWriter.d.ts.map +1 -0
- package/out/src/sdk/StorageSyncReaderWriter.js +3 -0
- package/out/src/sdk/StorageSyncReaderWriter.js.map +1 -0
- package/out/src/sdk/WERR_errors.d.ts +90 -0
- package/out/src/sdk/WERR_errors.d.ts.map +1 -0
- package/out/src/sdk/WERR_errors.js +128 -0
- package/out/src/sdk/WERR_errors.js.map +1 -0
- package/out/src/sdk/WalletError.d.ts +45 -0
- package/out/src/sdk/WalletError.d.ts.map +1 -0
- package/out/src/sdk/WalletError.js +122 -0
- package/out/src/sdk/WalletError.js.map +1 -0
- package/out/src/sdk/WalletServices.interfaces.d.ts +325 -0
- package/out/src/sdk/WalletServices.interfaces.d.ts.map +1 -0
- package/out/src/sdk/WalletServices.interfaces.js +3 -0
- package/out/src/sdk/WalletServices.interfaces.js.map +1 -0
- package/out/src/sdk/WalletSigner.interfaces.d.ts +10 -0
- package/out/src/sdk/WalletSigner.interfaces.d.ts.map +1 -0
- package/out/src/sdk/WalletSigner.interfaces.js +3 -0
- package/out/src/sdk/WalletSigner.interfaces.js.map +1 -0
- package/out/src/sdk/WalletStorage.interfaces.d.ts +299 -0
- package/out/src/sdk/WalletStorage.interfaces.d.ts.map +1 -0
- package/out/src/sdk/WalletStorage.interfaces.js +3 -0
- package/out/src/sdk/WalletStorage.interfaces.js.map +1 -0
- package/out/src/sdk/__test/CertificateLifeCycle.test.d.ts +2 -0
- package/out/src/sdk/__test/CertificateLifeCycle.test.d.ts.map +1 -0
- package/out/src/sdk/__test/CertificateLifeCycle.test.js +125 -0
- package/out/src/sdk/__test/CertificateLifeCycle.test.js.map +1 -0
- package/out/src/sdk/__test/PrivilegedKeyManager.test.d.ts +2 -0
- package/out/src/sdk/__test/PrivilegedKeyManager.test.d.ts.map +1 -0
- package/out/src/sdk/__test/PrivilegedKeyManager.test.js +660 -0
- package/out/src/sdk/__test/PrivilegedKeyManager.test.js.map +1 -0
- package/out/src/sdk/index.d.ts +12 -0
- package/out/src/sdk/index.d.ts.map +1 -0
- package/out/src/sdk/index.js +28 -0
- package/out/src/sdk/index.js.map +1 -0
- package/out/src/sdk/types.d.ts +74 -0
- package/out/src/sdk/types.d.ts.map +1 -0
- package/out/src/sdk/types.js +20 -0
- package/out/src/sdk/types.js.map +1 -0
- package/out/src/sdk/validationHelpers.d.ts +288 -0
- package/out/src/sdk/validationHelpers.d.ts.map +1 -0
- package/out/src/sdk/validationHelpers.js +630 -0
- package/out/src/sdk/validationHelpers.js.map +1 -0
- package/out/src/services/ServiceCollection.d.ts +25 -0
- package/out/src/services/ServiceCollection.d.ts.map +1 -0
- package/out/src/services/ServiceCollection.js +43 -0
- package/out/src/services/ServiceCollection.js.map +1 -0
- package/out/src/services/Services.d.ts +60 -0
- package/out/src/services/Services.d.ts.map +1 -0
- package/out/src/services/Services.js +342 -0
- package/out/src/services/Services.js.map +1 -0
- package/out/src/services/__tests/getMerklePath.test.d.ts +2 -0
- package/out/src/services/__tests/getMerklePath.test.d.ts.map +1 -0
- package/out/src/services/__tests/getMerklePath.test.js +16 -0
- package/out/src/services/__tests/getMerklePath.test.js.map +1 -0
- package/out/src/services/__tests/getRawTx.test.d.ts +2 -0
- package/out/src/services/__tests/getRawTx.test.d.ts.map +1 -0
- package/out/src/services/__tests/getRawTx.test.js +13 -0
- package/out/src/services/__tests/getRawTx.test.js.map +1 -0
- package/out/src/services/__tests/postBeef.test.d.ts +2 -0
- package/out/src/services/__tests/postBeef.test.d.ts.map +1 -0
- package/out/src/services/__tests/postBeef.test.js +18 -0
- package/out/src/services/__tests/postBeef.test.js.map +1 -0
- package/out/src/services/__tests/postBeefToArcTaal.test.d.ts +2 -0
- package/out/src/services/__tests/postBeefToArcTaal.test.d.ts.map +1 -0
- package/out/src/services/__tests/postBeefToArcTaal.test.js +479 -0
- package/out/src/services/__tests/postBeefToArcTaal.test.js.map +1 -0
- package/out/src/services/__tests/postTxs.test.d.ts +2 -0
- package/out/src/services/__tests/postTxs.test.d.ts.map +1 -0
- package/out/src/services/__tests/postTxs.test.js +19 -0
- package/out/src/services/__tests/postTxs.test.js.map +1 -0
- package/out/src/services/chaintracker/ChaintracksChainTracker.d.ts +15 -0
- package/out/src/services/chaintracker/ChaintracksChainTracker.d.ts.map +1 -0
- package/out/src/services/chaintracker/ChaintracksChainTracker.js +51 -0
- package/out/src/services/chaintracker/ChaintracksChainTracker.js.map +1 -0
- package/out/src/services/chaintracker/__tests/ChaintracksChainTracker.test.d.ts +2 -0
- package/out/src/services/chaintracker/__tests/ChaintracksChainTracker.test.d.ts.map +1 -0
- package/out/src/services/chaintracker/__tests/ChaintracksChainTracker.test.js +19 -0
- package/out/src/services/chaintracker/__tests/ChaintracksChainTracker.test.js.map +1 -0
- package/out/src/services/chaintracker/__tests/ChaintracksServiceClient.test.d.ts +2 -0
- package/out/src/services/chaintracker/__tests/ChaintracksServiceClient.test.d.ts.map +1 -0
- package/out/src/services/chaintracker/__tests/ChaintracksServiceClient.test.js +29 -0
- package/out/src/services/chaintracker/__tests/ChaintracksServiceClient.test.js.map +1 -0
- package/out/src/services/chaintracker/chaintracks/BlockHeaderApi.d.ts +98 -0
- package/out/src/services/chaintracker/chaintracks/BlockHeaderApi.d.ts.map +1 -0
- package/out/src/services/chaintracker/chaintracks/BlockHeaderApi.js +38 -0
- package/out/src/services/chaintracker/chaintracks/BlockHeaderApi.js.map +1 -0
- package/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.d.ts +36 -0
- package/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.d.ts.map +1 -0
- package/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.js +130 -0
- package/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.js.map +1 -0
- package/out/src/services/chaintracker/chaintracks/index.d.ts +3 -0
- package/out/src/services/chaintracker/chaintracks/index.d.ts.map +1 -0
- package/out/src/services/chaintracker/chaintracks/index.js +19 -0
- package/out/src/services/chaintracker/chaintracks/index.js.map +1 -0
- package/out/src/services/chaintracker/index.d.ts +3 -0
- package/out/src/services/chaintracker/index.d.ts.map +1 -0
- package/out/src/services/chaintracker/index.js +19 -0
- package/out/src/services/chaintracker/index.js.map +1 -0
- package/out/src/services/createDefaultWalletServicesOptions.d.ts +3 -0
- package/out/src/services/createDefaultWalletServicesOptions.d.ts.map +1 -0
- package/out/src/services/createDefaultWalletServicesOptions.js +34 -0
- package/out/src/services/createDefaultWalletServicesOptions.js.map +1 -0
- package/out/src/services/index.d.ts +2 -0
- package/out/src/services/index.d.ts.map +1 -0
- package/out/src/services/index.js +18 -0
- package/out/src/services/index.js.map +1 -0
- package/out/src/services/providers/arcServices.d.ts +62 -0
- package/out/src/services/providers/arcServices.d.ts.map +1 -0
- package/out/src/services/providers/arcServices.js +368 -0
- package/out/src/services/providers/arcServices.js.map +1 -0
- package/out/src/services/providers/echangeRates.d.ts +12 -0
- package/out/src/services/providers/echangeRates.d.ts.map +1 -0
- package/out/src/services/providers/echangeRates.js +237 -0
- package/out/src/services/providers/echangeRates.js.map +1 -0
- package/out/src/services/providers/whatsonchain.d.ts +17 -0
- package/out/src/services/providers/whatsonchain.d.ts.map +1 -0
- package/out/src/services/providers/whatsonchain.js +130 -0
- package/out/src/services/providers/whatsonchain.js.map +1 -0
- package/out/src/signer/WalletSigner.d.ts +11 -0
- package/out/src/signer/WalletSigner.d.ts.map +1 -0
- package/out/src/signer/WalletSigner.js +13 -0
- package/out/src/signer/WalletSigner.js.map +1 -0
- package/out/src/signer/methods/acquireDirectCertificate.d.ts +4 -0
- package/out/src/signer/methods/acquireDirectCertificate.d.ts.map +1 -0
- package/out/src/signer/methods/acquireDirectCertificate.js +47 -0
- package/out/src/signer/methods/acquireDirectCertificate.js.map +1 -0
- package/out/src/signer/methods/createAction.d.ts +7 -0
- package/out/src/signer/methods/createAction.d.ts.map +1 -0
- package/out/src/signer/methods/createAction.js +250 -0
- package/out/src/signer/methods/createAction.js.map +1 -0
- package/out/src/signer/methods/internalizeAction.d.ts +31 -0
- package/out/src/signer/methods/internalizeAction.d.ts.map +1 -0
- package/out/src/signer/methods/internalizeAction.js +95 -0
- package/out/src/signer/methods/internalizeAction.js.map +1 -0
- package/out/src/signer/methods/proveCertificate.d.ts +4 -0
- package/out/src/signer/methods/proveCertificate.d.ts.map +1 -0
- package/out/src/signer/methods/proveCertificate.js +45 -0
- package/out/src/signer/methods/proveCertificate.js.map +1 -0
- package/out/src/signer/methods/signAction.d.ts +6 -0
- package/out/src/signer/methods/signAction.d.ts.map +1 -0
- package/out/src/signer/methods/signAction.js +79 -0
- package/out/src/signer/methods/signAction.js.map +1 -0
- package/out/src/storage/StorageKnex.d.ts +176 -0
- package/out/src/storage/StorageKnex.d.ts.map +1 -0
- package/out/src/storage/StorageKnex.js +1035 -0
- package/out/src/storage/StorageKnex.js.map +1 -0
- package/out/src/storage/StorageProvider.d.ts +140 -0
- package/out/src/storage/StorageProvider.d.ts.map +1 -0
- package/out/src/storage/StorageProvider.js +539 -0
- package/out/src/storage/StorageProvider.js.map +1 -0
- package/out/src/storage/StorageReader.d.ts +76 -0
- package/out/src/storage/StorageReader.d.ts.map +1 -0
- package/out/src/storage/StorageReader.js +124 -0
- package/out/src/storage/StorageReader.js.map +1 -0
- package/out/src/storage/StorageReaderWriter.d.ts +87 -0
- package/out/src/storage/StorageReaderWriter.d.ts.map +1 -0
- package/out/src/storage/StorageReaderWriter.js +337 -0
- package/out/src/storage/StorageReaderWriter.js.map +1 -0
- package/out/src/storage/StorageSyncReader.d.ts +33 -0
- package/out/src/storage/StorageSyncReader.d.ts.map +1 -0
- package/out/src/storage/StorageSyncReader.js +142 -0
- package/out/src/storage/StorageSyncReader.js.map +1 -0
- package/out/src/storage/WalletStorageManager.d.ts +103 -0
- package/out/src/storage/WalletStorageManager.d.ts.map +1 -0
- package/out/src/storage/WalletStorageManager.js +408 -0
- package/out/src/storage/WalletStorageManager.js.map +1 -0
- package/out/src/storage/__test/WalletStorageManager.test.d.ts +2 -0
- package/out/src/storage/__test/WalletStorageManager.test.d.ts.map +1 -0
- package/out/src/storage/__test/WalletStorageManager.test.js +260 -0
- package/out/src/storage/__test/WalletStorageManager.test.js.map +1 -0
- package/out/src/storage/index.all.d.ts +11 -0
- package/out/src/storage/index.all.d.ts.map +1 -0
- package/out/src/storage/index.all.js +50 -0
- package/out/src/storage/index.all.js.map +1 -0
- package/out/src/storage/index.client.d.ts +7 -0
- package/out/src/storage/index.client.d.ts.map +1 -0
- package/out/src/storage/index.client.js +46 -0
- package/out/src/storage/index.client.js.map +1 -0
- package/out/src/storage/index.db.d.ts +1 -0
- package/out/src/storage/index.db.d.ts.map +1 -0
- package/out/src/storage/index.db.js +2 -0
- package/out/src/storage/index.db.js.map +1 -0
- package/out/src/storage/methods/__test/GenerateChange/generateChangeSdk.test.d.ts +2 -0
- package/out/src/storage/methods/__test/GenerateChange/generateChangeSdk.test.d.ts.map +1 -0
- package/out/src/storage/methods/__test/GenerateChange/generateChangeSdk.test.js +948 -0
- package/out/src/storage/methods/__test/GenerateChange/generateChangeSdk.test.js.map +1 -0
- package/out/src/storage/methods/__test/GenerateChange/randomValsUsed1.d.ts +2 -0
- package/out/src/storage/methods/__test/GenerateChange/randomValsUsed1.d.ts.map +1 -0
- package/out/src/storage/methods/__test/GenerateChange/randomValsUsed1.js +35 -0
- package/out/src/storage/methods/__test/GenerateChange/randomValsUsed1.js.map +1 -0
- package/out/src/storage/methods/attemptToPostReqsToNetwork.d.ts +27 -0
- package/out/src/storage/methods/attemptToPostReqsToNetwork.d.ts.map +1 -0
- package/out/src/storage/methods/attemptToPostReqsToNetwork.js +148 -0
- package/out/src/storage/methods/attemptToPostReqsToNetwork.js.map +1 -0
- package/out/src/storage/methods/createAction.d.ts +23 -0
- package/out/src/storage/methods/createAction.d.ts.map +1 -0
- package/out/src/storage/methods/createAction.js +663 -0
- package/out/src/storage/methods/createAction.js.map +1 -0
- package/out/src/storage/methods/generateChange.d.ts +108 -0
- package/out/src/storage/methods/generateChange.d.ts.map +1 -0
- package/out/src/storage/methods/generateChange.js +422 -0
- package/out/src/storage/methods/generateChange.js.map +1 -0
- package/out/src/storage/methods/getBeefForTransaction.d.ts +22 -0
- package/out/src/storage/methods/getBeefForTransaction.d.ts.map +1 -0
- package/out/src/storage/methods/getBeefForTransaction.js +94 -0
- package/out/src/storage/methods/getBeefForTransaction.js.map +1 -0
- package/out/src/storage/methods/getSyncChunk.d.ts +10 -0
- package/out/src/storage/methods/getSyncChunk.d.ts.map +1 -0
- package/out/src/storage/methods/getSyncChunk.js +271 -0
- package/out/src/storage/methods/getSyncChunk.js.map +1 -0
- package/out/src/storage/methods/internalizeAction.d.ts +38 -0
- package/out/src/storage/methods/internalizeAction.d.ts.map +1 -0
- package/out/src/storage/methods/internalizeAction.js +378 -0
- package/out/src/storage/methods/internalizeAction.js.map +1 -0
- package/out/src/storage/methods/listActions.d.ts +5 -0
- package/out/src/storage/methods/listActions.d.ts.map +1 -0
- package/out/src/storage/methods/listActions.js +174 -0
- package/out/src/storage/methods/listActions.js.map +1 -0
- package/out/src/storage/methods/listCertificates.d.ts +5 -0
- package/out/src/storage/methods/listCertificates.d.ts.map +1 -0
- package/out/src/storage/methods/listCertificates.js +68 -0
- package/out/src/storage/methods/listCertificates.js.map +1 -0
- package/out/src/storage/methods/listOutputs.d.ts +5 -0
- package/out/src/storage/methods/listOutputs.d.ts.map +1 -0
- package/out/src/storage/methods/listOutputs.js +189 -0
- package/out/src/storage/methods/listOutputs.js.map +1 -0
- package/out/src/storage/methods/processAction.d.ts +35 -0
- package/out/src/storage/methods/processAction.d.ts.map +1 -0
- package/out/src/storage/methods/processAction.js +271 -0
- package/out/src/storage/methods/processAction.js.map +1 -0
- package/out/src/storage/methods/purgeData.d.ts +4 -0
- package/out/src/storage/methods/purgeData.d.ts.map +1 -0
- package/out/src/storage/methods/purgeData.js +229 -0
- package/out/src/storage/methods/purgeData.js.map +1 -0
- package/out/src/storage/methods/reviewStatus.d.ts +9 -0
- package/out/src/storage/methods/reviewStatus.d.ts.map +1 -0
- package/out/src/storage/methods/reviewStatus.js +75 -0
- package/out/src/storage/methods/reviewStatus.js.map +1 -0
- package/out/src/storage/remoting/StorageClient.d.ts +56 -0
- package/out/src/storage/remoting/StorageClient.d.ts.map +1 -0
- package/out/src/storage/remoting/StorageClient.js +181 -0
- package/out/src/storage/remoting/StorageClient.js.map +1 -0
- package/out/src/storage/remoting/StorageServer.d.ts +26 -0
- package/out/src/storage/remoting/StorageServer.d.ts.map +1 -0
- package/out/src/storage/remoting/StorageServer.js +144 -0
- package/out/src/storage/remoting/StorageServer.js.map +1 -0
- package/out/src/storage/schema/KnexMigrations.d.ts +39 -0
- package/out/src/storage/schema/KnexMigrations.d.ts.map +1 -0
- package/out/src/storage/schema/KnexMigrations.js +442 -0
- package/out/src/storage/schema/KnexMigrations.js.map +1 -0
- package/out/src/storage/schema/entities/Certificate.d.ts +43 -0
- package/out/src/storage/schema/entities/Certificate.d.ts.map +1 -0
- package/out/src/storage/schema/entities/Certificate.js +162 -0
- package/out/src/storage/schema/entities/Certificate.js.map +1 -0
- package/out/src/storage/schema/entities/CertificateField.d.ts +32 -0
- package/out/src/storage/schema/entities/CertificateField.d.ts.map +1 -0
- package/out/src/storage/schema/entities/CertificateField.js +114 -0
- package/out/src/storage/schema/entities/CertificateField.js.map +1 -0
- package/out/src/storage/schema/entities/Commission.d.ts +37 -0
- package/out/src/storage/schema/entities/Commission.d.ts.map +1 -0
- package/out/src/storage/schema/entities/Commission.js +130 -0
- package/out/src/storage/schema/entities/Commission.js.map +1 -0
- package/out/src/storage/schema/entities/EntityBase.d.ts +105 -0
- package/out/src/storage/schema/entities/EntityBase.d.ts.map +1 -0
- package/out/src/storage/schema/entities/EntityBase.js +100 -0
- package/out/src/storage/schema/entities/EntityBase.js.map +1 -0
- package/out/src/storage/schema/entities/MergeEntity.d.ts +34 -0
- package/out/src/storage/schema/entities/MergeEntity.d.ts.map +1 -0
- package/out/src/storage/schema/entities/MergeEntity.js +57 -0
- package/out/src/storage/schema/entities/MergeEntity.js.map +1 -0
- package/out/src/storage/schema/entities/Output.d.ts +67 -0
- package/out/src/storage/schema/entities/Output.d.ts.map +1 -0
- package/out/src/storage/schema/entities/Output.js +281 -0
- package/out/src/storage/schema/entities/Output.js.map +1 -0
- package/out/src/storage/schema/entities/OutputBasket.d.ts +35 -0
- package/out/src/storage/schema/entities/OutputBasket.d.ts.map +1 -0
- package/out/src/storage/schema/entities/OutputBasket.js +133 -0
- package/out/src/storage/schema/entities/OutputBasket.js.map +1 -0
- package/out/src/storage/schema/entities/OutputTag.d.ts +31 -0
- package/out/src/storage/schema/entities/OutputTag.d.ts.map +1 -0
- package/out/src/storage/schema/entities/OutputTag.js +104 -0
- package/out/src/storage/schema/entities/OutputTag.js.map +1 -0
- package/out/src/storage/schema/entities/OutputTagMap.d.ts +28 -0
- package/out/src/storage/schema/entities/OutputTagMap.d.ts.map +1 -0
- package/out/src/storage/schema/entities/OutputTagMap.js +101 -0
- package/out/src/storage/schema/entities/OutputTagMap.js.map +1 -0
- package/out/src/storage/schema/entities/ProvenTx.d.ts +84 -0
- package/out/src/storage/schema/entities/ProvenTx.d.ts.map +1 -0
- package/out/src/storage/schema/entities/ProvenTx.js +283 -0
- package/out/src/storage/schema/entities/ProvenTx.js.map +1 -0
- package/out/src/storage/schema/entities/ProvenTxReq.d.ts +130 -0
- package/out/src/storage/schema/entities/ProvenTxReq.d.ts.map +1 -0
- package/out/src/storage/schema/entities/ProvenTxReq.js +521 -0
- package/out/src/storage/schema/entities/ProvenTxReq.js.map +1 -0
- package/out/src/storage/schema/entities/SyncState.d.ts +66 -0
- package/out/src/storage/schema/entities/SyncState.d.ts.map +1 -0
- package/out/src/storage/schema/entities/SyncState.js +284 -0
- package/out/src/storage/schema/entities/SyncState.js.map +1 -0
- package/out/src/storage/schema/entities/Transaction.d.ts +67 -0
- package/out/src/storage/schema/entities/Transaction.d.ts.map +1 -0
- package/out/src/storage/schema/entities/Transaction.js +264 -0
- package/out/src/storage/schema/entities/Transaction.js.map +1 -0
- package/out/src/storage/schema/entities/TxLabel.d.ts +31 -0
- package/out/src/storage/schema/entities/TxLabel.d.ts.map +1 -0
- package/out/src/storage/schema/entities/TxLabel.js +104 -0
- package/out/src/storage/schema/entities/TxLabel.js.map +1 -0
- package/out/src/storage/schema/entities/TxLabelMap.d.ts +28 -0
- package/out/src/storage/schema/entities/TxLabelMap.d.ts.map +1 -0
- package/out/src/storage/schema/entities/TxLabelMap.js +103 -0
- package/out/src/storage/schema/entities/TxLabelMap.js.map +1 -0
- package/out/src/storage/schema/entities/User.d.ts +29 -0
- package/out/src/storage/schema/entities/User.d.ts.map +1 -0
- package/out/src/storage/schema/entities/User.js +100 -0
- package/out/src/storage/schema/entities/User.js.map +1 -0
- package/out/src/storage/schema/entities/__tests/CertificateFieldTests.test.d.ts +2 -0
- package/out/src/storage/schema/entities/__tests/CertificateFieldTests.test.d.ts.map +1 -0
- package/out/src/storage/schema/entities/__tests/CertificateFieldTests.test.js +588 -0
- package/out/src/storage/schema/entities/__tests/CertificateFieldTests.test.js.map +1 -0
- package/out/src/storage/schema/entities/__tests/CertificateTests.test.d.ts +2 -0
- package/out/src/storage/schema/entities/__tests/CertificateTests.test.d.ts.map +1 -0
- package/out/src/storage/schema/entities/__tests/CertificateTests.test.js +449 -0
- package/out/src/storage/schema/entities/__tests/CertificateTests.test.js.map +1 -0
- package/out/src/storage/schema/entities/__tests/CommissionTests.test.d.ts +2 -0
- package/out/src/storage/schema/entities/__tests/CommissionTests.test.d.ts.map +1 -0
- package/out/src/storage/schema/entities/__tests/CommissionTests.test.js +602 -0
- package/out/src/storage/schema/entities/__tests/CommissionTests.test.js.map +1 -0
- package/out/src/storage/schema/entities/__tests/OutputBasketTests.test.d.ts +2 -0
- package/out/src/storage/schema/entities/__tests/OutputBasketTests.test.d.ts.map +1 -0
- package/out/src/storage/schema/entities/__tests/OutputBasketTests.test.js +515 -0
- package/out/src/storage/schema/entities/__tests/OutputBasketTests.test.js.map +1 -0
- package/out/src/storage/schema/entities/__tests/OutputTagMapTests.test.d.ts +2 -0
- package/out/src/storage/schema/entities/__tests/OutputTagMapTests.test.d.ts.map +1 -0
- package/out/src/storage/schema/entities/__tests/OutputTagMapTests.test.js +478 -0
- package/out/src/storage/schema/entities/__tests/OutputTagMapTests.test.js.map +1 -0
- package/out/src/storage/schema/entities/__tests/OutputTagTests.test.d.ts +2 -0
- package/out/src/storage/schema/entities/__tests/OutputTagTests.test.d.ts.map +1 -0
- package/out/src/storage/schema/entities/__tests/OutputTagTests.test.js +440 -0
- package/out/src/storage/schema/entities/__tests/OutputTagTests.test.js.map +1 -0
- package/out/src/storage/schema/entities/__tests/OutputTests.test.d.ts +2 -0
- package/out/src/storage/schema/entities/__tests/OutputTests.test.d.ts.map +1 -0
- package/out/src/storage/schema/entities/__tests/OutputTests.test.js +626 -0
- package/out/src/storage/schema/entities/__tests/OutputTests.test.js.map +1 -0
- package/out/src/storage/schema/entities/__tests/ProvenTxReqTests.test.d.ts +2 -0
- package/out/src/storage/schema/entities/__tests/ProvenTxReqTests.test.d.ts.map +1 -0
- package/out/src/storage/schema/entities/__tests/ProvenTxReqTests.test.js +585 -0
- package/out/src/storage/schema/entities/__tests/ProvenTxReqTests.test.js.map +1 -0
- package/out/src/storage/schema/entities/__tests/ProvenTxTests.test.d.ts +2 -0
- package/out/src/storage/schema/entities/__tests/ProvenTxTests.test.d.ts.map +1 -0
- package/out/src/storage/schema/entities/__tests/ProvenTxTests.test.js +628 -0
- package/out/src/storage/schema/entities/__tests/ProvenTxTests.test.js.map +1 -0
- package/out/src/storage/schema/entities/__tests/SyncStateTests.test.d.ts +2 -0
- package/out/src/storage/schema/entities/__tests/SyncStateTests.test.d.ts.map +1 -0
- package/out/src/storage/schema/entities/__tests/SyncStateTests.test.js +307 -0
- package/out/src/storage/schema/entities/__tests/SyncStateTests.test.js.map +1 -0
- package/out/src/storage/schema/entities/__tests/TransactionTests.test.d.ts +2 -0
- package/out/src/storage/schema/entities/__tests/TransactionTests.test.d.ts.map +1 -0
- package/out/src/storage/schema/entities/__tests/TransactionTests.test.js +823 -0
- package/out/src/storage/schema/entities/__tests/TransactionTests.test.js.map +1 -0
- package/out/src/storage/schema/entities/__tests/TxLabelMapTests.test.d.ts +2 -0
- package/out/src/storage/schema/entities/__tests/TxLabelMapTests.test.d.ts.map +1 -0
- package/out/src/storage/schema/entities/__tests/TxLabelMapTests.test.js +442 -0
- package/out/src/storage/schema/entities/__tests/TxLabelMapTests.test.js.map +1 -0
- package/out/src/storage/schema/entities/__tests/TxLabelTests.test.d.ts +2 -0
- package/out/src/storage/schema/entities/__tests/TxLabelTests.test.d.ts.map +1 -0
- package/out/src/storage/schema/entities/__tests/TxLabelTests.test.js +313 -0
- package/out/src/storage/schema/entities/__tests/TxLabelTests.test.js.map +1 -0
- package/out/src/storage/schema/entities/__tests/stampLogTests.test.d.ts +2 -0
- package/out/src/storage/schema/entities/__tests/stampLogTests.test.d.ts.map +1 -0
- package/out/src/storage/schema/entities/__tests/stampLogTests.test.js +81 -0
- package/out/src/storage/schema/entities/__tests/stampLogTests.test.js.map +1 -0
- package/out/src/storage/schema/entities/__tests/usersTests.test.d.ts +2 -0
- package/out/src/storage/schema/entities/__tests/usersTests.test.d.ts.map +1 -0
- package/out/src/storage/schema/entities/__tests/usersTests.test.js +418 -0
- package/out/src/storage/schema/entities/__tests/usersTests.test.js.map +1 -0
- package/out/src/storage/schema/entities/index.d.ts +17 -0
- package/out/src/storage/schema/entities/index.d.ts.map +1 -0
- package/out/src/storage/schema/entities/index.js +33 -0
- package/out/src/storage/schema/entities/index.js.map +1 -0
- package/out/src/storage/schema/tables/Certificate.d.ts +20 -0
- package/out/src/storage/schema/tables/Certificate.d.ts.map +1 -0
- package/out/src/storage/schema/tables/Certificate.js +3 -0
- package/out/src/storage/schema/tables/Certificate.js.map +1 -0
- package/out/src/storage/schema/tables/CertificateField.d.ts +12 -0
- package/out/src/storage/schema/tables/CertificateField.d.ts.map +1 -0
- package/out/src/storage/schema/tables/CertificateField.js +3 -0
- package/out/src/storage/schema/tables/CertificateField.js.map +1 -0
- package/out/src/storage/schema/tables/Commission.d.ts +13 -0
- package/out/src/storage/schema/tables/Commission.d.ts.map +1 -0
- package/out/src/storage/schema/tables/Commission.js +3 -0
- package/out/src/storage/schema/tables/Commission.js.map +1 -0
- package/out/src/storage/schema/tables/MonitorEvent.d.ts +9 -0
- package/out/src/storage/schema/tables/MonitorEvent.d.ts.map +1 -0
- package/out/src/storage/schema/tables/MonitorEvent.js +3 -0
- package/out/src/storage/schema/tables/MonitorEvent.js.map +1 -0
- package/out/src/storage/schema/tables/Output.d.ts +36 -0
- package/out/src/storage/schema/tables/Output.d.ts.map +1 -0
- package/out/src/storage/schema/tables/Output.js +31 -0
- package/out/src/storage/schema/tables/Output.js.map +1 -0
- package/out/src/storage/schema/tables/OutputBasket.d.ts +12 -0
- package/out/src/storage/schema/tables/OutputBasket.d.ts.map +1 -0
- package/out/src/storage/schema/tables/OutputBasket.js +3 -0
- package/out/src/storage/schema/tables/OutputBasket.js.map +1 -0
- package/out/src/storage/schema/tables/OutputTag.d.ts +10 -0
- package/out/src/storage/schema/tables/OutputTag.d.ts.map +1 -0
- package/out/src/storage/schema/tables/OutputTag.js +3 -0
- package/out/src/storage/schema/tables/OutputTag.js.map +1 -0
- package/out/src/storage/schema/tables/OutputTagMap.d.ts +9 -0
- package/out/src/storage/schema/tables/OutputTagMap.d.ts.map +1 -0
- package/out/src/storage/schema/tables/OutputTagMap.js +3 -0
- package/out/src/storage/schema/tables/OutputTagMap.js.map +1 -0
- package/out/src/storage/schema/tables/ProvenTx.d.ts +14 -0
- package/out/src/storage/schema/tables/ProvenTx.d.ts.map +1 -0
- package/out/src/storage/schema/tables/ProvenTx.js +3 -0
- package/out/src/storage/schema/tables/ProvenTx.js.map +1 -0
- package/out/src/storage/schema/tables/ProvenTxReq.d.ts +64 -0
- package/out/src/storage/schema/tables/ProvenTxReq.d.ts.map +1 -0
- package/out/src/storage/schema/tables/ProvenTxReq.js +3 -0
- package/out/src/storage/schema/tables/ProvenTxReq.js.map +1 -0
- package/out/src/storage/schema/tables/Settings.d.ts +17 -0
- package/out/src/storage/schema/tables/Settings.d.ts.map +1 -0
- package/out/src/storage/schema/tables/Settings.js +3 -0
- package/out/src/storage/schema/tables/Settings.js.map +1 -0
- package/out/src/storage/schema/tables/SyncState.d.ts +18 -0
- package/out/src/storage/schema/tables/SyncState.d.ts.map +1 -0
- package/out/src/storage/schema/tables/SyncState.js +3 -0
- package/out/src/storage/schema/tables/SyncState.js.map +1 -0
- package/out/src/storage/schema/tables/Transaction.d.ts +37 -0
- package/out/src/storage/schema/tables/Transaction.d.ts.map +1 -0
- package/out/src/storage/schema/tables/Transaction.js +21 -0
- package/out/src/storage/schema/tables/Transaction.js.map +1 -0
- package/out/src/storage/schema/tables/TxLabel.d.ts +10 -0
- package/out/src/storage/schema/tables/TxLabel.d.ts.map +1 -0
- package/out/src/storage/schema/tables/TxLabel.js +3 -0
- package/out/src/storage/schema/tables/TxLabel.js.map +1 -0
- package/out/src/storage/schema/tables/TxLabelMap.d.ts +9 -0
- package/out/src/storage/schema/tables/TxLabelMap.d.ts.map +1 -0
- package/out/src/storage/schema/tables/TxLabelMap.js +3 -0
- package/out/src/storage/schema/tables/TxLabelMap.js.map +1 -0
- package/out/src/storage/schema/tables/User.d.ts +16 -0
- package/out/src/storage/schema/tables/User.d.ts.map +1 -0
- package/out/src/storage/schema/tables/User.js +3 -0
- package/out/src/storage/schema/tables/User.js.map +1 -0
- package/out/src/storage/schema/tables/index.d.ts +17 -0
- package/out/src/storage/schema/tables/index.d.ts.map +1 -0
- package/out/src/storage/schema/tables/index.js +33 -0
- package/out/src/storage/schema/tables/index.js.map +1 -0
- package/out/src/storage/sync/StorageMySQLDojoReader.d.ts +71 -0
- package/out/src/storage/sync/StorageMySQLDojoReader.d.ts.map +1 -0
- package/out/src/storage/sync/StorageMySQLDojoReader.js +612 -0
- package/out/src/storage/sync/StorageMySQLDojoReader.js.map +1 -0
- package/out/src/storage/sync/index.d.ts +2 -0
- package/out/src/storage/sync/index.d.ts.map +1 -0
- package/out/src/storage/sync/index.js +18 -0
- package/out/src/storage/sync/index.js.map +1 -0
- package/out/src/utility/ScriptTemplateSABPPP.d.ts +25 -0
- package/out/src/utility/ScriptTemplateSABPPP.d.ts.map +1 -0
- package/out/src/utility/ScriptTemplateSABPPP.js +46 -0
- package/out/src/utility/ScriptTemplateSABPPP.js.map +1 -0
- package/out/src/utility/index.all.d.ts +7 -0
- package/out/src/utility/index.all.d.ts.map +1 -0
- package/out/src/utility/index.all.js +23 -0
- package/out/src/utility/index.all.js.map +1 -0
- package/out/src/utility/index.client.d.ts +7 -0
- package/out/src/utility/index.client.d.ts.map +1 -0
- package/out/src/utility/index.client.js +23 -0
- package/out/src/utility/index.client.js.map +1 -0
- package/out/src/utility/parseTxScriptOffsets.d.ts +14 -0
- package/out/src/utility/parseTxScriptOffsets.d.ts.map +1 -0
- package/out/src/utility/parseTxScriptOffsets.js +26 -0
- package/out/src/utility/parseTxScriptOffsets.js.map +1 -0
- package/out/src/utility/stampLog.d.ts +18 -0
- package/out/src/utility/stampLog.d.ts.map +1 -0
- package/out/src/utility/stampLog.js +72 -0
- package/out/src/utility/stampLog.js.map +1 -0
- package/out/src/utility/tscProofToMerklePath.d.ts +8 -0
- package/out/src/utility/tscProofToMerklePath.d.ts.map +1 -0
- package/out/src/utility/tscProofToMerklePath.js +41 -0
- package/out/src/utility/tscProofToMerklePath.js.map +1 -0
- package/out/src/utility/utilityHelpers.buffer.d.ts +18 -0
- package/out/src/utility/utilityHelpers.buffer.d.ts.map +1 -0
- package/out/src/utility/utilityHelpers.buffer.js +45 -0
- package/out/src/utility/utilityHelpers.buffer.js.map +1 -0
- package/out/src/utility/utilityHelpers.d.ts +129 -0
- package/out/src/utility/utilityHelpers.d.ts.map +1 -0
- package/out/src/utility/utilityHelpers.js +268 -0
- package/out/src/utility/utilityHelpers.js.map +1 -0
- package/out/src/utility/utilityHelpers.noBuffer.d.ts +9 -0
- package/out/src/utility/utilityHelpers.noBuffer.d.ts.map +1 -0
- package/out/src/utility/utilityHelpers.noBuffer.js +23 -0
- package/out/src/utility/utilityHelpers.noBuffer.js.map +1 -0
- package/out/test/Wallet/StorageClient/storageClient.man.test.d.ts +2 -0
- package/out/test/Wallet/StorageClient/storageClient.man.test.d.ts.map +1 -0
- package/out/test/Wallet/StorageClient/storageClient.man.test.js +45 -0
- package/out/test/Wallet/StorageClient/storageClient.man.test.js.map +1 -0
- package/out/test/Wallet/action/internalizeAction.a.test.d.ts +2 -0
- package/out/test/Wallet/action/internalizeAction.a.test.d.ts.map +1 -0
- package/out/test/Wallet/action/internalizeAction.a.test.js +243 -0
- package/out/test/Wallet/action/internalizeAction.a.test.js.map +1 -0
- package/out/test/Wallet/certificate/acquireCertificate.test.d.ts +2 -0
- package/out/test/Wallet/certificate/acquireCertificate.test.d.ts.map +1 -0
- package/out/test/Wallet/certificate/acquireCertificate.test.js +213 -0
- package/out/test/Wallet/certificate/acquireCertificate.test.js.map +1 -0
- package/out/test/Wallet/certificate/listCertificates.test.d.ts +2 -0
- package/out/test/Wallet/certificate/listCertificates.test.d.ts.map +1 -0
- package/out/test/Wallet/certificate/listCertificates.test.js +305 -0
- package/out/test/Wallet/certificate/listCertificates.test.js.map +1 -0
- package/out/test/Wallet/get/getHeaderForHeight.test.d.ts +2 -0
- package/out/test/Wallet/get/getHeaderForHeight.test.d.ts.map +1 -0
- package/out/test/Wallet/get/getHeaderForHeight.test.js +68 -0
- package/out/test/Wallet/get/getHeaderForHeight.test.js.map +1 -0
- package/out/test/Wallet/get/getHeight.test.d.ts +2 -0
- package/out/test/Wallet/get/getHeight.test.d.ts.map +1 -0
- package/out/test/Wallet/get/getHeight.test.js +45 -0
- package/out/test/Wallet/get/getHeight.test.js.map +1 -0
- package/out/test/Wallet/get/getKnownTxids.test.d.ts +2 -0
- package/out/test/Wallet/get/getKnownTxids.test.d.ts.map +1 -0
- package/out/test/Wallet/get/getKnownTxids.test.js +73 -0
- package/out/test/Wallet/get/getKnownTxids.test.js.map +1 -0
- package/out/test/Wallet/get/getNetwork.test.d.ts +2 -0
- package/out/test/Wallet/get/getNetwork.test.d.ts.map +1 -0
- package/out/test/Wallet/get/getNetwork.test.js +26 -0
- package/out/test/Wallet/get/getNetwork.test.js.map +1 -0
- package/out/test/Wallet/get/getVersion.test.d.ts +2 -0
- package/out/test/Wallet/get/getVersion.test.d.ts.map +1 -0
- package/out/test/Wallet/get/getVersion.test.js +25 -0
- package/out/test/Wallet/get/getVersion.test.js.map +1 -0
- package/out/test/Wallet/live/walletLive.man.test.d.ts +26 -0
- package/out/test/Wallet/live/walletLive.man.test.d.ts.map +1 -0
- package/out/test/Wallet/live/walletLive.man.test.js +389 -0
- package/out/test/Wallet/live/walletLive.man.test.js.map +1 -0
- package/out/test/Wallet/sync/Wallet.updateWalletLegacyTestData.man.test.d.ts +2 -0
- package/out/test/Wallet/sync/Wallet.updateWalletLegacyTestData.man.test.d.ts.map +1 -0
- package/out/test/Wallet/sync/Wallet.updateWalletLegacyTestData.man.test.js +153 -0
- package/out/test/Wallet/sync/Wallet.updateWalletLegacyTestData.man.test.js.map +1 -0
- package/out/test/checkDB.d.ts +4 -0
- package/out/test/checkDB.d.ts.map +1 -0
- package/out/test/checkDB.js +55 -0
- package/out/test/checkDB.js.map +1 -0
- package/out/test/examples/README.man.test.d.ts +2 -0
- package/out/test/examples/README.man.test.d.ts.map +1 -0
- package/out/test/examples/README.man.test.js +46 -0
- package/out/test/examples/README.man.test.js.map +1 -0
- package/out/test/monitor/Monitor.test.d.ts +2 -0
- package/out/test/monitor/Monitor.test.d.ts.map +1 -0
- package/out/test/monitor/Monitor.test.js +446 -0
- package/out/test/monitor/Monitor.test.js.map +1 -0
- package/out/test/services/Services.test.d.ts +2 -0
- package/out/test/services/Services.test.d.ts.map +1 -0
- package/out/test/services/Services.test.js +128 -0
- package/out/test/services/Services.test.js.map +1 -0
- package/out/test/storage/KnexMigrations.test.d.ts +2 -0
- package/out/test/storage/KnexMigrations.test.d.ts.map +1 -0
- package/out/test/storage/KnexMigrations.test.js +81 -0
- package/out/test/storage/KnexMigrations.test.js.map +1 -0
- package/out/test/storage/StorageMySQLDojoReader.man.test.d.ts +2 -0
- package/out/test/storage/StorageMySQLDojoReader.man.test.d.ts.map +1 -0
- package/out/test/storage/StorageMySQLDojoReader.man.test.js +88 -0
- package/out/test/storage/StorageMySQLDojoReader.man.test.js.map +1 -0
- package/out/test/storage/count.test.d.ts +2 -0
- package/out/test/storage/count.test.d.ts.map +1 -0
- package/out/test/storage/count.test.js +141 -0
- package/out/test/storage/count.test.js.map +1 -0
- package/out/test/storage/find.test.d.ts +2 -0
- package/out/test/storage/find.test.d.ts.map +1 -0
- package/out/test/storage/find.test.js +148 -0
- package/out/test/storage/find.test.js.map +1 -0
- package/out/test/storage/findLegacy.test.d.ts +2 -0
- package/out/test/storage/findLegacy.test.d.ts.map +1 -0
- package/out/test/storage/findLegacy.test.js +52 -0
- package/out/test/storage/findLegacy.test.js.map +1 -0
- package/out/test/storage/insert.test.d.ts +2 -0
- package/out/test/storage/insert.test.d.ts.map +1 -0
- package/out/test/storage/insert.test.js +256 -0
- package/out/test/storage/insert.test.js.map +1 -0
- package/out/test/storage/update.test.d.ts +2 -0
- package/out/test/storage/update.test.d.ts.map +1 -0
- package/out/test/storage/update.test.js +926 -0
- package/out/test/storage/update.test.js.map +1 -0
- package/out/test/storage/update2.test.d.ts +2 -0
- package/out/test/storage/update2.test.d.ts.map +1 -0
- package/out/test/storage/update2.test.js +766 -0
- package/out/test/storage/update2.test.js.map +1 -0
- package/out/test/utils/TestUtilsWalletStorage.d.ts +399 -0
- package/out/test/utils/TestUtilsWalletStorage.d.ts.map +1 -0
- package/out/test/utils/TestUtilsWalletStorage.js +1337 -0
- package/out/test/utils/TestUtilsWalletStorage.js.map +1 -0
- package/out/test/wallet/action/abortAction.test.d.ts +2 -0
- package/out/test/wallet/action/abortAction.test.d.ts.map +1 -0
- package/out/test/wallet/action/abortAction.test.js +44 -0
- package/out/test/wallet/action/abortAction.test.js.map +1 -0
- package/out/test/wallet/action/createAction.test.d.ts +2 -0
- package/out/test/wallet/action/createAction.test.d.ts.map +1 -0
- package/out/test/wallet/action/createAction.test.js +230 -0
- package/out/test/wallet/action/createAction.test.js.map +1 -0
- package/out/test/wallet/action/createActionToGenerateBeefs.man.test.d.ts +2 -0
- package/out/test/wallet/action/createActionToGenerateBeefs.man.test.d.ts.map +1 -0
- package/out/test/wallet/action/createActionToGenerateBeefs.man.test.js +273 -0
- package/out/test/wallet/action/createActionToGenerateBeefs.man.test.js.map +1 -0
- package/out/test/wallet/action/internalizeAction.test.d.ts +2 -0
- package/out/test/wallet/action/internalizeAction.test.d.ts.map +1 -0
- package/out/test/wallet/action/internalizeAction.test.js +603 -0
- package/out/test/wallet/action/internalizeAction.test.js.map +1 -0
- package/out/test/wallet/action/relinquishOutput.test.d.ts +2 -0
- package/out/test/wallet/action/relinquishOutput.test.d.ts.map +1 -0
- package/out/test/wallet/action/relinquishOutput.test.js +31 -0
- package/out/test/wallet/action/relinquishOutput.test.js.map +1 -0
- package/out/test/wallet/construct/Wallet.constructor.test.d.ts +2 -0
- package/out/test/wallet/construct/Wallet.constructor.test.d.ts.map +1 -0
- package/out/test/wallet/construct/Wallet.constructor.test.js +49 -0
- package/out/test/wallet/construct/Wallet.constructor.test.js.map +1 -0
- package/out/test/wallet/list/listActions.test.d.ts +2 -0
- package/out/test/wallet/list/listActions.test.d.ts.map +1 -0
- package/out/test/wallet/list/listActions.test.js +265 -0
- package/out/test/wallet/list/listActions.test.js.map +1 -0
- package/out/test/wallet/list/listActions2.test.d.ts +2 -0
- package/out/test/wallet/list/listActions2.test.d.ts.map +1 -0
- package/out/test/wallet/list/listActions2.test.js +423 -0
- package/out/test/wallet/list/listActions2.test.js.map +1 -0
- package/out/test/wallet/list/listCertificates.test.d.ts +2 -0
- package/out/test/wallet/list/listCertificates.test.d.ts.map +1 -0
- package/out/test/wallet/list/listCertificates.test.js +115 -0
- package/out/test/wallet/list/listCertificates.test.js.map +1 -0
- package/out/test/wallet/list/listOutputs.test.d.ts +2 -0
- package/out/test/wallet/list/listOutputs.test.d.ts.map +1 -0
- package/out/test/wallet/list/listOutputs.test.js +521 -0
- package/out/test/wallet/list/listOutputs.test.js.map +1 -0
- package/out/test/wallet/sync/Wallet.sync.test.d.ts +2 -0
- package/out/test/wallet/sync/Wallet.sync.test.d.ts.map +1 -0
- package/out/test/wallet/sync/Wallet.sync.test.js +142 -0
- package/out/test/wallet/sync/Wallet.sync.test.js.map +1 -0
- package/out/tsconfig.all.tsbuildinfo +1 -0
- package/package.json +63 -0
- package/src/Wallet.ts +771 -0
- package/src/index.all.ts +8 -0
- package/src/index.client.ts +7 -0
- package/src/index.ts +2 -0
- package/src/monitor/Monitor.ts +317 -0
- package/src/monitor/MonitorDaemon.ts +197 -0
- package/src/monitor/README.md +3 -0
- package/src/monitor/__test/MonitorDaemon.man.test.ts +17 -0
- package/src/monitor/tasks/TaskCheckForProofs.ts +235 -0
- package/src/monitor/tasks/TaskClock.ts +35 -0
- package/src/monitor/tasks/TaskFailAbandoned.ts +56 -0
- package/src/monitor/tasks/TaskNewHeader.ts +48 -0
- package/src/monitor/tasks/TaskPurge.ts +69 -0
- package/src/monitor/tasks/TaskReviewStatus.ts +51 -0
- package/src/monitor/tasks/TaskSendWaiting.ts +107 -0
- package/src/monitor/tasks/TaskSyncWhenIdle.ts +26 -0
- package/src/monitor/tasks/WalletMonitorTask.ts +47 -0
- package/src/sdk/CertOps.ts +346 -0
- package/src/sdk/PrivilegedKeyManager.ts +402 -0
- package/src/sdk/README.md +13 -0
- package/src/sdk/StorageSyncReader.ts +155 -0
- package/src/sdk/StorageSyncReaderWriter.ts +263 -0
- package/src/sdk/WERR_errors.ts +152 -0
- package/src/sdk/WalletError.ts +136 -0
- package/src/sdk/WalletServices.interfaces.ts +399 -0
- package/src/sdk/WalletSigner.interfaces.ts +38 -0
- package/src/sdk/WalletStorage.interfaces.ts +416 -0
- package/src/sdk/__test/CertificateLifeCycle.test.ts +194 -0
- package/src/sdk/__test/PrivilegedKeyManager.test.ts +775 -0
- package/src/sdk/index.ts +11 -0
- package/src/sdk/types.ts +115 -0
- package/src/sdk/validationHelpers.ts +1248 -0
- package/src/services/README.md +11 -0
- package/src/services/ServiceCollection.ts +50 -0
- package/src/services/Services.ts +461 -0
- package/src/services/__tests/getMerklePath.test.ts +16 -0
- package/src/services/__tests/getRawTx.test.ts +15 -0
- package/src/services/__tests/postBeef.test.ts +19 -0
- package/src/services/__tests/postBeefToArcTaal.test.ts +487 -0
- package/src/services/__tests/postTxs.test.ts +20 -0
- package/src/services/chaintracker/ChaintracksChainTracker.ts +78 -0
- package/src/services/chaintracker/__tests/ChaintracksChainTracker.test.ts +25 -0
- package/src/services/chaintracker/__tests/ChaintracksServiceClient.test.ts +32 -0
- package/src/services/chaintracker/chaintracks/BlockHeaderApi.ts +123 -0
- package/src/services/chaintracker/chaintracks/ChaintracksServiceClient.ts +160 -0
- package/src/services/chaintracker/chaintracks/index.ts +2 -0
- package/src/services/chaintracker/index.ts +2 -0
- package/src/services/createDefaultWalletServicesOptions.ts +38 -0
- package/src/services/index.ts +1 -0
- package/src/services/providers/arcServices.ts +570 -0
- package/src/services/providers/echangeRates.ts +276 -0
- package/src/services/providers/whatsonchain.ts +170 -0
- package/src/signer/README.md +5 -0
- package/src/signer/WalletSigner.ts +21 -0
- package/src/signer/methods/acquireDirectCertificate.ts +53 -0
- package/src/signer/methods/createAction.ts +364 -0
- package/src/signer/methods/internalizeAction.ts +142 -0
- package/src/signer/methods/proveCertificate.ts +51 -0
- package/src/signer/methods/signAction.ts +121 -0
- package/src/storage/README.md +14 -0
- package/src/storage/StorageKnex.ts +1449 -0
- package/src/storage/StorageProvider.ts +853 -0
- package/src/storage/StorageReader.ts +222 -0
- package/src/storage/StorageReaderWriter.ts +623 -0
- package/src/storage/StorageSyncReader.ts +143 -0
- package/src/storage/WalletStorageManager.ts +532 -0
- package/src/storage/__test/WalletStorageManager.test.ts +292 -0
- package/src/storage/index.all.ts +10 -0
- package/src/storage/index.client.ts +6 -0
- package/src/storage/index.db.ts +0 -0
- package/src/storage/methods/__test/GenerateChange/generateChangeSdk.test.ts +1143 -0
- package/src/storage/methods/__test/GenerateChange/randomValsUsed1.ts +31 -0
- package/src/storage/methods/attemptToPostReqsToNetwork.ts +185 -0
- package/src/storage/methods/createAction.ts +997 -0
- package/src/storage/methods/generateChange.ts +629 -0
- package/src/storage/methods/getBeefForTransaction.ts +143 -0
- package/src/storage/methods/getSyncChunk.ts +330 -0
- package/src/storage/methods/internalizeAction.ts +538 -0
- package/src/storage/methods/listActions.ts +203 -0
- package/src/storage/methods/listCertificates.ts +81 -0
- package/src/storage/methods/listOutputs.ts +219 -0
- package/src/storage/methods/processAction.ts +477 -0
- package/src/storage/methods/purgeData.ts +276 -0
- package/src/storage/methods/reviewStatus.ts +95 -0
- package/src/storage/remoting/StorageClient.ts +306 -0
- package/src/storage/remoting/StorageServer.ts +179 -0
- package/src/storage/schema/KnexMigrations.ts +488 -0
- package/src/storage/schema/entities/Certificate.ts +199 -0
- package/src/storage/schema/entities/CertificateField.ts +157 -0
- package/src/storage/schema/entities/Commission.ts +169 -0
- package/src/storage/schema/entities/EntityBase.ts +214 -0
- package/src/storage/schema/entities/MergeEntity.ts +79 -0
- package/src/storage/schema/entities/Output.ts +323 -0
- package/src/storage/schema/entities/OutputBasket.ts +165 -0
- package/src/storage/schema/entities/OutputTag.ts +138 -0
- package/src/storage/schema/entities/OutputTagMap.ts +146 -0
- package/src/storage/schema/entities/ProvenTx.ts +349 -0
- package/src/storage/schema/entities/ProvenTxReq.ts +646 -0
- package/src/storage/schema/entities/SyncState.ts +429 -0
- package/src/storage/schema/entities/Transaction.ts +334 -0
- package/src/storage/schema/entities/TxLabel.ts +135 -0
- package/src/storage/schema/entities/TxLabelMap.ts +148 -0
- package/src/storage/schema/entities/User.ts +138 -0
- package/src/storage/schema/entities/__tests/CertificateFieldTests.test.ts +663 -0
- package/src/storage/schema/entities/__tests/CertificateTests.test.ts +527 -0
- package/src/storage/schema/entities/__tests/CommissionTests.test.ts +658 -0
- package/src/storage/schema/entities/__tests/OutputBasketTests.test.ts +567 -0
- package/src/storage/schema/entities/__tests/OutputTagMapTests.test.ts +530 -0
- package/src/storage/schema/entities/__tests/OutputTagTests.test.ts +504 -0
- package/src/storage/schema/entities/__tests/OutputTests.test.ts +689 -0
- package/src/storage/schema/entities/__tests/ProvenTxReqTests.test.ts +669 -0
- package/src/storage/schema/entities/__tests/ProvenTxTests.test.ts +700 -0
- package/src/storage/schema/entities/__tests/SyncStateTests.test.ts +376 -0
- package/src/storage/schema/entities/__tests/TransactionTests.test.ts +920 -0
- package/src/storage/schema/entities/__tests/TxLabelMapTests.test.ts +512 -0
- package/src/storage/schema/entities/__tests/TxLabelTests.test.ts +350 -0
- package/src/storage/schema/entities/__tests/stampLogTests.test.ts +97 -0
- package/src/storage/schema/entities/__tests/usersTests.test.ts +485 -0
- package/src/storage/schema/entities/index.ts +16 -0
- package/src/storage/schema/tables/Certificate.ts +21 -0
- package/src/storage/schema/tables/CertificateField.ts +12 -0
- package/src/storage/schema/tables/Commission.ts +13 -0
- package/src/storage/schema/tables/MonitorEvent.ts +9 -0
- package/src/storage/schema/tables/Output.ts +64 -0
- package/src/storage/schema/tables/OutputBasket.ts +12 -0
- package/src/storage/schema/tables/OutputTag.ts +10 -0
- package/src/storage/schema/tables/OutputTagMap.ts +9 -0
- package/src/storage/schema/tables/ProvenTx.ts +14 -0
- package/src/storage/schema/tables/ProvenTxReq.ts +65 -0
- package/src/storage/schema/tables/Settings.ts +17 -0
- package/src/storage/schema/tables/SyncState.ts +18 -0
- package/src/storage/schema/tables/Transaction.ts +54 -0
- package/src/storage/schema/tables/TxLabel.ts +10 -0
- package/src/storage/schema/tables/TxLabelMap.ts +9 -0
- package/src/storage/schema/tables/User.ts +16 -0
- package/src/storage/schema/tables/index.ts +16 -0
- package/src/storage/sync/StorageMySQLDojoReader.ts +771 -0
- package/src/storage/sync/index.ts +1 -0
- package/src/utility/README.md +3 -0
- package/src/utility/ScriptTemplateSABPPP.ts +79 -0
- package/src/utility/index.all.ts +7 -0
- package/src/utility/index.client.ts +7 -0
- package/src/utility/parseTxScriptOffsets.ts +29 -0
- package/src/utility/stampLog.ts +73 -0
- package/src/utility/tscProofToMerklePath.ts +51 -0
- package/src/utility/utilityHelpers.buffer.ts +43 -0
- package/src/utility/utilityHelpers.noBuffer.ts +18 -0
- package/src/utility/utilityHelpers.ts +283 -0
- package/test/Wallet/StorageClient/storageClient.man.test.ts +55 -0
- package/test/Wallet/action/internalizeAction.a.test.ts +301 -0
- package/test/Wallet/certificate/acquireCertificate.test.ts +253 -0
- package/test/Wallet/certificate/listCertificates.test.ts +352 -0
- package/test/Wallet/get/getHeaderForHeight.test.ts +79 -0
- package/test/Wallet/get/getHeight.test.ts +52 -0
- package/test/Wallet/get/getKnownTxids.test.ts +90 -0
- package/test/Wallet/get/getNetwork.test.ts +28 -0
- package/test/Wallet/get/getVersion.test.ts +28 -0
- package/test/Wallet/live/walletLive.man.test.ts +510 -0
- package/test/Wallet/sync/Wallet.updateWalletLegacyTestData.man.test.ts +155 -0
- package/test/checkDB.ts +63 -0
- package/test/checkdb +0 -0
- package/test/examples/README.man.test.ts +53 -0
- package/test/monitor/Monitor.test.ts +536 -0
- package/test/services/Services.test.ts +149 -0
- package/test/storage/KnexMigrations.test.ts +100 -0
- package/test/storage/StorageMySQLDojoReader.man.test.ts +71 -0
- package/test/storage/count.test.ts +193 -0
- package/test/storage/find.test.ts +216 -0
- package/test/storage/findLegacy.test.ts +70 -0
- package/test/storage/insert.test.ts +294 -0
- package/test/storage/update.test.ts +1146 -0
- package/test/storage/update2.test.ts +1017 -0
- package/test/utils/TestUtilsWalletStorage.ts +1923 -0
- package/test/utils/removeFailedFromDatabase.sql +17 -0
- package/test/wallet/action/abortAction.test.ts +55 -0
- package/test/wallet/action/createAction.test.ts +266 -0
- package/test/wallet/action/createActionToGenerateBeefs.man.test.ts +297 -0
- package/test/wallet/action/internalizeAction.test.ts +729 -0
- package/test/wallet/action/relinquishOutput.test.ts +43 -0
- package/test/wallet/construct/Wallet.constructor.test.ts +57 -0
- package/test/wallet/list/listActions.test.ts +282 -0
- package/test/wallet/list/listActions2.test.ts +570 -0
- package/test/wallet/list/listCertificates.test.ts +129 -0
- package/test/wallet/list/listOutputs.test.ts +573 -0
- package/test/wallet/sync/Wallet.sync.test.ts +226 -0
- package/ts2md.json +32 -0
- package/tsconfig.all.json +29 -0
- package/tsconfig.client.json +22 -0
- package/tsconfig.json +14 -0
- package/unlock-migrations.sh +41 -0
|
@@ -0,0 +1,997 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Beef,
|
|
3
|
+
BigNumber,
|
|
4
|
+
Curve,
|
|
5
|
+
OriginatorDomainNameStringUnder250Bytes,
|
|
6
|
+
P2PKH,
|
|
7
|
+
PrivateKey,
|
|
8
|
+
PubKeyHex,
|
|
9
|
+
PublicKey,
|
|
10
|
+
Script
|
|
11
|
+
} from '@bsv/sdk'
|
|
12
|
+
import {
|
|
13
|
+
asArray,
|
|
14
|
+
asString,
|
|
15
|
+
entity,
|
|
16
|
+
randomBytesBase64,
|
|
17
|
+
sdk,
|
|
18
|
+
sha256Hash,
|
|
19
|
+
stampLog,
|
|
20
|
+
stampLogFormat,
|
|
21
|
+
StorageProvider,
|
|
22
|
+
table,
|
|
23
|
+
validateStorageFeeModel,
|
|
24
|
+
verifyId,
|
|
25
|
+
verifyNumber,
|
|
26
|
+
verifyOne,
|
|
27
|
+
verifyOneOrNone,
|
|
28
|
+
verifyTruthy
|
|
29
|
+
} from '../../index.client'
|
|
30
|
+
import {
|
|
31
|
+
generateChangeSdk,
|
|
32
|
+
GenerateChangeSdkChangeInput,
|
|
33
|
+
GenerateChangeSdkParams
|
|
34
|
+
} from './generateChange'
|
|
35
|
+
|
|
36
|
+
export async function createAction(
|
|
37
|
+
storage: StorageProvider,
|
|
38
|
+
auth: sdk.AuthId,
|
|
39
|
+
vargs: sdk.ValidCreateActionArgs,
|
|
40
|
+
originator?: OriginatorDomainNameStringUnder250Bytes
|
|
41
|
+
): Promise<sdk.StorageCreateActionResult> {
|
|
42
|
+
//stampLog(vargs, `start storage createTransactionSdk`)
|
|
43
|
+
|
|
44
|
+
if (!vargs.isNewTx)
|
|
45
|
+
// The purpose of this function is to create the initial storage records associated
|
|
46
|
+
// with a new transaction. It's an error if we have no new inputs or outputs...
|
|
47
|
+
throw new sdk.WERR_INTERNAL()
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Steps to create a transaction:
|
|
51
|
+
* - Verify that all inputs either have proof in vargs.inputBEEF or that options.trustSelf === 'known' and input txid.vout are known valid to storage.
|
|
52
|
+
* - Create a new transaction record with status 'unsigned' as the anchor for construction work and to new outputs.
|
|
53
|
+
* - Create all transaction labels.
|
|
54
|
+
* - Add new commission output
|
|
55
|
+
* - Attempt to fund the transaction by allocating change outputs:
|
|
56
|
+
* - As each change output is selected it is simultaneously locked.
|
|
57
|
+
* - Create all new output, basket, tag records
|
|
58
|
+
* - If requested, create result Beef with complete proofs for all inputs used
|
|
59
|
+
* - Create result inputs with source locking scripts
|
|
60
|
+
* - Create result outputs with new locking scripts.
|
|
61
|
+
* - Create and return result.
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
const userId = auth.userId!
|
|
65
|
+
const { storageBeef, beef, xinputs } = await validateRequiredInputs(
|
|
66
|
+
storage,
|
|
67
|
+
userId,
|
|
68
|
+
vargs
|
|
69
|
+
)
|
|
70
|
+
const xoutputs = validateRequiredOutputs(storage, userId, vargs)
|
|
71
|
+
|
|
72
|
+
const changeBasketName = 'default'
|
|
73
|
+
const changeBasket = verifyOne(
|
|
74
|
+
await storage.findOutputBaskets({
|
|
75
|
+
partial: { userId, name: changeBasketName }
|
|
76
|
+
}),
|
|
77
|
+
`Invalid outputGeneration basket "${changeBasketName}"`
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
const noSendChangeIn = await validateNoSendChange(
|
|
81
|
+
storage,
|
|
82
|
+
userId,
|
|
83
|
+
vargs,
|
|
84
|
+
changeBasket
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
const availableChangeCount = await storage.countChangeInputs(
|
|
88
|
+
userId,
|
|
89
|
+
changeBasket.basketId,
|
|
90
|
+
!vargs.isDelayed
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
const feeModel = validateStorageFeeModel(storage.feeModel)
|
|
94
|
+
|
|
95
|
+
const newTx = await createNewTxRecord(storage, userId, vargs, storageBeef)
|
|
96
|
+
|
|
97
|
+
const ctx: CreateTransactionSdkContext = {
|
|
98
|
+
xinputs,
|
|
99
|
+
xoutputs,
|
|
100
|
+
changeBasket,
|
|
101
|
+
noSendChangeIn,
|
|
102
|
+
availableChangeCount,
|
|
103
|
+
feeModel,
|
|
104
|
+
transactionId: newTx.transactionId!
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const { allocatedChange, changeOutputs, derivationPrefix } =
|
|
108
|
+
await fundNewTransactionSdk(storage, userId, vargs, ctx)
|
|
109
|
+
|
|
110
|
+
// The satoshis of the transaction is the satoshis we get back in change minus the satoshis we spend.
|
|
111
|
+
const satoshis =
|
|
112
|
+
changeOutputs.reduce((a, e) => a + e.satoshis!, 0) -
|
|
113
|
+
allocatedChange.reduce((a, e) => a + e.satoshis!, 0)
|
|
114
|
+
await storage.updateTransaction(newTx.transactionId!, { satoshis })
|
|
115
|
+
|
|
116
|
+
const { outputs, changeVouts } = await createNewOutputs(
|
|
117
|
+
storage,
|
|
118
|
+
userId,
|
|
119
|
+
vargs,
|
|
120
|
+
ctx,
|
|
121
|
+
changeOutputs
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
const inputBeef = await mergeAllocatedChangeBeefs(
|
|
125
|
+
storage,
|
|
126
|
+
userId,
|
|
127
|
+
vargs,
|
|
128
|
+
allocatedChange,
|
|
129
|
+
beef
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
const inputs = await createNewInputs(
|
|
133
|
+
storage,
|
|
134
|
+
userId,
|
|
135
|
+
vargs,
|
|
136
|
+
ctx,
|
|
137
|
+
allocatedChange
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
const r: sdk.StorageCreateActionResult = {
|
|
141
|
+
reference: newTx.reference!,
|
|
142
|
+
version: newTx.version!,
|
|
143
|
+
lockTime: newTx.lockTime!,
|
|
144
|
+
inputs,
|
|
145
|
+
outputs,
|
|
146
|
+
derivationPrefix,
|
|
147
|
+
inputBeef,
|
|
148
|
+
noSendChangeOutputVouts: vargs.isNoSend ? changeVouts : undefined
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
//stampLog(vargs, `end storage createTransactionSdk`)
|
|
152
|
+
return r
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
interface CreateTransactionSdkContext {
|
|
156
|
+
xinputs: XValidCreateActionInput[]
|
|
157
|
+
xoutputs: XValidCreateActionOutput[]
|
|
158
|
+
changeBasket: table.OutputBasket
|
|
159
|
+
noSendChangeIn: table.Output[]
|
|
160
|
+
availableChangeCount: number
|
|
161
|
+
feeModel: sdk.StorageFeeModel
|
|
162
|
+
transactionId: number
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
interface XValidCreateActionInput extends sdk.ValidCreateActionInput {
|
|
166
|
+
vin: number
|
|
167
|
+
lockingScript: Script
|
|
168
|
+
satoshis: number
|
|
169
|
+
output?: table.Output
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export interface XValidCreateActionOutput extends sdk.ValidCreateActionOutput {
|
|
173
|
+
vout: number
|
|
174
|
+
providedBy: sdk.StorageProvidedBy
|
|
175
|
+
purpose?: string
|
|
176
|
+
derivationSuffix?: string
|
|
177
|
+
keyOffset?: string
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function makeDefaultOutput(
|
|
181
|
+
userId: number,
|
|
182
|
+
transactionId: number,
|
|
183
|
+
satoshis: number,
|
|
184
|
+
vout: number
|
|
185
|
+
): table.Output {
|
|
186
|
+
const now = new Date()
|
|
187
|
+
const output: table.Output = {
|
|
188
|
+
created_at: now,
|
|
189
|
+
updated_at: now,
|
|
190
|
+
outputId: 0,
|
|
191
|
+
userId,
|
|
192
|
+
transactionId,
|
|
193
|
+
satoshis: satoshis,
|
|
194
|
+
vout,
|
|
195
|
+
|
|
196
|
+
basketId: undefined,
|
|
197
|
+
change: false,
|
|
198
|
+
customInstructions: undefined,
|
|
199
|
+
derivationPrefix: undefined,
|
|
200
|
+
derivationSuffix: undefined,
|
|
201
|
+
outputDescription: '',
|
|
202
|
+
lockingScript: undefined,
|
|
203
|
+
providedBy: 'you',
|
|
204
|
+
purpose: '',
|
|
205
|
+
senderIdentityKey: undefined,
|
|
206
|
+
spendable: true,
|
|
207
|
+
spendingDescription: undefined,
|
|
208
|
+
spentBy: undefined,
|
|
209
|
+
txid: undefined,
|
|
210
|
+
type: ''
|
|
211
|
+
}
|
|
212
|
+
return output
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
async function createNewInputs(
|
|
216
|
+
storage: StorageProvider,
|
|
217
|
+
userId: number,
|
|
218
|
+
vargs: sdk.ValidCreateActionArgs,
|
|
219
|
+
ctx: CreateTransactionSdkContext,
|
|
220
|
+
allocatedChange: table.Output[]
|
|
221
|
+
): Promise<sdk.StorageCreateTransactionSdkInput[]> {
|
|
222
|
+
const r: sdk.StorageCreateTransactionSdkInput[] = []
|
|
223
|
+
|
|
224
|
+
const newInputs: {
|
|
225
|
+
i?: XValidCreateActionInput
|
|
226
|
+
o?: table.Output
|
|
227
|
+
unlockLen?: number
|
|
228
|
+
}[] = []
|
|
229
|
+
for (const i of ctx.xinputs) {
|
|
230
|
+
const o = i.output
|
|
231
|
+
newInputs.push({ i, o })
|
|
232
|
+
if (o) {
|
|
233
|
+
await storage.updateOutput(o.outputId!, {
|
|
234
|
+
spendable: false,
|
|
235
|
+
spentBy: ctx.transactionId,
|
|
236
|
+
spendingDescription: i.inputDescription
|
|
237
|
+
})
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
for (const o of allocatedChange) {
|
|
242
|
+
newInputs.push({ o, unlockLen: 107 })
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
let vin = -1
|
|
246
|
+
for (const { i, o, unlockLen } of newInputs) {
|
|
247
|
+
vin++
|
|
248
|
+
if (o) {
|
|
249
|
+
if (!i && !unlockLen)
|
|
250
|
+
throw new sdk.WERR_INTERNAL(
|
|
251
|
+
`vin ${vin} non-fixedInput without unlockLen`
|
|
252
|
+
)
|
|
253
|
+
const ri: sdk.StorageCreateTransactionSdkInput = {
|
|
254
|
+
vin,
|
|
255
|
+
sourceTxid: o.txid!,
|
|
256
|
+
sourceVout: o!.vout!,
|
|
257
|
+
sourceSatoshis: o.satoshis!,
|
|
258
|
+
sourceLockingScript: asString(o.lockingScript!),
|
|
259
|
+
unlockingScriptLength: unlockLen ? unlockLen : i!.unlockingScriptLength,
|
|
260
|
+
providedBy:
|
|
261
|
+
i && o.providedBy === 'storage'
|
|
262
|
+
? 'you-and-storage'
|
|
263
|
+
: (o.providedBy! as sdk.StorageProvidedBy),
|
|
264
|
+
type: o.type,
|
|
265
|
+
spendingDescription: o.spendingDescription || undefined,
|
|
266
|
+
derivationPrefix: o.derivationPrefix || undefined,
|
|
267
|
+
derivationSuffix: o.derivationSuffix || undefined,
|
|
268
|
+
senderIdentityKey: o.senderIdentityKey || undefined
|
|
269
|
+
}
|
|
270
|
+
r.push(ri)
|
|
271
|
+
} else {
|
|
272
|
+
if (!i) throw new sdk.WERR_INTERNAL(`vin ${vin} without output or xinput`)
|
|
273
|
+
// user specified input with no corresponding output being spent.
|
|
274
|
+
const ri: sdk.StorageCreateTransactionSdkInput = {
|
|
275
|
+
vin,
|
|
276
|
+
sourceTxid: i.outpoint.txid,
|
|
277
|
+
sourceVout: i.outpoint.vout,
|
|
278
|
+
sourceSatoshis: i.satoshis,
|
|
279
|
+
sourceLockingScript: i.lockingScript.toHex(),
|
|
280
|
+
unlockingScriptLength: i.unlockingScriptLength,
|
|
281
|
+
providedBy: 'you',
|
|
282
|
+
type: 'custom',
|
|
283
|
+
spendingDescription: undefined,
|
|
284
|
+
derivationPrefix: undefined,
|
|
285
|
+
derivationSuffix: undefined,
|
|
286
|
+
senderIdentityKey: undefined
|
|
287
|
+
}
|
|
288
|
+
r.push(ri)
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return r
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
async function createNewOutputs(
|
|
295
|
+
storage: StorageProvider,
|
|
296
|
+
userId: number,
|
|
297
|
+
vargs: sdk.ValidCreateActionArgs,
|
|
298
|
+
ctx: CreateTransactionSdkContext,
|
|
299
|
+
changeOutputs: table.Output[]
|
|
300
|
+
): Promise<{
|
|
301
|
+
outputs: sdk.StorageCreateTransactionSdkOutput[]
|
|
302
|
+
changeVouts: number[]
|
|
303
|
+
}> {
|
|
304
|
+
const outputs: sdk.StorageCreateTransactionSdkOutput[] = []
|
|
305
|
+
|
|
306
|
+
// Lookup output baskets
|
|
307
|
+
const txBaskets: Record<string, table.OutputBasket> = {}
|
|
308
|
+
for (const xo of ctx.xoutputs) {
|
|
309
|
+
if (xo.basket !== undefined && !txBaskets[xo.basket])
|
|
310
|
+
txBaskets[xo.basket] = await storage.findOrInsertOutputBasket(
|
|
311
|
+
userId,
|
|
312
|
+
xo.basket!
|
|
313
|
+
)
|
|
314
|
+
}
|
|
315
|
+
// Lookup output tags
|
|
316
|
+
const txTags: Record<string, table.OutputTag> = {}
|
|
317
|
+
for (const xo of ctx.xoutputs) {
|
|
318
|
+
for (const tag of xo.tags) {
|
|
319
|
+
txTags[tag] = await storage.findOrInsertOutputTag(userId, tag)
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const newOutputs: { o: table.Output; tags: string[] }[] = []
|
|
324
|
+
|
|
325
|
+
for (const xo of ctx.xoutputs) {
|
|
326
|
+
const lockingScript = asArray(xo.lockingScript)
|
|
327
|
+
if (xo.purpose === 'service-charge') {
|
|
328
|
+
const now = new Date()
|
|
329
|
+
await storage.insertCommission({
|
|
330
|
+
userId,
|
|
331
|
+
transactionId: ctx.transactionId,
|
|
332
|
+
lockingScript,
|
|
333
|
+
satoshis: xo.satoshis,
|
|
334
|
+
isRedeemed: false,
|
|
335
|
+
keyOffset: verifyTruthy(xo.keyOffset),
|
|
336
|
+
created_at: now,
|
|
337
|
+
updated_at: now,
|
|
338
|
+
commissionId: 0
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
const o = makeDefaultOutput(
|
|
342
|
+
userId,
|
|
343
|
+
ctx.transactionId,
|
|
344
|
+
xo.satoshis,
|
|
345
|
+
xo.vout
|
|
346
|
+
)
|
|
347
|
+
o.lockingScript = lockingScript
|
|
348
|
+
o.providedBy = 'storage'
|
|
349
|
+
o.purpose = 'storage-commission'
|
|
350
|
+
o.type = 'custom'
|
|
351
|
+
o.spendable = false
|
|
352
|
+
|
|
353
|
+
newOutputs.push({ o, tags: [] })
|
|
354
|
+
} else {
|
|
355
|
+
// The user wants tracking if they put their output in a basket
|
|
356
|
+
const basketId = !xo.basket ? undefined : txBaskets[xo.basket].basketId!
|
|
357
|
+
|
|
358
|
+
const o = makeDefaultOutput(
|
|
359
|
+
userId,
|
|
360
|
+
ctx.transactionId,
|
|
361
|
+
xo.satoshis,
|
|
362
|
+
xo.vout
|
|
363
|
+
)
|
|
364
|
+
o.lockingScript = lockingScript
|
|
365
|
+
o.basketId = basketId
|
|
366
|
+
o.customInstructions = xo.customInstructions
|
|
367
|
+
o.outputDescription = xo.outputDescription
|
|
368
|
+
o.providedBy = xo.providedBy
|
|
369
|
+
o.purpose = xo.purpose || ''
|
|
370
|
+
o.type = 'custom'
|
|
371
|
+
|
|
372
|
+
newOutputs.push({ o, tags: xo.tags })
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
for (const o of changeOutputs) {
|
|
377
|
+
o.spendable = true
|
|
378
|
+
newOutputs.push({ o, tags: [] })
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
if (vargs.options.randomizeOutputs) {
|
|
382
|
+
const randomVals: number[] = []
|
|
383
|
+
|
|
384
|
+
const nextRandomVal = (): number => {
|
|
385
|
+
let val = 0
|
|
386
|
+
if (!randomVals || randomVals.length === 0) {
|
|
387
|
+
val = Math.random()
|
|
388
|
+
} else {
|
|
389
|
+
val = randomVals.shift() || 0
|
|
390
|
+
randomVals.push(val)
|
|
391
|
+
}
|
|
392
|
+
return val
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/** In-place array shuffle */
|
|
396
|
+
const shuffleArray = <T>(array: T[]): T[] => {
|
|
397
|
+
let currentIndex = array.length
|
|
398
|
+
let temporaryValue: T
|
|
399
|
+
let randomIndex: number
|
|
400
|
+
while (currentIndex !== 0) {
|
|
401
|
+
randomIndex = Math.floor(nextRandomVal() * currentIndex)
|
|
402
|
+
currentIndex -= 1
|
|
403
|
+
temporaryValue = array[currentIndex]
|
|
404
|
+
array[currentIndex] = array[randomIndex]
|
|
405
|
+
array[randomIndex] = temporaryValue
|
|
406
|
+
}
|
|
407
|
+
return array
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
let vout = -1
|
|
411
|
+
const newVouts = Array<number>(newOutputs.length)
|
|
412
|
+
for (let i = 0; i < newVouts.length; i++) newVouts[i] = i
|
|
413
|
+
shuffleArray(newVouts)
|
|
414
|
+
for (const no of newOutputs) {
|
|
415
|
+
vout++
|
|
416
|
+
if (no.o.vout !== vout)
|
|
417
|
+
throw new sdk.WERR_INTERNAL(
|
|
418
|
+
`new output ${vout} has out of order vout ${no.o.vout}`
|
|
419
|
+
)
|
|
420
|
+
no.o.vout = newVouts[vout]
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const changeVouts: number[] = []
|
|
425
|
+
for (const { o, tags } of newOutputs) {
|
|
426
|
+
o.outputId = await storage.insertOutput(o)
|
|
427
|
+
|
|
428
|
+
if (o.change && o.purpose === 'change' && o.providedBy === 'storage')
|
|
429
|
+
changeVouts.push(o.vout!)
|
|
430
|
+
|
|
431
|
+
// Add tags to the output
|
|
432
|
+
for (const tagName of tags) {
|
|
433
|
+
const tag = txTags[tagName]!
|
|
434
|
+
await storage.findOrInsertOutputTagMap(
|
|
435
|
+
verifyId(o.outputId),
|
|
436
|
+
verifyId(tag.outputTagId)
|
|
437
|
+
)
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const ro: sdk.StorageCreateTransactionSdkOutput = {
|
|
441
|
+
vout: verifyTruthy(o.vout),
|
|
442
|
+
satoshis: verifyTruthy(o.satoshis),
|
|
443
|
+
lockingScript: !o.lockingScript ? '' : asString(o.lockingScript),
|
|
444
|
+
providedBy: verifyTruthy(o.providedBy) as sdk.StorageProvidedBy,
|
|
445
|
+
purpose: o.purpose || undefined,
|
|
446
|
+
basket: Object.values(txBaskets).find(b => b.basketId === o.basketId)
|
|
447
|
+
?.name,
|
|
448
|
+
tags: tags,
|
|
449
|
+
outputDescription: o.outputDescription,
|
|
450
|
+
derivationSuffix: o.derivationSuffix,
|
|
451
|
+
customInstructions: o.customInstructions
|
|
452
|
+
}
|
|
453
|
+
outputs.push(ro)
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
return { outputs, changeVouts }
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
async function createNewTxRecord(
|
|
460
|
+
storage: StorageProvider,
|
|
461
|
+
userId: number,
|
|
462
|
+
vargs: sdk.ValidCreateActionArgs,
|
|
463
|
+
storageBeef: Beef
|
|
464
|
+
): Promise<table.Transaction> {
|
|
465
|
+
const now = new Date()
|
|
466
|
+
const newTx: table.Transaction = {
|
|
467
|
+
created_at: now,
|
|
468
|
+
updated_at: now,
|
|
469
|
+
transactionId: 0,
|
|
470
|
+
version: vargs.version,
|
|
471
|
+
lockTime: vargs.lockTime,
|
|
472
|
+
status: 'unsigned',
|
|
473
|
+
reference: randomBytesBase64(12),
|
|
474
|
+
satoshis: 0, // updated after fundingTransaction
|
|
475
|
+
userId,
|
|
476
|
+
isOutgoing: true,
|
|
477
|
+
inputBEEF: storageBeef.toBinary(),
|
|
478
|
+
description: vargs.description,
|
|
479
|
+
txid: undefined,
|
|
480
|
+
rawTx: undefined
|
|
481
|
+
}
|
|
482
|
+
newTx.transactionId = await storage.insertTransaction(newTx)
|
|
483
|
+
|
|
484
|
+
for (const label of vargs.labels) {
|
|
485
|
+
const txLabel = await storage.findOrInsertTxLabel(userId, label)
|
|
486
|
+
await storage.findOrInsertTxLabelMap(
|
|
487
|
+
verifyId(newTx.transactionId),
|
|
488
|
+
verifyId(txLabel.txLabelId)
|
|
489
|
+
)
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
return newTx
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Convert vargs.outputs:
|
|
497
|
+
*
|
|
498
|
+
* lockingScript: HexString
|
|
499
|
+
* satoshis: SatoshiValue
|
|
500
|
+
* outputDescription: DescriptionString5to50Bytes
|
|
501
|
+
* basket?: BasketStringUnder300Bytes
|
|
502
|
+
* customInstructions?: string
|
|
503
|
+
* tags: BasketStringUnderBytes[]
|
|
504
|
+
*
|
|
505
|
+
* to XValidCreateActionOutput (which aims for sdk.StorageCreateTransactionSdkOutput)
|
|
506
|
+
*
|
|
507
|
+
* adds:
|
|
508
|
+
* vout: number
|
|
509
|
+
* providedBy: sdk.StorageProvidedBy
|
|
510
|
+
* purpose?: string
|
|
511
|
+
* derivationSuffix?: string
|
|
512
|
+
* keyOffset?: string
|
|
513
|
+
*
|
|
514
|
+
* @param vargs
|
|
515
|
+
* @returns xoutputs
|
|
516
|
+
*/
|
|
517
|
+
function validateRequiredOutputs(
|
|
518
|
+
storage: StorageProvider,
|
|
519
|
+
userId: number,
|
|
520
|
+
vargs: sdk.ValidCreateActionArgs
|
|
521
|
+
): XValidCreateActionOutput[] {
|
|
522
|
+
const xoutputs: XValidCreateActionOutput[] = []
|
|
523
|
+
let vout = -1
|
|
524
|
+
for (const output of vargs.outputs) {
|
|
525
|
+
vout++
|
|
526
|
+
const xo: XValidCreateActionOutput = {
|
|
527
|
+
...output,
|
|
528
|
+
vout,
|
|
529
|
+
providedBy: 'you',
|
|
530
|
+
purpose: undefined,
|
|
531
|
+
derivationSuffix: undefined,
|
|
532
|
+
keyOffset: undefined
|
|
533
|
+
}
|
|
534
|
+
xoutputs.push(xo)
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
if (storage.commissionSatoshis > 0 && storage.commissionPubKeyHex) {
|
|
538
|
+
vout++
|
|
539
|
+
const { script, keyOffset } = createStorageServiceChargeScript(
|
|
540
|
+
storage.commissionPubKeyHex
|
|
541
|
+
)
|
|
542
|
+
xoutputs.push({
|
|
543
|
+
lockingScript: script,
|
|
544
|
+
satoshis: storage.commissionSatoshis,
|
|
545
|
+
outputDescription: 'Storage Service Charge',
|
|
546
|
+
basket: undefined,
|
|
547
|
+
tags: [],
|
|
548
|
+
|
|
549
|
+
vout,
|
|
550
|
+
providedBy: 'storage',
|
|
551
|
+
purpose: 'service-charge',
|
|
552
|
+
keyOffset
|
|
553
|
+
})
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
return xoutputs
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Verify that we are in posession of validity proof data for any inputs being proposed for a new transaction.
|
|
561
|
+
*
|
|
562
|
+
* `vargs.inputs` is the source of inputs.
|
|
563
|
+
* `vargs.inputBEEF` may include new user supplied validity data.
|
|
564
|
+
* 'vargs.options.trustSelf === 'known'` indicates whether we can rely on the storage database records.
|
|
565
|
+
*
|
|
566
|
+
* If there are no inputs, returns an empty `Beef`.
|
|
567
|
+
*
|
|
568
|
+
* Always pulls rawTx data into first level of validity chains so that parsed transaction data is available
|
|
569
|
+
* and checks input sourceSatoshis as well as filling in input sourceLockingScript.
|
|
570
|
+
*
|
|
571
|
+
* This data may be pruned again before being returned to the user based on `vargs.options.knownTxids`.
|
|
572
|
+
*
|
|
573
|
+
* @param storage
|
|
574
|
+
* @param userId
|
|
575
|
+
* @param vargs
|
|
576
|
+
* @returns {storageBeef} containing only validity proof data for only unknown required inputs.
|
|
577
|
+
* @returns {beef} containing verified validity proof data for all required inputs.
|
|
578
|
+
* @returns {xinputs} extended validated required inputs.
|
|
579
|
+
*/
|
|
580
|
+
async function validateRequiredInputs(
|
|
581
|
+
storage: StorageProvider,
|
|
582
|
+
userId: number,
|
|
583
|
+
vargs: sdk.ValidCreateActionArgs
|
|
584
|
+
): Promise<{
|
|
585
|
+
storageBeef: Beef
|
|
586
|
+
beef: Beef
|
|
587
|
+
xinputs: XValidCreateActionInput[]
|
|
588
|
+
}> {
|
|
589
|
+
//stampLog(vargs, `start storage verifyInputBeef`)
|
|
590
|
+
|
|
591
|
+
const beef = new Beef()
|
|
592
|
+
|
|
593
|
+
if (vargs.inputs.length === 0) return { storageBeef: beef, beef, xinputs: [] }
|
|
594
|
+
|
|
595
|
+
if (vargs.inputBEEF) beef.mergeBeef(vargs.inputBEEF)
|
|
596
|
+
|
|
597
|
+
const xinputs: XValidCreateActionInput[] = vargs.inputs.map((input, vin) => ({
|
|
598
|
+
...input,
|
|
599
|
+
vin,
|
|
600
|
+
satoshis: -1,
|
|
601
|
+
lockingScript: new Script()
|
|
602
|
+
}))
|
|
603
|
+
|
|
604
|
+
const trustSelf = vargs.options.trustSelf === 'known'
|
|
605
|
+
|
|
606
|
+
const inputTxids: Record<string, boolean> = {}
|
|
607
|
+
for (const input of xinputs) inputTxids[input.outpoint.txid] = true
|
|
608
|
+
|
|
609
|
+
// Check beef from user that either there are no txidOnly entries,
|
|
610
|
+
// or that we can trust storage data and it does indeed vouch
|
|
611
|
+
// for any txidOnly entries
|
|
612
|
+
for (const btx of beef.txs) {
|
|
613
|
+
if (btx.isTxidOnly) {
|
|
614
|
+
if (!trustSelf)
|
|
615
|
+
throw new sdk.WERR_INVALID_PARAMETER(
|
|
616
|
+
'inputBEEF',
|
|
617
|
+
`valid and contain complete proof data for ${btx.txid}`
|
|
618
|
+
)
|
|
619
|
+
if (!inputTxids[btx.txid]) {
|
|
620
|
+
// inputTxids are checked next
|
|
621
|
+
const isKnown = await storage.verifyKnownValidTransaction(btx.txid)
|
|
622
|
+
if (!isKnown)
|
|
623
|
+
throw new sdk.WERR_INVALID_PARAMETER(
|
|
624
|
+
'inputBEEF',
|
|
625
|
+
`valid and contain complete proof data for unknown ${btx.txid}`
|
|
626
|
+
)
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
// Make sure that there's an entry for all inputs txid values:
|
|
632
|
+
for (const txid of Object.keys(inputTxids)) {
|
|
633
|
+
let btx = beef.findTxid(txid)
|
|
634
|
+
if (!btx && trustSelf) {
|
|
635
|
+
if (await storage.verifyKnownValidTransaction(txid))
|
|
636
|
+
btx = beef.mergeTxidOnly(txid)
|
|
637
|
+
}
|
|
638
|
+
if (!btx)
|
|
639
|
+
throw new sdk.WERR_INVALID_PARAMETER(
|
|
640
|
+
'inputBEEF',
|
|
641
|
+
`valid and contain proof data for possibly known ${txid}`
|
|
642
|
+
)
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
if (
|
|
646
|
+
!(await beef.verify(await storage.getServices().getChainTracker(), true))
|
|
647
|
+
) {
|
|
648
|
+
console.log(
|
|
649
|
+
`verifyInputBeef failed, inputBEEF failed to verify.\n${beef.toLogString()}\n`
|
|
650
|
+
)
|
|
651
|
+
//console.log(`verifyInputBeef failed, inputBEEF failed to verify.\n${stampLogFormat(vargs.log)}\n${beef.toLogString()}\n`)
|
|
652
|
+
throw new sdk.WERR_INVALID_PARAMETER(
|
|
653
|
+
'inputBEEF',
|
|
654
|
+
'valid Beef when factoring options.trustSelf'
|
|
655
|
+
)
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// beef may now be trusted and has a BeefTx for every input txid.
|
|
659
|
+
|
|
660
|
+
const storageBeef = beef.clone()
|
|
661
|
+
|
|
662
|
+
for (const input of xinputs) {
|
|
663
|
+
const { txid, vout } = input.outpoint
|
|
664
|
+
const output = verifyOneOrNone(
|
|
665
|
+
await storage.findOutputs({ partial: { userId, txid, vout } })
|
|
666
|
+
)
|
|
667
|
+
if (output) {
|
|
668
|
+
input.output = output
|
|
669
|
+
if (
|
|
670
|
+
!Array.isArray(output.lockingScript) ||
|
|
671
|
+
!Number.isInteger(output.satoshis)
|
|
672
|
+
)
|
|
673
|
+
throw new sdk.WERR_INVALID_PARAMETER(
|
|
674
|
+
`${txid}.${vout}`,
|
|
675
|
+
'output with valid lockingScript and satoshis'
|
|
676
|
+
)
|
|
677
|
+
if (!output.spendable && !vargs.isNoSend)
|
|
678
|
+
throw new sdk.WERR_INVALID_PARAMETER(
|
|
679
|
+
`${txid}.${vout}`,
|
|
680
|
+
'spendable output unless noSend is true'
|
|
681
|
+
)
|
|
682
|
+
// input is spending an existing user output which has an lockingScript
|
|
683
|
+
input.satoshis = verifyNumber(output.satoshis)
|
|
684
|
+
input.lockingScript = Script.fromBinary(asArray(output.lockingScript!))
|
|
685
|
+
} else {
|
|
686
|
+
let btx = beef.findTxid(txid)!
|
|
687
|
+
if (btx.isTxidOnly) {
|
|
688
|
+
const { rawTx, proven } = await storage.getProvenOrRawTx(txid)
|
|
689
|
+
//stampLog(vargs, `... storage verifyInputBeef getProvenOrRawTx ${txid} ${proven ? 'proven' : rawTx ? 'rawTx' : 'unknown'}`)
|
|
690
|
+
if (!rawTx)
|
|
691
|
+
throw new sdk.WERR_INVALID_PARAMETER(
|
|
692
|
+
'inputBEEF',
|
|
693
|
+
`valid and contain proof data for ${txid}`
|
|
694
|
+
)
|
|
695
|
+
btx = beef.mergeRawTx(asArray(rawTx))
|
|
696
|
+
if (proven) beef.mergeBump(new entity.ProvenTx(proven).getMerklePath())
|
|
697
|
+
}
|
|
698
|
+
// btx is valid has parsed transaction data.
|
|
699
|
+
if (vout >= btx.tx.outputs.length)
|
|
700
|
+
throw new sdk.WERR_INVALID_PARAMETER(
|
|
701
|
+
`${txid}.${vout}`,
|
|
702
|
+
'valid outpoint'
|
|
703
|
+
)
|
|
704
|
+
const so = btx.tx.outputs[vout]
|
|
705
|
+
input.satoshis = verifyTruthy(so.satoshis)
|
|
706
|
+
input.lockingScript = so.lockingScript
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
return { beef, storageBeef, xinputs }
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
async function validateNoSendChange(
|
|
714
|
+
dojo: StorageProvider,
|
|
715
|
+
userId: number,
|
|
716
|
+
vargs: sdk.ValidCreateActionArgs,
|
|
717
|
+
changeBasket: table.OutputBasket
|
|
718
|
+
): Promise<table.Output[]> {
|
|
719
|
+
const r: table.Output[] = []
|
|
720
|
+
|
|
721
|
+
if (!vargs.isNoSend) return []
|
|
722
|
+
|
|
723
|
+
const noSendChange = vargs.options.noSendChange
|
|
724
|
+
|
|
725
|
+
if (noSendChange && noSendChange.length > 0) {
|
|
726
|
+
for (const op of noSendChange) {
|
|
727
|
+
const output = verifyOneOrNone(
|
|
728
|
+
await dojo.findOutputs({
|
|
729
|
+
partial: { userId, txid: op.txid, vout: op.vout }
|
|
730
|
+
})
|
|
731
|
+
)
|
|
732
|
+
// noSendChange is not marked spendable until sent, may not already be spent, and must have a valid greater than zero satoshis
|
|
733
|
+
if (
|
|
734
|
+
!output ||
|
|
735
|
+
output.providedBy !== 'storage' ||
|
|
736
|
+
output.purpose !== 'change' ||
|
|
737
|
+
output.spendable === false ||
|
|
738
|
+
Number.isInteger(output.spentBy) ||
|
|
739
|
+
!verifyNumber(output.satoshis) ||
|
|
740
|
+
output.basketId !== changeBasket.basketId
|
|
741
|
+
)
|
|
742
|
+
throw new sdk.WERR_INVALID_PARAMETER('noSendChange outpoint', 'valid')
|
|
743
|
+
if (-1 < r.findIndex(o => o.outputId === output.outputId))
|
|
744
|
+
// noSendChange duplicate OutPoints are not allowed.
|
|
745
|
+
throw new sdk.WERR_INVALID_PARAMETER(
|
|
746
|
+
'noSendChange outpoint',
|
|
747
|
+
'unique. Duplicates are not allowed.'
|
|
748
|
+
)
|
|
749
|
+
r.push(output)
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
return r
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
async function fundNewTransactionSdk(
|
|
757
|
+
dojo: StorageProvider,
|
|
758
|
+
userId: number,
|
|
759
|
+
vargs: sdk.ValidCreateActionArgs,
|
|
760
|
+
ctx: CreateTransactionSdkContext
|
|
761
|
+
): Promise<{
|
|
762
|
+
allocatedChange: table.Output[]
|
|
763
|
+
changeOutputs: table.Output[]
|
|
764
|
+
derivationPrefix: string
|
|
765
|
+
}> {
|
|
766
|
+
const params: GenerateChangeSdkParams = {
|
|
767
|
+
fixedInputs: ctx.xinputs.map(xi => ({
|
|
768
|
+
satoshis: xi.satoshis,
|
|
769
|
+
unlockingScriptLength: xi.unlockingScriptLength!
|
|
770
|
+
})),
|
|
771
|
+
fixedOutputs: ctx.xoutputs.map(xo => ({
|
|
772
|
+
satoshis: xo.satoshis,
|
|
773
|
+
lockingScriptLength: xo.lockingScript.length / 2
|
|
774
|
+
})),
|
|
775
|
+
feeModel: ctx.feeModel,
|
|
776
|
+
changeInitialSatoshis: ctx.changeBasket.minimumDesiredUTXOValue,
|
|
777
|
+
changeFirstSatoshis: Math.max(
|
|
778
|
+
1,
|
|
779
|
+
ctx.changeBasket.minimumDesiredUTXOValue / 4
|
|
780
|
+
),
|
|
781
|
+
changeLockingScriptLength: 25,
|
|
782
|
+
changeUnlockingScriptLength: 107,
|
|
783
|
+
targetNetCount:
|
|
784
|
+
ctx.changeBasket.numberOfDesiredUTXOs - ctx.availableChangeCount
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
const noSendChange = [...ctx.noSendChangeIn]
|
|
788
|
+
const outputs: Record<number, table.Output> = {}
|
|
789
|
+
|
|
790
|
+
const allocateChangeInput = async (
|
|
791
|
+
targetSatoshis: number,
|
|
792
|
+
exactSatoshis?: number
|
|
793
|
+
): Promise<GenerateChangeSdkChangeInput | undefined> => {
|
|
794
|
+
// noSendChange gets allocated first...typically only one input...just allocate in order...
|
|
795
|
+
if (noSendChange.length > 0) {
|
|
796
|
+
const o = noSendChange.pop()!
|
|
797
|
+
outputs[o.outputId!] = o
|
|
798
|
+
// allocate the output in storage, noSendChange is by definition spendable false and part of noSpend transaction batch.
|
|
799
|
+
await dojo.updateOutput(o.outputId!, {
|
|
800
|
+
spendable: false,
|
|
801
|
+
spentBy: ctx.transactionId
|
|
802
|
+
})
|
|
803
|
+
o.spendable = false
|
|
804
|
+
o.spentBy = ctx.transactionId
|
|
805
|
+
const r: GenerateChangeSdkChangeInput = {
|
|
806
|
+
outputId: o.outputId!,
|
|
807
|
+
satoshis: o.satoshis!
|
|
808
|
+
}
|
|
809
|
+
return r
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
const basketId = ctx.changeBasket.basketId!
|
|
813
|
+
const o = await dojo.allocateChangeInput(
|
|
814
|
+
userId,
|
|
815
|
+
basketId,
|
|
816
|
+
targetSatoshis,
|
|
817
|
+
exactSatoshis,
|
|
818
|
+
!vargs.isDelayed,
|
|
819
|
+
ctx.transactionId
|
|
820
|
+
)
|
|
821
|
+
if (!o) return undefined
|
|
822
|
+
outputs[o.outputId!] = o
|
|
823
|
+
const r: GenerateChangeSdkChangeInput = {
|
|
824
|
+
outputId: o.outputId!,
|
|
825
|
+
satoshis: o.satoshis!
|
|
826
|
+
}
|
|
827
|
+
return r
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
const releaseChangeInput = async (outputId: number): Promise<void> => {
|
|
831
|
+
const nsco = ctx.noSendChangeIn.find(o => o.outputId === outputId)
|
|
832
|
+
if (nsco) {
|
|
833
|
+
noSendChange.push(nsco)
|
|
834
|
+
return
|
|
835
|
+
}
|
|
836
|
+
await dojo.updateOutput(outputId, {
|
|
837
|
+
spendable: true,
|
|
838
|
+
spentBy: undefined
|
|
839
|
+
})
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
const gcr = await generateChangeSdk(
|
|
843
|
+
params,
|
|
844
|
+
allocateChangeInput,
|
|
845
|
+
releaseChangeInput
|
|
846
|
+
)
|
|
847
|
+
|
|
848
|
+
// Generate a derivation prefix for the payment
|
|
849
|
+
const derivationPrefix = randomBytesBase64(16)
|
|
850
|
+
|
|
851
|
+
const r: {
|
|
852
|
+
allocatedChange: table.Output[]
|
|
853
|
+
changeOutputs: table.Output[]
|
|
854
|
+
derivationPrefix: string
|
|
855
|
+
} = {
|
|
856
|
+
allocatedChange: gcr.allocatedChangeInputs.map(i => outputs[i.outputId]),
|
|
857
|
+
changeOutputs: gcr.changeOutputs.map(
|
|
858
|
+
(o, i) =>
|
|
859
|
+
<table.Output>{
|
|
860
|
+
// what we knnow now and can insert into the database for this new transaction's change output
|
|
861
|
+
created_at: new Date(),
|
|
862
|
+
updated_at: new Date(),
|
|
863
|
+
outputId: 0,
|
|
864
|
+
userId,
|
|
865
|
+
transactionId: ctx.transactionId,
|
|
866
|
+
vout: params.fixedOutputs.length + i,
|
|
867
|
+
satoshis: o.satoshis,
|
|
868
|
+
basketId: ctx.changeBasket.basketId!,
|
|
869
|
+
spendable: false,
|
|
870
|
+
change: true,
|
|
871
|
+
type: 'P2PKH',
|
|
872
|
+
derivationPrefix,
|
|
873
|
+
derivationSuffix: randomBytesBase64(16),
|
|
874
|
+
providedBy: 'storage',
|
|
875
|
+
purpose: 'change',
|
|
876
|
+
customInstructions: undefined,
|
|
877
|
+
senderIdentityKey: undefined,
|
|
878
|
+
outputDescription: '',
|
|
879
|
+
|
|
880
|
+
// what will be known when transaction is signed
|
|
881
|
+
txid: undefined,
|
|
882
|
+
lockingScript: undefined,
|
|
883
|
+
|
|
884
|
+
// when this output gets spent
|
|
885
|
+
spentBy: undefined,
|
|
886
|
+
spendingDescription: undefined
|
|
887
|
+
}
|
|
888
|
+
),
|
|
889
|
+
derivationPrefix
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
return r
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
/**
|
|
896
|
+
* Avoid returning any known raw transaction data by converting any known transaction
|
|
897
|
+
* in the `beef` to txidOnly.
|
|
898
|
+
* @returns undefined if `vargs.options.returnTXIDOnly` or trimmed `Beef`
|
|
899
|
+
*/
|
|
900
|
+
function trimInputBeef(
|
|
901
|
+
beef: Beef,
|
|
902
|
+
vargs: sdk.ValidCreateActionArgs
|
|
903
|
+
): number[] | undefined {
|
|
904
|
+
if (vargs.options.returnTXIDOnly) return undefined
|
|
905
|
+
const knownTxids: Record<string, boolean> = {}
|
|
906
|
+
for (const txid of vargs.options.knownTxids) knownTxids[txid] = true
|
|
907
|
+
for (const txid of beef.txs.map(btx => btx.txid))
|
|
908
|
+
if (knownTxids[txid]) beef.makeTxidOnly(txid)
|
|
909
|
+
return beef.toBinary()
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
async function mergeAllocatedChangeBeefs(
|
|
913
|
+
dojo: StorageProvider,
|
|
914
|
+
userId: number,
|
|
915
|
+
vargs: sdk.ValidCreateActionArgs,
|
|
916
|
+
allocatedChange: table.Output[],
|
|
917
|
+
beef: Beef
|
|
918
|
+
): Promise<number[] | undefined> {
|
|
919
|
+
const options: sdk.StorageGetBeefOptions = {
|
|
920
|
+
trustSelf: undefined,
|
|
921
|
+
knownTxids: vargs.options.knownTxids,
|
|
922
|
+
mergeToBeef: beef,
|
|
923
|
+
ignoreStorage: false,
|
|
924
|
+
ignoreServices: true,
|
|
925
|
+
ignoreNewProven: false,
|
|
926
|
+
minProofLevel: undefined
|
|
927
|
+
}
|
|
928
|
+
if (vargs.options.returnTXIDOnly) return undefined
|
|
929
|
+
for (const o of allocatedChange) {
|
|
930
|
+
if (
|
|
931
|
+
!beef.findTxid(o.txid!) &&
|
|
932
|
+
!vargs.options.knownTxids.find(txid => txid === o.txid)
|
|
933
|
+
) {
|
|
934
|
+
await dojo.getBeefForTransaction(o.txid!, options)
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
return trimInputBeef(beef, vargs)
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
function keyOffsetToHashedSecret(
|
|
941
|
+
pub: PublicKey,
|
|
942
|
+
keyOffset?: string
|
|
943
|
+
): { hashedSecret: BigNumber; keyOffset: string } {
|
|
944
|
+
let offset: PrivateKey
|
|
945
|
+
if (keyOffset !== undefined && typeof keyOffset === 'string') {
|
|
946
|
+
if (keyOffset.length === 64)
|
|
947
|
+
offset = PrivateKey.fromString(keyOffset, 'hex')
|
|
948
|
+
else offset = PrivateKey.fromWif(keyOffset)
|
|
949
|
+
} else {
|
|
950
|
+
offset = PrivateKey.fromRandom()
|
|
951
|
+
keyOffset = offset.toWif()
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
const sharedSecret = pub.mul(offset).encode(true, undefined) as number[]
|
|
955
|
+
const hashedSecret = sha256Hash(sharedSecret)
|
|
956
|
+
|
|
957
|
+
return { hashedSecret: new BigNumber(hashedSecret), keyOffset }
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
export function offsetPubKey(
|
|
961
|
+
pubKey: string,
|
|
962
|
+
keyOffset?: string
|
|
963
|
+
): { offsetPubKey: string; keyOffset: string } {
|
|
964
|
+
const pub = PublicKey.fromString(pubKey)
|
|
965
|
+
|
|
966
|
+
const r = keyOffsetToHashedSecret(pub, keyOffset)
|
|
967
|
+
|
|
968
|
+
// The hashed secret is multiplied by the generator point.
|
|
969
|
+
const point = new Curve().g.mul(r.hashedSecret)
|
|
970
|
+
|
|
971
|
+
// The resulting point is added to the recipient public key.
|
|
972
|
+
const offsetPubKey = new PublicKey(pub.add(point))
|
|
973
|
+
|
|
974
|
+
return { offsetPubKey: offsetPubKey.toString(), keyOffset: r.keyOffset }
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
export function lockScriptWithKeyOffsetFromPubKey(
|
|
978
|
+
pubKey: string,
|
|
979
|
+
keyOffset?: string
|
|
980
|
+
): { script: string; keyOffset: string } {
|
|
981
|
+
const r = offsetPubKey(pubKey, keyOffset)
|
|
982
|
+
|
|
983
|
+
const offsetPub = PublicKey.fromString(r.offsetPubKey)
|
|
984
|
+
|
|
985
|
+
const hash = offsetPub.toHash() as number[]
|
|
986
|
+
|
|
987
|
+
const script = new P2PKH().lock(hash).toHex()
|
|
988
|
+
|
|
989
|
+
return { script, keyOffset: r.keyOffset }
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
export function createStorageServiceChargeScript(pubKeyHex: PubKeyHex): {
|
|
993
|
+
script: string
|
|
994
|
+
keyOffset: string
|
|
995
|
+
} {
|
|
996
|
+
return lockScriptWithKeyOffsetFromPubKey(pubKeyHex)
|
|
997
|
+
}
|