@bsv/wallet-toolbox 1.7.1 → 1.7.2
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/CHANGELOG.md +7 -0
- package/docs/client.md +489 -1334
- package/docs/services.md +5 -5
- package/docs/storage.md +64 -61
- package/docs/wallet.md +489 -1334
- package/mobile/out/src/Wallet.d.ts +21 -4
- package/mobile/out/src/Wallet.d.ts.map +1 -1
- package/mobile/out/src/Wallet.js +93 -57
- package/mobile/out/src/Wallet.js.map +1 -1
- package/mobile/out/src/WalletLogger.d.ts +33 -0
- package/mobile/out/src/WalletLogger.d.ts.map +1 -0
- package/mobile/out/src/WalletLogger.js +157 -0
- package/mobile/out/src/WalletLogger.js.map +1 -0
- package/mobile/out/src/WalletPermissionsManager.d.ts.map +1 -1
- package/mobile/out/src/WalletPermissionsManager.js +1 -2
- package/mobile/out/src/WalletPermissionsManager.js.map +1 -1
- package/mobile/out/src/sdk/WERR_errors.d.ts.map +1 -1
- package/mobile/out/src/sdk/WERR_errors.js.map +1 -1
- package/mobile/out/src/sdk/WalletError.d.ts.map +1 -1
- package/mobile/out/src/sdk/WalletError.js +0 -2
- package/mobile/out/src/sdk/WalletError.js.map +1 -1
- package/mobile/out/src/sdk/WalletServices.interfaces.d.ts +3 -3
- package/mobile/out/src/sdk/WalletServices.interfaces.d.ts.map +1 -1
- package/mobile/out/src/sdk/WalletStorage.interfaces.d.ts +9 -10
- package/mobile/out/src/sdk/WalletStorage.interfaces.d.ts.map +1 -1
- package/mobile/out/src/sdk/index.d.ts +1 -1
- package/mobile/out/src/sdk/index.d.ts.map +1 -1
- package/mobile/out/src/sdk/index.js +3 -1
- package/mobile/out/src/sdk/index.js.map +1 -1
- package/mobile/out/src/services/Services.d.ts +5 -5
- package/mobile/out/src/services/Services.d.ts.map +1 -1
- package/mobile/out/src/services/Services.js +18 -4
- package/mobile/out/src/services/Services.js.map +1 -1
- package/mobile/out/src/services/providers/WhatsOnChain.d.ts.map +1 -1
- package/mobile/out/src/services/providers/WhatsOnChain.js +1 -2
- package/mobile/out/src/services/providers/WhatsOnChain.js.map +1 -1
- package/mobile/out/src/services/providers/getBeefForTxid.d.ts.map +1 -1
- package/mobile/out/src/services/providers/getBeefForTxid.js.map +1 -1
- package/mobile/out/src/signer/methods/acquireDirectCertificate.d.ts +2 -3
- package/mobile/out/src/signer/methods/acquireDirectCertificate.d.ts.map +1 -1
- package/mobile/out/src/signer/methods/acquireDirectCertificate.js.map +1 -1
- package/mobile/out/src/signer/methods/buildSignableTransaction.d.ts +3 -4
- package/mobile/out/src/signer/methods/buildSignableTransaction.d.ts.map +1 -1
- package/mobile/out/src/signer/methods/buildSignableTransaction.js +1 -2
- package/mobile/out/src/signer/methods/buildSignableTransaction.js.map +1 -1
- package/mobile/out/src/signer/methods/createAction.d.ts +3 -4
- package/mobile/out/src/signer/methods/createAction.d.ts.map +1 -1
- package/mobile/out/src/signer/methods/createAction.js +17 -6
- package/mobile/out/src/signer/methods/createAction.js.map +1 -1
- package/mobile/out/src/signer/methods/internalizeAction.d.ts.map +1 -1
- package/mobile/out/src/signer/methods/internalizeAction.js +1 -2
- package/mobile/out/src/signer/methods/internalizeAction.js.map +1 -1
- package/mobile/out/src/signer/methods/proveCertificate.d.ts +2 -3
- package/mobile/out/src/signer/methods/proveCertificate.d.ts.map +1 -1
- package/mobile/out/src/signer/methods/proveCertificate.js.map +1 -1
- package/mobile/out/src/signer/methods/signAction.d.ts.map +1 -1
- package/mobile/out/src/signer/methods/signAction.js +1 -2
- package/mobile/out/src/signer/methods/signAction.js.map +1 -1
- package/mobile/out/src/storage/StorageIdb.d.ts +3 -4
- package/mobile/out/src/storage/StorageIdb.d.ts.map +1 -1
- package/mobile/out/src/storage/StorageIdb.js.map +1 -1
- package/mobile/out/src/storage/StorageProvider.d.ts +6 -7
- package/mobile/out/src/storage/StorageProvider.d.ts.map +1 -1
- package/mobile/out/src/storage/StorageProvider.js +5 -6
- package/mobile/out/src/storage/StorageProvider.js.map +1 -1
- package/mobile/out/src/storage/WalletStorageManager.d.ts +5 -5
- package/mobile/out/src/storage/WalletStorageManager.d.ts.map +1 -1
- package/mobile/out/src/storage/WalletStorageManager.js +5 -4
- package/mobile/out/src/storage/WalletStorageManager.js.map +1 -1
- package/mobile/out/src/storage/methods/ListActionsSpecOp.d.ts +2 -2
- package/mobile/out/src/storage/methods/ListActionsSpecOp.d.ts.map +1 -1
- package/mobile/out/src/storage/methods/ListActionsSpecOp.js.map +1 -1
- package/mobile/out/src/storage/methods/ListOutputsSpecOp.d.ts +4 -5
- package/mobile/out/src/storage/methods/ListOutputsSpecOp.d.ts.map +1 -1
- package/mobile/out/src/storage/methods/ListOutputsSpecOp.js.map +1 -1
- package/mobile/out/src/storage/methods/attemptToPostReqsToNetwork.d.ts +2 -2
- package/mobile/out/src/storage/methods/attemptToPostReqsToNetwork.d.ts.map +1 -1
- package/mobile/out/src/storage/methods/attemptToPostReqsToNetwork.js +11 -7
- package/mobile/out/src/storage/methods/attemptToPostReqsToNetwork.js.map +1 -1
- package/mobile/out/src/storage/methods/createAction.d.ts +3 -4
- package/mobile/out/src/storage/methods/createAction.d.ts.map +1 -1
- package/mobile/out/src/storage/methods/createAction.js +18 -5
- package/mobile/out/src/storage/methods/createAction.js.map +1 -1
- package/mobile/out/src/storage/methods/generateChange.js +10 -10
- package/mobile/out/src/storage/methods/generateChange.js.map +1 -1
- package/mobile/out/src/storage/methods/internalizeAction.d.ts.map +1 -1
- package/mobile/out/src/storage/methods/internalizeAction.js +1 -2
- package/mobile/out/src/storage/methods/internalizeAction.js.map +1 -1
- package/mobile/out/src/storage/methods/listActionsIdb.d.ts +2 -3
- package/mobile/out/src/storage/methods/listActionsIdb.d.ts.map +1 -1
- package/mobile/out/src/storage/methods/listActionsIdb.js.map +1 -1
- package/mobile/out/src/storage/methods/listCertificates.d.ts +3 -3
- package/mobile/out/src/storage/methods/listCertificates.d.ts.map +1 -1
- package/mobile/out/src/storage/methods/listCertificates.js.map +1 -1
- package/mobile/out/src/storage/methods/listOutputsIdb.d.ts +2 -3
- package/mobile/out/src/storage/methods/listOutputsIdb.d.ts.map +1 -1
- package/mobile/out/src/storage/methods/listOutputsIdb.js.map +1 -1
- package/mobile/out/src/storage/methods/processAction.d.ts +2 -2
- package/mobile/out/src/storage/methods/processAction.d.ts.map +1 -1
- package/mobile/out/src/storage/methods/processAction.js +15 -10
- package/mobile/out/src/storage/methods/processAction.js.map +1 -1
- package/mobile/out/src/storage/remoting/StorageClient.d.ts +5 -6
- package/mobile/out/src/storage/remoting/StorageClient.d.ts.map +1 -1
- package/mobile/out/src/storage/remoting/StorageClient.js +22 -0
- package/mobile/out/src/storage/remoting/StorageClient.js.map +1 -1
- package/mobile/out/src/storage/remoting/StorageMobile.d.ts +5 -6
- package/mobile/out/src/storage/remoting/StorageMobile.d.ts.map +1 -1
- package/mobile/out/src/storage/remoting/StorageMobile.js.map +1 -1
- package/mobile/package-lock.json +6 -6
- package/mobile/package.json +2 -2
- package/out/src/Wallet.d.ts +21 -4
- package/out/src/Wallet.d.ts.map +1 -1
- package/out/src/Wallet.js +93 -57
- package/out/src/Wallet.js.map +1 -1
- package/out/src/WalletLogger.d.ts +33 -0
- package/out/src/WalletLogger.d.ts.map +1 -0
- package/out/src/WalletLogger.js +157 -0
- package/out/src/WalletLogger.js.map +1 -0
- package/out/src/WalletPermissionsManager.d.ts.map +1 -1
- package/out/src/WalletPermissionsManager.js +1 -2
- package/out/src/WalletPermissionsManager.js.map +1 -1
- package/out/src/__tests/WalletPermissionsManager.fixtures.d.ts +1 -0
- package/out/src/__tests/WalletPermissionsManager.fixtures.d.ts.map +1 -1
- package/out/src/__tests/WalletPermissionsManager.fixtures.js +15 -4
- package/out/src/__tests/WalletPermissionsManager.fixtures.js.map +1 -1
- package/out/src/__tests/WalletPermissionsManager.proxying.test.js +79 -74
- package/out/src/__tests/WalletPermissionsManager.proxying.test.js.map +1 -1
- package/out/src/sdk/WERR_errors.d.ts.map +1 -1
- package/out/src/sdk/WERR_errors.js.map +1 -1
- package/out/src/sdk/WalletError.d.ts.map +1 -1
- package/out/src/sdk/WalletError.js +0 -2
- package/out/src/sdk/WalletError.js.map +1 -1
- package/out/src/sdk/WalletServices.interfaces.d.ts +3 -3
- package/out/src/sdk/WalletServices.interfaces.d.ts.map +1 -1
- package/out/src/sdk/WalletStorage.interfaces.d.ts +9 -10
- package/out/src/sdk/WalletStorage.interfaces.d.ts.map +1 -1
- package/out/src/sdk/__test/validationHelpers.test.js +4 -4
- package/out/src/sdk/__test/validationHelpers.test.js.map +1 -1
- package/out/src/sdk/index.d.ts +1 -1
- package/out/src/sdk/index.d.ts.map +1 -1
- package/out/src/sdk/index.js +3 -1
- package/out/src/sdk/index.js.map +1 -1
- package/out/src/services/Services.d.ts +5 -5
- package/out/src/services/Services.d.ts.map +1 -1
- package/out/src/services/Services.js +18 -4
- package/out/src/services/Services.js.map +1 -1
- package/out/src/services/providers/WhatsOnChain.d.ts.map +1 -1
- package/out/src/services/providers/WhatsOnChain.js +1 -2
- package/out/src/services/providers/WhatsOnChain.js.map +1 -1
- package/out/src/services/providers/getBeefForTxid.d.ts.map +1 -1
- package/out/src/services/providers/getBeefForTxid.js.map +1 -1
- package/out/src/signer/methods/acquireDirectCertificate.d.ts +2 -3
- package/out/src/signer/methods/acquireDirectCertificate.d.ts.map +1 -1
- package/out/src/signer/methods/acquireDirectCertificate.js.map +1 -1
- package/out/src/signer/methods/buildSignableTransaction.d.ts +3 -4
- package/out/src/signer/methods/buildSignableTransaction.d.ts.map +1 -1
- package/out/src/signer/methods/buildSignableTransaction.js +1 -2
- package/out/src/signer/methods/buildSignableTransaction.js.map +1 -1
- package/out/src/signer/methods/createAction.d.ts +3 -4
- package/out/src/signer/methods/createAction.d.ts.map +1 -1
- package/out/src/signer/methods/createAction.js +17 -6
- package/out/src/signer/methods/createAction.js.map +1 -1
- package/out/src/signer/methods/internalizeAction.d.ts.map +1 -1
- package/out/src/signer/methods/internalizeAction.js +1 -2
- package/out/src/signer/methods/internalizeAction.js.map +1 -1
- package/out/src/signer/methods/proveCertificate.d.ts +2 -3
- package/out/src/signer/methods/proveCertificate.d.ts.map +1 -1
- package/out/src/signer/methods/proveCertificate.js.map +1 -1
- package/out/src/signer/methods/signAction.d.ts.map +1 -1
- package/out/src/signer/methods/signAction.js +1 -2
- package/out/src/signer/methods/signAction.js.map +1 -1
- package/out/src/storage/StorageIdb.d.ts +3 -4
- package/out/src/storage/StorageIdb.d.ts.map +1 -1
- package/out/src/storage/StorageIdb.js.map +1 -1
- package/out/src/storage/StorageKnex.d.ts +3 -4
- package/out/src/storage/StorageKnex.d.ts.map +1 -1
- package/out/src/storage/StorageKnex.js.map +1 -1
- package/out/src/storage/StorageProvider.d.ts +6 -7
- package/out/src/storage/StorageProvider.d.ts.map +1 -1
- package/out/src/storage/StorageProvider.js +5 -6
- package/out/src/storage/StorageProvider.js.map +1 -1
- package/out/src/storage/WalletStorageManager.d.ts +5 -5
- package/out/src/storage/WalletStorageManager.d.ts.map +1 -1
- package/out/src/storage/WalletStorageManager.js +5 -4
- package/out/src/storage/WalletStorageManager.js.map +1 -1
- package/out/src/storage/__test/getBeefForTransaction.test.js.map +1 -1
- package/out/src/storage/methods/ListActionsSpecOp.d.ts +2 -2
- package/out/src/storage/methods/ListActionsSpecOp.d.ts.map +1 -1
- package/out/src/storage/methods/ListActionsSpecOp.js.map +1 -1
- package/out/src/storage/methods/ListOutputsSpecOp.d.ts +4 -5
- package/out/src/storage/methods/ListOutputsSpecOp.d.ts.map +1 -1
- package/out/src/storage/methods/ListOutputsSpecOp.js.map +1 -1
- package/out/src/storage/methods/attemptToPostReqsToNetwork.d.ts +2 -2
- package/out/src/storage/methods/attemptToPostReqsToNetwork.d.ts.map +1 -1
- package/out/src/storage/methods/attemptToPostReqsToNetwork.js +11 -7
- package/out/src/storage/methods/attemptToPostReqsToNetwork.js.map +1 -1
- package/out/src/storage/methods/createAction.d.ts +3 -4
- package/out/src/storage/methods/createAction.d.ts.map +1 -1
- package/out/src/storage/methods/createAction.js +18 -5
- package/out/src/storage/methods/createAction.js.map +1 -1
- package/out/src/storage/methods/generateChange.js +10 -10
- package/out/src/storage/methods/generateChange.js.map +1 -1
- package/out/src/storage/methods/internalizeAction.d.ts.map +1 -1
- package/out/src/storage/methods/internalizeAction.js +1 -2
- package/out/src/storage/methods/internalizeAction.js.map +1 -1
- package/out/src/storage/methods/listActionsIdb.d.ts +2 -3
- package/out/src/storage/methods/listActionsIdb.d.ts.map +1 -1
- package/out/src/storage/methods/listActionsIdb.js.map +1 -1
- package/out/src/storage/methods/listActionsKnex.d.ts +2 -3
- package/out/src/storage/methods/listActionsKnex.d.ts.map +1 -1
- package/out/src/storage/methods/listActionsKnex.js.map +1 -1
- package/out/src/storage/methods/listCertificates.d.ts +3 -3
- package/out/src/storage/methods/listCertificates.d.ts.map +1 -1
- package/out/src/storage/methods/listCertificates.js.map +1 -1
- package/out/src/storage/methods/listOutputsIdb.d.ts +2 -3
- package/out/src/storage/methods/listOutputsIdb.d.ts.map +1 -1
- package/out/src/storage/methods/listOutputsIdb.js.map +1 -1
- package/out/src/storage/methods/listOutputsKnex.d.ts +2 -3
- package/out/src/storage/methods/listOutputsKnex.d.ts.map +1 -1
- package/out/src/storage/methods/listOutputsKnex.js.map +1 -1
- package/out/src/storage/methods/processAction.d.ts +2 -2
- package/out/src/storage/methods/processAction.d.ts.map +1 -1
- package/out/src/storage/methods/processAction.js +15 -10
- package/out/src/storage/methods/processAction.js.map +1 -1
- package/out/src/storage/remoting/StorageClient.d.ts +5 -6
- package/out/src/storage/remoting/StorageClient.d.ts.map +1 -1
- package/out/src/storage/remoting/StorageClient.js +22 -0
- package/out/src/storage/remoting/StorageClient.js.map +1 -1
- package/out/src/storage/remoting/StorageMobile.d.ts +5 -6
- package/out/src/storage/remoting/StorageMobile.d.ts.map +1 -1
- package/out/src/storage/remoting/StorageMobile.js.map +1 -1
- package/out/src/storage/remoting/StorageServer.d.ts +5 -0
- package/out/src/storage/remoting/StorageServer.d.ts.map +1 -1
- package/out/src/storage/remoting/StorageServer.js +38 -5
- package/out/src/storage/remoting/StorageServer.js.map +1 -1
- package/out/src/storage/remoting/__test/StorageClient.test.d.ts +2 -0
- package/out/src/storage/remoting/__test/StorageClient.test.d.ts.map +1 -0
- package/out/src/storage/remoting/__test/StorageClient.test.js +98 -0
- package/out/src/storage/remoting/__test/StorageClient.test.js.map +1 -0
- package/out/src/storage/sync/StorageMySQLDojoReader.d.ts.map +1 -1
- package/out/src/storage/sync/StorageMySQLDojoReader.js +1 -2
- package/out/src/storage/sync/StorageMySQLDojoReader.js.map +1 -1
- package/out/test/Wallet/certificate/listCertificates.test.js.map +1 -1
- package/out/test/Wallet/local/localWallet2.man.test.js.map +1 -1
- package/out/test/Wallet/signAction/mountaintop.man.test.js +2 -2
- package/out/test/Wallet/signAction/mountaintop.man.test.js.map +1 -1
- package/out/test/Wallet/support/operations.man.test.js +46 -1
- package/out/test/Wallet/support/operations.man.test.js.map +1 -1
- package/out/test/Wallet/support/reqErrorReview.2025.05.06.man.test.js.map +1 -1
- package/out/test/WalletClient/WERR.man.test.js +1 -1
- package/out/test/WalletClient/WERR.man.test.js.map +1 -1
- package/out/test/utils/localWalletMethods.d.ts.map +1 -1
- package/out/test/utils/localWalletMethods.js +2 -3
- package/out/test/utils/localWalletMethods.js.map +1 -1
- package/out/test/wallet/action/createAction.test.js +3 -0
- package/out/test/wallet/action/createAction.test.js.map +1 -1
- package/out/tsconfig.all.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/Wallet.ts +114 -79
- package/src/WalletLogger.ts +167 -0
- package/src/WalletPermissionsManager.ts +3 -5
- package/src/__tests/WalletPermissionsManager.fixtures.ts +14 -1
- package/src/__tests/WalletPermissionsManager.proxying.test.ts +89 -85
- package/src/sdk/WERR_errors.ts +6 -3
- package/src/sdk/WalletError.ts +0 -4
- package/src/sdk/WalletServices.interfaces.ts +14 -3
- package/src/sdk/WalletStorage.interfaces.ts +11 -16
- package/src/sdk/__test/validationHelpers.test.ts +4 -5
- package/src/sdk/index.ts +1 -1
- package/src/services/Services.ts +23 -5
- package/src/services/providers/WhatsOnChain.ts +2 -3
- package/src/services/providers/getBeefForTxid.ts +3 -5
- package/src/signer/methods/acquireDirectCertificate.ts +2 -3
- package/src/signer/methods/buildSignableTransaction.ts +5 -6
- package/src/signer/methods/createAction.ts +24 -18
- package/src/signer/methods/internalizeAction.ts +4 -5
- package/src/signer/methods/proveCertificate.ts +3 -4
- package/src/signer/methods/signAction.ts +6 -4
- package/src/storage/StorageIdb.ts +3 -4
- package/src/storage/StorageKnex.ts +3 -4
- package/src/storage/StorageProvider.ts +16 -20
- package/src/storage/WalletStorageManager.ts +10 -11
- package/src/storage/__test/getBeefForTransaction.test.ts +3 -4
- package/src/storage/methods/ListActionsSpecOp.ts +4 -4
- package/src/storage/methods/ListOutputsSpecOp.ts +7 -8
- package/src/storage/methods/attemptToPostReqsToNetwork.ts +15 -8
- package/src/storage/methods/createAction.ts +39 -23
- package/src/storage/methods/generateChange.ts +10 -10
- package/src/storage/methods/internalizeAction.ts +4 -4
- package/src/storage/methods/listActionsIdb.ts +3 -3
- package/src/storage/methods/listActionsKnex.ts +3 -3
- package/src/storage/methods/listCertificates.ts +7 -6
- package/src/storage/methods/listOutputsIdb.ts +2 -3
- package/src/storage/methods/listOutputsKnex.ts +2 -3
- package/src/storage/methods/processAction.ts +30 -11
- package/src/storage/remoting/StorageClient.ts +31 -12
- package/src/storage/remoting/StorageMobile.ts +6 -12
- package/src/storage/remoting/StorageServer.ts +45 -6
- package/src/storage/remoting/__test/StorageClient.test.ts +113 -0
- package/src/storage/sync/StorageMySQLDojoReader.ts +2 -3
- package/test/Wallet/certificate/listCertificates.test.ts +2 -2
- package/test/Wallet/local/localWallet2.man.test.ts +5 -5
- package/test/Wallet/signAction/mountaintop.man.test.ts +3 -2
- package/test/Wallet/support/operations.man.test.ts +65 -6
- package/test/Wallet/support/reqErrorReview.2025.05.06.man.test.ts +2 -14
- package/test/WalletClient/WERR.man.test.ts +3 -3
- package/test/utils/localWalletMethods.ts +5 -5
- package/test/wallet/action/createAction.test.ts +3 -0
- package/mobile/out/src/sdk/validationHelpers.d.ts +0 -322
- package/mobile/out/src/sdk/validationHelpers.d.ts.map +0 -1
- package/mobile/out/src/sdk/validationHelpers.js +0 -691
- package/mobile/out/src/sdk/validationHelpers.js.map +0 -1
- package/out/src/sdk/validationHelpers.d.ts +0 -322
- package/out/src/sdk/validationHelpers.d.ts.map +0 -1
- package/out/src/sdk/validationHelpers.js +0 -691
- package/out/src/sdk/validationHelpers.js.map +0 -1
- package/src/sdk/validationHelpers.ts +0 -1034
|
@@ -1,1034 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AbortActionArgs,
|
|
3
|
-
AcquireCertificateArgs,
|
|
4
|
-
AcquisitionProtocol,
|
|
5
|
-
AtomicBEEF,
|
|
6
|
-
Base64String,
|
|
7
|
-
BasketInsertion,
|
|
8
|
-
BasketStringUnder300Bytes,
|
|
9
|
-
Beef,
|
|
10
|
-
BEEF,
|
|
11
|
-
BooleanDefaultFalse,
|
|
12
|
-
BooleanDefaultTrue,
|
|
13
|
-
CertificateFieldNameUnder50Bytes,
|
|
14
|
-
CreateActionArgs,
|
|
15
|
-
CreateActionInput,
|
|
16
|
-
CreateActionOptions,
|
|
17
|
-
CreateActionOutput,
|
|
18
|
-
DescriptionString5to50Bytes,
|
|
19
|
-
DiscoverByAttributesArgs,
|
|
20
|
-
DiscoverByIdentityKeyArgs,
|
|
21
|
-
HexString,
|
|
22
|
-
InternalizeActionArgs,
|
|
23
|
-
InternalizeOutput,
|
|
24
|
-
KeyringRevealer,
|
|
25
|
-
LabelStringUnder300Bytes,
|
|
26
|
-
ListActionsArgs,
|
|
27
|
-
ListCertificatesArgs,
|
|
28
|
-
ListOutputsArgs,
|
|
29
|
-
OutpointString,
|
|
30
|
-
OutputTagStringUnder300Bytes,
|
|
31
|
-
PositiveInteger,
|
|
32
|
-
PositiveIntegerDefault10Max10000,
|
|
33
|
-
PositiveIntegerOrZero,
|
|
34
|
-
ProveCertificateArgs,
|
|
35
|
-
PubKeyHex,
|
|
36
|
-
RelinquishCertificateArgs,
|
|
37
|
-
RelinquishOutputArgs,
|
|
38
|
-
SatoshiValue,
|
|
39
|
-
SignActionArgs,
|
|
40
|
-
SignActionOptions,
|
|
41
|
-
SignActionSpend,
|
|
42
|
-
TrustSelf,
|
|
43
|
-
TXIDHexString,
|
|
44
|
-
Utils,
|
|
45
|
-
WalletPayment
|
|
46
|
-
} from '@bsv/sdk'
|
|
47
|
-
import { OutPoint, specOpThrowReviewActions } from './types'
|
|
48
|
-
import { WERR_INTERNAL, WERR_INVALID_PARAMETER } from './WERR_errors'
|
|
49
|
-
|
|
50
|
-
export function parseWalletOutpoint(outpoint: string): {
|
|
51
|
-
txid: string
|
|
52
|
-
vout: number
|
|
53
|
-
} {
|
|
54
|
-
const [txid, vout] = outpoint.split('.')
|
|
55
|
-
return { txid, vout: Number(vout) }
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function defaultTrue(v?: boolean) {
|
|
59
|
-
return v ?? true
|
|
60
|
-
}
|
|
61
|
-
function defaultFalse(v?: boolean) {
|
|
62
|
-
return v ?? false
|
|
63
|
-
}
|
|
64
|
-
function defaultZero(v?: number) {
|
|
65
|
-
return v ?? 0
|
|
66
|
-
}
|
|
67
|
-
function default0xffffffff(v?: number) {
|
|
68
|
-
return v ?? 0xffffffff
|
|
69
|
-
}
|
|
70
|
-
function defaultOne(v?: number) {
|
|
71
|
-
return v ?? 1
|
|
72
|
-
}
|
|
73
|
-
function defaultEmpty<T>(v?: T[]) {
|
|
74
|
-
return v ?? []
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function validateOptionalStringLength(
|
|
78
|
-
s: string | undefined,
|
|
79
|
-
name: string,
|
|
80
|
-
min?: number,
|
|
81
|
-
max?: number
|
|
82
|
-
): string | undefined {
|
|
83
|
-
if (s === undefined) return undefined
|
|
84
|
-
return validateStringLength(s, name, min, max)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function validateSatoshis(v: number | undefined, name: string, min?: number): number {
|
|
88
|
-
if (v === undefined || !Number.isInteger(v) || v < 0 || v > 21e14)
|
|
89
|
-
throw new WERR_INVALID_PARAMETER(name, 'a valid number of satoshis')
|
|
90
|
-
if (min !== undefined && v < min) throw new WERR_INVALID_PARAMETER(name, `at least ${min} satoshis.`)
|
|
91
|
-
return v
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export function validateOptionalInteger(
|
|
95
|
-
v: number | undefined,
|
|
96
|
-
name: string,
|
|
97
|
-
min?: number,
|
|
98
|
-
max?: number
|
|
99
|
-
): number | undefined {
|
|
100
|
-
if (v === undefined) return undefined
|
|
101
|
-
return validateInteger(v, name, undefined, min, max)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export function validateInteger(
|
|
105
|
-
v: number | undefined,
|
|
106
|
-
name: string,
|
|
107
|
-
defaultValue?: number,
|
|
108
|
-
min?: number,
|
|
109
|
-
max?: number
|
|
110
|
-
): number {
|
|
111
|
-
if (v === undefined) {
|
|
112
|
-
if (defaultValue !== undefined) return defaultValue
|
|
113
|
-
throw new WERR_INVALID_PARAMETER(name, 'a valid integer')
|
|
114
|
-
}
|
|
115
|
-
if (!Number.isInteger(v)) throw new WERR_INVALID_PARAMETER(name, 'an integer')
|
|
116
|
-
v = Number(v)
|
|
117
|
-
if (min !== undefined && v < min) throw new WERR_INVALID_PARAMETER(name, `at least ${min} length.`)
|
|
118
|
-
if (max !== undefined && v > max) throw new WERR_INVALID_PARAMETER(name, `no more than ${max} length.`)
|
|
119
|
-
return v
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export function validatePositiveIntegerOrZero(v: number, name: string): number {
|
|
123
|
-
return validateInteger(v, name, 0, 0)
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export function validateStringLength(s: string, name: string, min?: number, max?: number): string {
|
|
127
|
-
const bytes = Utils.toArray(s, 'utf8').length
|
|
128
|
-
if (min !== undefined && bytes < min) throw new WERR_INVALID_PARAMETER(name, `at least ${min} length.`)
|
|
129
|
-
if (max !== undefined && bytes > max) throw new WERR_INVALID_PARAMETER(name, `no more than ${max} length.`)
|
|
130
|
-
return s
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function validateOptionalBasket(s?: string): string | undefined {
|
|
134
|
-
if (s === undefined) return undefined
|
|
135
|
-
return validateBasket(s)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function validateBasket(s: string): string {
|
|
139
|
-
return validateIdentifier(s, 'basket', 1, 300)
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function validateLabel(s: string): string {
|
|
143
|
-
return validateIdentifier(s, 'label', 1, 300)
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function validateTag(s: string): string {
|
|
147
|
-
return validateIdentifier(s, 'tag', 1, 300)
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function validateIdentifier(s: string, name: string, min?: number, max?: number): string {
|
|
151
|
-
s = s.trim().toLowerCase()
|
|
152
|
-
const bytes = Utils.toArray(s, 'utf8').length
|
|
153
|
-
if (min !== undefined && bytes < min) throw new WERR_INVALID_PARAMETER(name, `at least ${min} length.`)
|
|
154
|
-
if (max !== undefined && bytes > max) throw new WERR_INVALID_PARAMETER(name, `no more than ${max} length.`)
|
|
155
|
-
return s
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function validateOptionalBase64String(
|
|
159
|
-
s: string | undefined,
|
|
160
|
-
name: string,
|
|
161
|
-
min?: number,
|
|
162
|
-
max?: number
|
|
163
|
-
): string | undefined {
|
|
164
|
-
if (s === undefined) return undefined
|
|
165
|
-
return validateBase64String(s, name, min, max)
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Validate a Base64 string (structure and decoded size).
|
|
170
|
-
*
|
|
171
|
-
* @param s - base64 string
|
|
172
|
-
* @param name - parameter name used in error messages
|
|
173
|
-
* @param min - optional minimum decoded byte length
|
|
174
|
-
* @param max - optional maximum decoded byte length
|
|
175
|
-
* @returns validated base64 string
|
|
176
|
-
* @throws WERR_INVALID_PARAMETER when invalid
|
|
177
|
-
*/
|
|
178
|
-
export function validateBase64String(s: string, name: string, min?: number, max?: number): string {
|
|
179
|
-
s = s.trim()
|
|
180
|
-
if (s.length === 0) {
|
|
181
|
-
throw new WERR_INVALID_PARAMETER(name, 'valid base64 string')
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
let paddingCount = 0
|
|
185
|
-
let validCharCount = 0
|
|
186
|
-
|
|
187
|
-
for (let i = 0; i < s.length; i++) {
|
|
188
|
-
const char = s.charCodeAt(i)
|
|
189
|
-
if (char >= 65 && char <= 90) continue // A-Z
|
|
190
|
-
if (char >= 97 && char <= 122) continue // a-z
|
|
191
|
-
if (char >= 48 && char <= 57) continue // 0-9
|
|
192
|
-
if (char === 43) continue // +
|
|
193
|
-
if (char === 47) continue // /
|
|
194
|
-
if (char === 61) {
|
|
195
|
-
// =
|
|
196
|
-
if (i < s.length - 2) {
|
|
197
|
-
throw new WERR_INVALID_PARAMETER(name, 'valid base64 string')
|
|
198
|
-
}
|
|
199
|
-
paddingCount++
|
|
200
|
-
continue
|
|
201
|
-
}
|
|
202
|
-
throw new WERR_INVALID_PARAMETER(name, 'valid base64 string')
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// Padding rules
|
|
206
|
-
if (paddingCount > 2) {
|
|
207
|
-
throw new WERR_INVALID_PARAMETER(name, 'valid base64 string')
|
|
208
|
-
}
|
|
209
|
-
if (paddingCount > 0 && s.length % 4 !== 0) {
|
|
210
|
-
throw new WERR_INVALID_PARAMETER(name, 'valid base64 string')
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// Length must be multiple of 4 if no padding, or valid with padding
|
|
214
|
-
const mod = s.length % 4
|
|
215
|
-
if (mod !== 0 && mod !== 4 - paddingCount) {
|
|
216
|
-
throw new WERR_INVALID_PARAMETER(name, 'valid base64 string')
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// Calculate decoded byte length: (valid chars * 6) / 8
|
|
220
|
-
const encodedLength = s.length - paddingCount
|
|
221
|
-
const bytes = Math.floor((encodedLength * 3) / 4)
|
|
222
|
-
|
|
223
|
-
if (min !== undefined && bytes < min) {
|
|
224
|
-
throw new WERR_INVALID_PARAMETER(name, `at least ${min} bytes`)
|
|
225
|
-
}
|
|
226
|
-
if (max !== undefined && bytes > max) {
|
|
227
|
-
throw new WERR_INVALID_PARAMETER(name, `no more than ${max} bytes`)
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return s
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
function validateOptionalHexString(
|
|
234
|
-
s: string | undefined,
|
|
235
|
-
name: string,
|
|
236
|
-
min?: number,
|
|
237
|
-
max?: number
|
|
238
|
-
): string | undefined {
|
|
239
|
-
if (s === undefined) return undefined
|
|
240
|
-
return validateHexString(s, name, min, max)
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* @param s
|
|
245
|
-
* @param name
|
|
246
|
-
* @param min if valid, string length minimum (not bytes)
|
|
247
|
-
* @param max if valid, string length maximum (not bytes)
|
|
248
|
-
* @returns
|
|
249
|
-
*/
|
|
250
|
-
function validateHexString(s: string, name: string, min?: number, max?: number): string {
|
|
251
|
-
s = s.trim().toLowerCase()
|
|
252
|
-
if (s.length % 2 === 1) throw new WERR_INVALID_PARAMETER(name, `even length, not ${s.length}.`)
|
|
253
|
-
const hexRegex = /^[0-9A-Fa-f]+$/
|
|
254
|
-
if (!hexRegex.test(s)) throw new WERR_INVALID_PARAMETER(name, `hexadecimal string.`)
|
|
255
|
-
if (min !== undefined && s.length < min) throw new WERR_INVALID_PARAMETER(name, `at least ${min} length.`)
|
|
256
|
-
if (max !== undefined && s.length > max) throw new WERR_INVALID_PARAMETER(name, `no more than ${max} length.`)
|
|
257
|
-
return s
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
export function isHexString(s: string): boolean {
|
|
261
|
-
s = s.trim()
|
|
262
|
-
if (s.length % 2 === 1) return false
|
|
263
|
-
const hexRegex = /^[0-9A-Fa-f]+$/
|
|
264
|
-
if (!hexRegex.test(s)) return false
|
|
265
|
-
return true
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* @typedef {string & { minLength: 5, maxLength: 2000 }} DescriptionString5to2000Bytes
|
|
270
|
-
* A string used for descriptions, with a length between 5 and 2000 characters.
|
|
271
|
-
*/
|
|
272
|
-
export type DescriptionString5to2000Bytes = string
|
|
273
|
-
|
|
274
|
-
export interface ValidWalletSignerArgs {}
|
|
275
|
-
|
|
276
|
-
export interface ValidCreateActionInput {
|
|
277
|
-
outpoint: OutPoint
|
|
278
|
-
inputDescription: DescriptionString5to2000Bytes
|
|
279
|
-
sequenceNumber: PositiveIntegerOrZero
|
|
280
|
-
unlockingScript?: HexString
|
|
281
|
-
unlockingScriptLength: PositiveInteger
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
export function validateCreateActionInput(i: CreateActionInput): ValidCreateActionInput {
|
|
285
|
-
if (i.unlockingScript === undefined && i.unlockingScriptLength === undefined)
|
|
286
|
-
throw new WERR_INVALID_PARAMETER('unlockingScript, unlockingScriptLength', `at least one valid value.`)
|
|
287
|
-
const unlockingScript = validateOptionalHexString(i.unlockingScript, 'unlockingScript')
|
|
288
|
-
const unlockingScriptLength = i.unlockingScriptLength ?? unlockingScript!.length / 2
|
|
289
|
-
if (unlockingScript && unlockingScriptLength !== unlockingScript.length / 2)
|
|
290
|
-
throw new WERR_INVALID_PARAMETER('unlockingScriptLength', `length unlockingScript if both valid.`)
|
|
291
|
-
const vi: ValidCreateActionInput = {
|
|
292
|
-
outpoint: parseWalletOutpoint(i.outpoint),
|
|
293
|
-
inputDescription: validateStringLength(i.inputDescription, 'inputDescription', 5, 2000),
|
|
294
|
-
unlockingScript,
|
|
295
|
-
unlockingScriptLength,
|
|
296
|
-
sequenceNumber: default0xffffffff(i.sequenceNumber)
|
|
297
|
-
}
|
|
298
|
-
return vi
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
export interface ValidCreateActionOutput {
|
|
302
|
-
lockingScript: HexString
|
|
303
|
-
satoshis: SatoshiValue
|
|
304
|
-
outputDescription: DescriptionString5to2000Bytes
|
|
305
|
-
basket?: BasketStringUnder300Bytes
|
|
306
|
-
customInstructions?: string
|
|
307
|
-
tags: BasketStringUnder300Bytes[]
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
export function validateCreateActionOutput(o: CreateActionOutput): ValidCreateActionOutput {
|
|
311
|
-
const vo: ValidCreateActionOutput = {
|
|
312
|
-
lockingScript: validateHexString(o.lockingScript, 'lockingScript'),
|
|
313
|
-
satoshis: validateSatoshis(o.satoshis, 'satoshis'),
|
|
314
|
-
outputDescription: validateStringLength(o.outputDescription, 'outputDescription', 5, 2000),
|
|
315
|
-
basket: validateOptionalBasket(o.basket),
|
|
316
|
-
customInstructions: o.customInstructions,
|
|
317
|
-
tags: defaultEmpty(o.tags).map(t => validateTag(t))
|
|
318
|
-
}
|
|
319
|
-
return vo
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* Set all default true/false booleans to true or false if undefined.
|
|
324
|
-
* Set all possibly undefined numbers to their default values.
|
|
325
|
-
* Set all possibly undefined arrays to empty arrays.
|
|
326
|
-
* Convert string outpoints to `{ txid: string, vout: number }`
|
|
327
|
-
*/
|
|
328
|
-
export function validateCreateActionOptions(options?: CreateActionOptions): ValidCreateActionOptions {
|
|
329
|
-
const o = options || {}
|
|
330
|
-
const vo: ValidCreateActionOptions = {
|
|
331
|
-
signAndProcess: defaultTrue(o.signAndProcess),
|
|
332
|
-
acceptDelayedBroadcast: defaultTrue(o.acceptDelayedBroadcast),
|
|
333
|
-
knownTxids: defaultEmpty(o.knownTxids),
|
|
334
|
-
returnTXIDOnly: defaultFalse(o.returnTXIDOnly),
|
|
335
|
-
noSend: defaultFalse(o.noSend),
|
|
336
|
-
noSendChange: defaultEmpty(o.noSendChange).map(nsc => parseWalletOutpoint(nsc)),
|
|
337
|
-
sendWith: defaultEmpty(o.sendWith),
|
|
338
|
-
randomizeOutputs: defaultTrue(o.randomizeOutputs)
|
|
339
|
-
}
|
|
340
|
-
return vo
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
export interface ValidProcessActionOptions {
|
|
344
|
-
acceptDelayedBroadcast: BooleanDefaultTrue
|
|
345
|
-
returnTXIDOnly: BooleanDefaultFalse
|
|
346
|
-
noSend: BooleanDefaultFalse
|
|
347
|
-
sendWith: TXIDHexString[]
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
export interface ValidCreateActionOptions extends ValidProcessActionOptions {
|
|
351
|
-
signAndProcess: boolean
|
|
352
|
-
trustSelf?: TrustSelf
|
|
353
|
-
knownTxids: TXIDHexString[]
|
|
354
|
-
noSendChange: OutPoint[]
|
|
355
|
-
randomizeOutputs: boolean
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
export interface ValidSignActionOptions extends ValidProcessActionOptions {
|
|
359
|
-
acceptDelayedBroadcast: boolean
|
|
360
|
-
returnTXIDOnly: boolean
|
|
361
|
-
noSend: boolean
|
|
362
|
-
sendWith: TXIDHexString[]
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
export interface ValidProcessActionArgs extends ValidWalletSignerArgs {
|
|
366
|
-
options: ValidProcessActionOptions
|
|
367
|
-
// true if a batch of transactions is included for processing.
|
|
368
|
-
isSendWith: boolean
|
|
369
|
-
// true if there is a new transaction (not no inputs and no outputs)
|
|
370
|
-
isNewTx: boolean
|
|
371
|
-
// true if this is a request to remix change, `isNewTx` will also be true and `isSendWith` must be false
|
|
372
|
-
isRemixChange: boolean
|
|
373
|
-
// true if any new transaction should NOT be sent to the network
|
|
374
|
-
isNoSend: boolean
|
|
375
|
-
// true if options.acceptDelayedBroadcast is true
|
|
376
|
-
isDelayed: boolean
|
|
377
|
-
// true if WERR_REVIEW_ACTIONS should be thrown to test review actions handling
|
|
378
|
-
isTestWerrReviewActions: boolean
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
export interface ValidCreateActionArgs extends ValidProcessActionArgs {
|
|
382
|
-
description: DescriptionString5to2000Bytes
|
|
383
|
-
inputBEEF?: BEEF
|
|
384
|
-
inputs: ValidCreateActionInput[]
|
|
385
|
-
outputs: ValidCreateActionOutput[]
|
|
386
|
-
lockTime: number
|
|
387
|
-
version: number
|
|
388
|
-
labels: string[]
|
|
389
|
-
|
|
390
|
-
options: ValidCreateActionOptions
|
|
391
|
-
// true if transaction creation completion will require a `signAction` call.
|
|
392
|
-
isSignAction: boolean
|
|
393
|
-
randomVals?: number[]
|
|
394
|
-
/**
|
|
395
|
-
* If true, signableTransactions will include sourceTransaction for each input,
|
|
396
|
-
* including those that do not require signature and those that were also contained
|
|
397
|
-
* in the inputBEEF.
|
|
398
|
-
*/
|
|
399
|
-
includeAllSourceTransactions: boolean
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
export interface ValidSignActionArgs extends ValidProcessActionArgs {
|
|
403
|
-
spends: Record<PositiveIntegerOrZero, SignActionSpend>
|
|
404
|
-
reference: Base64String
|
|
405
|
-
|
|
406
|
-
options: ValidSignActionOptions
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
/**
|
|
410
|
-
* Validate the arguments for creating a new action.
|
|
411
|
-
*
|
|
412
|
-
* @param args
|
|
413
|
-
* @returns validated arguments
|
|
414
|
-
* @throws primarily WERR_INVALID_PARAMETER if args are invalid.
|
|
415
|
-
*/
|
|
416
|
-
export function validateCreateActionArgs(args: CreateActionArgs): ValidCreateActionArgs {
|
|
417
|
-
const vargs: ValidCreateActionArgs = {
|
|
418
|
-
description: validateStringLength(args.description, 'description', 5, 2000),
|
|
419
|
-
inputBEEF: args.inputBEEF,
|
|
420
|
-
inputs: defaultEmpty(args.inputs).map(i => validateCreateActionInput(i)),
|
|
421
|
-
outputs: defaultEmpty(args.outputs).map(o => validateCreateActionOutput(o)),
|
|
422
|
-
lockTime: defaultZero(args.lockTime),
|
|
423
|
-
version: defaultOne(args.version),
|
|
424
|
-
labels: defaultEmpty(args.labels?.map(l => validateLabel(l))),
|
|
425
|
-
options: validateCreateActionOptions(args.options),
|
|
426
|
-
isSendWith: false,
|
|
427
|
-
isDelayed: false,
|
|
428
|
-
isNoSend: false,
|
|
429
|
-
isNewTx: false,
|
|
430
|
-
isRemixChange: false,
|
|
431
|
-
isSignAction: false,
|
|
432
|
-
randomVals: undefined,
|
|
433
|
-
includeAllSourceTransactions: false,
|
|
434
|
-
isTestWerrReviewActions: false
|
|
435
|
-
}
|
|
436
|
-
vargs.isTestWerrReviewActions = vargs.labels.indexOf(specOpThrowReviewActions) >= 0
|
|
437
|
-
vargs.isSendWith = vargs.options.sendWith.length > 0
|
|
438
|
-
vargs.isRemixChange = !vargs.isSendWith && vargs.inputs.length === 0 && vargs.outputs.length === 0
|
|
439
|
-
vargs.isNewTx = vargs.isRemixChange || vargs.inputs.length > 0 || vargs.outputs.length > 0
|
|
440
|
-
vargs.isSignAction =
|
|
441
|
-
vargs.isNewTx && (vargs.options.signAndProcess === false || vargs.inputs.some(i => i.unlockingScript === undefined))
|
|
442
|
-
vargs.isDelayed = vargs.options.acceptDelayedBroadcast
|
|
443
|
-
vargs.isNoSend = vargs.options.noSend
|
|
444
|
-
|
|
445
|
-
return vargs
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
* Set all default true/false booleans to true or false if undefined.
|
|
450
|
-
* Set all possibly undefined numbers to their default values.
|
|
451
|
-
* Set all possibly undefined arrays to empty arrays.
|
|
452
|
-
* Convert string outpoints to `{ txid: string, vout: number }`
|
|
453
|
-
*/
|
|
454
|
-
export function validateSignActionOptions(options?: SignActionOptions): ValidSignActionOptions {
|
|
455
|
-
const o = options || {}
|
|
456
|
-
const vo: ValidSignActionOptions = {
|
|
457
|
-
acceptDelayedBroadcast: defaultTrue(o.acceptDelayedBroadcast),
|
|
458
|
-
returnTXIDOnly: defaultFalse(o.returnTXIDOnly),
|
|
459
|
-
noSend: defaultFalse(o.noSend),
|
|
460
|
-
sendWith: defaultEmpty(o.sendWith)
|
|
461
|
-
}
|
|
462
|
-
return vo
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
export function validateSignActionArgs(args: SignActionArgs): ValidSignActionArgs {
|
|
466
|
-
const vargs: ValidSignActionArgs = {
|
|
467
|
-
spends: args.spends,
|
|
468
|
-
reference: args.reference,
|
|
469
|
-
options: validateSignActionOptions(args.options),
|
|
470
|
-
isSendWith: false,
|
|
471
|
-
isDelayed: false,
|
|
472
|
-
isNoSend: false,
|
|
473
|
-
isNewTx: true,
|
|
474
|
-
isRemixChange: false,
|
|
475
|
-
isTestWerrReviewActions: false
|
|
476
|
-
}
|
|
477
|
-
vargs.isSendWith = vargs.options.sendWith.length > 0
|
|
478
|
-
vargs.isDelayed = vargs.options.acceptDelayedBroadcast
|
|
479
|
-
vargs.isNoSend = vargs.options.noSend
|
|
480
|
-
|
|
481
|
-
return vargs
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
export interface ValidAbortActionArgs extends ValidWalletSignerArgs {
|
|
485
|
-
reference: Base64String
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
export function validateAbortActionArgs(args: AbortActionArgs): ValidAbortActionArgs {
|
|
489
|
-
const vargs: ValidAbortActionArgs = {
|
|
490
|
-
reference: validateBase64String(args.reference, 'reference')
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
return vargs
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
export interface ValidWalletPayment {
|
|
497
|
-
derivationPrefix: Base64String
|
|
498
|
-
derivationSuffix: Base64String
|
|
499
|
-
senderIdentityKey: PubKeyHex
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
export function validateWalletPayment(args?: WalletPayment): ValidWalletPayment | undefined {
|
|
503
|
-
if (args === undefined) return undefined
|
|
504
|
-
const v: ValidWalletPayment = {
|
|
505
|
-
derivationPrefix: validateBase64String(args.derivationPrefix, 'derivationPrefix'),
|
|
506
|
-
derivationSuffix: validateBase64String(args.derivationSuffix, 'derivationSuffix'),
|
|
507
|
-
senderIdentityKey: validateHexString(args.senderIdentityKey, 'senderIdentityKey')
|
|
508
|
-
}
|
|
509
|
-
return v
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
export interface ValidBasketInsertion {
|
|
513
|
-
basket: BasketStringUnder300Bytes
|
|
514
|
-
customInstructions?: string
|
|
515
|
-
tags: BasketStringUnder300Bytes[]
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
export function validateBasketInsertion(args?: BasketInsertion): ValidBasketInsertion | undefined {
|
|
519
|
-
if (args === undefined) return undefined
|
|
520
|
-
const v: ValidBasketInsertion = {
|
|
521
|
-
basket: validateBasket(args.basket),
|
|
522
|
-
customInstructions: validateOptionalStringLength(args.customInstructions, 'customInstructions', 0, 1000), // TODO: real max??
|
|
523
|
-
tags: defaultEmpty(args.tags).map(t => validateTag(t))
|
|
524
|
-
}
|
|
525
|
-
return v
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
export interface ValidInternalizeOutput {
|
|
529
|
-
outputIndex: PositiveIntegerOrZero
|
|
530
|
-
protocol: 'wallet payment' | 'basket insertion'
|
|
531
|
-
paymentRemittance?: ValidWalletPayment
|
|
532
|
-
insertionRemittance?: ValidBasketInsertion
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
export function validateInternalizeOutput(args: InternalizeOutput): ValidInternalizeOutput {
|
|
536
|
-
if (args.protocol !== 'basket insertion' && args.protocol !== 'wallet payment')
|
|
537
|
-
throw new WERR_INVALID_PARAMETER('protocol', `'basket insertion' or 'wallet payment'`)
|
|
538
|
-
const v: ValidInternalizeOutput = {
|
|
539
|
-
outputIndex: validatePositiveIntegerOrZero(args.outputIndex, 'outputIndex'),
|
|
540
|
-
protocol: args.protocol,
|
|
541
|
-
paymentRemittance: validateWalletPayment(args.paymentRemittance),
|
|
542
|
-
insertionRemittance: validateBasketInsertion(args.insertionRemittance)
|
|
543
|
-
}
|
|
544
|
-
return v
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
export interface ValidInternalizeActionArgs extends ValidWalletSignerArgs {
|
|
548
|
-
tx: AtomicBEEF
|
|
549
|
-
outputs: InternalizeOutput[]
|
|
550
|
-
description: DescriptionString5to2000Bytes
|
|
551
|
-
labels: LabelStringUnder300Bytes[]
|
|
552
|
-
seekPermission: BooleanDefaultTrue
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
export function validateOriginator(s?: string): string | undefined {
|
|
556
|
-
if (s === undefined) return undefined
|
|
557
|
-
s = s.trim().toLowerCase()
|
|
558
|
-
validateStringLength(s, 'originator', 1, 250)
|
|
559
|
-
const sps = s.split('.')
|
|
560
|
-
for (const sp of sps) {
|
|
561
|
-
validateStringLength(sp, 'originator part', 1, 63)
|
|
562
|
-
}
|
|
563
|
-
return s
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
export function validateInternalizeActionArgs(args: InternalizeActionArgs): ValidInternalizeActionArgs {
|
|
567
|
-
const vargs: ValidInternalizeActionArgs = {
|
|
568
|
-
tx: args.tx,
|
|
569
|
-
outputs: args.outputs.map(o => validateInternalizeOutput(o)),
|
|
570
|
-
description: validateStringLength(args.description, 'description', 5, 2000),
|
|
571
|
-
labels: (args.labels || []).map(t => validateLabel(t)),
|
|
572
|
-
seekPermission: defaultTrue(args.seekPermission)
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
try {
|
|
576
|
-
const beef = Beef.fromBinary(vargs.tx)
|
|
577
|
-
if (beef.txs.length < 1)
|
|
578
|
-
throw new WERR_INVALID_PARAMETER('tx', `at least one transaction to internalize an output from`)
|
|
579
|
-
} catch {
|
|
580
|
-
throw new WERR_INVALID_PARAMETER('tx', `valid with at least one transaction to internalize an output from`)
|
|
581
|
-
}
|
|
582
|
-
if (vargs.outputs.length < 1)
|
|
583
|
-
throw new WERR_INVALID_PARAMETER('outputs', `at least one output to internalize from the transaction`)
|
|
584
|
-
|
|
585
|
-
return vargs
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
export function validateOptionalOutpointString(outpoint: string | undefined, name: string): string | undefined {
|
|
589
|
-
if (outpoint === undefined) return undefined
|
|
590
|
-
return validateOutpointString(outpoint, name)
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
export function validateOutpointString(outpoint: string, name: string): string {
|
|
594
|
-
const s = outpoint.split('.')
|
|
595
|
-
if (s.length !== 2 || !Number.isInteger(Number(s[1])))
|
|
596
|
-
throw new WERR_INVALID_PARAMETER(name, `txid as hex string and numeric output index joined with '.'`)
|
|
597
|
-
const txid = validateHexString(s[0], `${name} txid`, undefined, 64)
|
|
598
|
-
const vout = validatePositiveIntegerOrZero(Number(s[1]), `${name} vout`)
|
|
599
|
-
return `${txid}.${vout}`
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
export interface ValidRelinquishOutputArgs extends ValidWalletSignerArgs {
|
|
603
|
-
basket: BasketStringUnder300Bytes
|
|
604
|
-
output: OutpointString
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
export function validateRelinquishOutputArgs(args: RelinquishOutputArgs): ValidRelinquishOutputArgs {
|
|
608
|
-
const vargs: ValidRelinquishOutputArgs = {
|
|
609
|
-
basket: validateBasket(args.basket),
|
|
610
|
-
output: validateOutpointString(args.output, 'output')
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
return vargs
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
export interface ValidRelinquishCertificateArgs extends ValidWalletSignerArgs {
|
|
617
|
-
type: Base64String
|
|
618
|
-
serialNumber: Base64String
|
|
619
|
-
certifier: PubKeyHex
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
export function validateRelinquishCertificateArgs(args: RelinquishCertificateArgs): ValidRelinquishCertificateArgs {
|
|
623
|
-
const vargs: ValidRelinquishCertificateArgs = {
|
|
624
|
-
type: validateBase64String(args.type, 'type'),
|
|
625
|
-
serialNumber: validateBase64String(args.serialNumber, 'serialNumber'),
|
|
626
|
-
certifier: validateHexString(args.certifier, 'certifier')
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
return vargs
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
export interface ValidListCertificatesArgs extends ValidWalletSignerArgs {
|
|
633
|
-
partial?: {
|
|
634
|
-
type?: Base64String
|
|
635
|
-
serialNumber?: Base64String
|
|
636
|
-
certifier?: PubKeyHex
|
|
637
|
-
subject?: PubKeyHex
|
|
638
|
-
revocationOutpoint?: OutpointString
|
|
639
|
-
signature?: HexString
|
|
640
|
-
}
|
|
641
|
-
certifiers: PubKeyHex[]
|
|
642
|
-
types: Base64String[]
|
|
643
|
-
limit: PositiveIntegerDefault10Max10000
|
|
644
|
-
offset: PositiveIntegerOrZero
|
|
645
|
-
privileged: BooleanDefaultFalse
|
|
646
|
-
privilegedReason?: DescriptionString5to50Bytes
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
export function validateListCertificatesArgs(args: ListCertificatesArgs): ValidListCertificatesArgs {
|
|
650
|
-
const vargs: ValidListCertificatesArgs = {
|
|
651
|
-
certifiers: defaultEmpty(args.certifiers.map(c => validateHexString(c.trim(), 'certifiers'))),
|
|
652
|
-
types: defaultEmpty(args.types.map(t => validateBase64String(t.trim(), 'types'))),
|
|
653
|
-
limit: validateInteger(args.limit, 'limit', 10, 1, 10000),
|
|
654
|
-
offset: validatePositiveIntegerOrZero(defaultZero(args.offset), 'offset'),
|
|
655
|
-
privileged: defaultFalse(args.privileged),
|
|
656
|
-
privilegedReason: validateOptionalStringLength(args.privilegedReason, 'privilegedReason', 5, 50),
|
|
657
|
-
partial: undefined
|
|
658
|
-
}
|
|
659
|
-
return vargs
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
export interface ValidAcquireCertificateArgs extends ValidWalletSignerArgs {
|
|
663
|
-
acquisitionProtocol: AcquisitionProtocol
|
|
664
|
-
|
|
665
|
-
type: Base64String
|
|
666
|
-
serialNumber?: Base64String
|
|
667
|
-
certifier: PubKeyHex
|
|
668
|
-
revocationOutpoint?: OutpointString
|
|
669
|
-
fields: Record<CertificateFieldNameUnder50Bytes, string>
|
|
670
|
-
signature?: HexString
|
|
671
|
-
|
|
672
|
-
certifierUrl?: string
|
|
673
|
-
|
|
674
|
-
keyringRevealer?: KeyringRevealer
|
|
675
|
-
keyringForSubject?: Record<CertificateFieldNameUnder50Bytes, Base64String>
|
|
676
|
-
|
|
677
|
-
privileged: boolean
|
|
678
|
-
privilegedReason?: DescriptionString5to50Bytes
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
function validateCertificateFields(
|
|
682
|
-
fields: Record<CertificateFieldNameUnder50Bytes, string>
|
|
683
|
-
): Record<CertificateFieldNameUnder50Bytes, string> {
|
|
684
|
-
for (const fieldName of Object.keys(fields)) {
|
|
685
|
-
validateStringLength(fieldName, 'field name', 1, 50)
|
|
686
|
-
}
|
|
687
|
-
return fields
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
function validateKeyringRevealer(kr: KeyringRevealer, name: string): KeyringRevealer {
|
|
691
|
-
if (kr === 'certifier') return kr
|
|
692
|
-
return validateHexString(kr, name)
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
function validateOptionalKeyringRevealer(kr: KeyringRevealer | undefined, name: string): KeyringRevealer | undefined {
|
|
696
|
-
if (kr === undefined) return undefined
|
|
697
|
-
return validateKeyringRevealer(kr, name)
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
function validateKeyringForSubject(
|
|
701
|
-
kr: Record<CertificateFieldNameUnder50Bytes, Base64String>,
|
|
702
|
-
name: string
|
|
703
|
-
): Record<CertificateFieldNameUnder50Bytes, Base64String> {
|
|
704
|
-
for (const fn of Object.keys(kr)) {
|
|
705
|
-
validateStringLength(fn, `${name} field name`, 1, 50)
|
|
706
|
-
validateBase64String(kr[fn], `${name} field value`)
|
|
707
|
-
}
|
|
708
|
-
return kr
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
function validateOptionalKeyringForSubject(
|
|
712
|
-
kr: Record<CertificateFieldNameUnder50Bytes, Base64String> | undefined,
|
|
713
|
-
name: string
|
|
714
|
-
): Record<CertificateFieldNameUnder50Bytes, Base64String> | undefined {
|
|
715
|
-
if (kr === undefined) return undefined
|
|
716
|
-
return validateKeyringForSubject(kr, name)
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
/**
|
|
720
|
-
*
|
|
721
|
-
* @param args
|
|
722
|
-
* @param subject Must be valid for "direct" `acquisitionProtocol`. public key of the certificate subject.
|
|
723
|
-
* @returns
|
|
724
|
-
*/
|
|
725
|
-
export async function validateAcquireCertificateArgs(
|
|
726
|
-
args: AcquireCertificateArgs
|
|
727
|
-
): Promise<ValidAcquireCertificateArgs> {
|
|
728
|
-
const vargs: ValidAcquireCertificateArgs = {
|
|
729
|
-
acquisitionProtocol: args.acquisitionProtocol,
|
|
730
|
-
type: validateBase64String(args.type, 'type'),
|
|
731
|
-
serialNumber: validateOptionalBase64String(args.serialNumber, 'serialNumber'),
|
|
732
|
-
certifier: validateHexString(args.certifier, 'certifier'),
|
|
733
|
-
revocationOutpoint: validateOptionalOutpointString(args.revocationOutpoint, 'revocationOutpoint'),
|
|
734
|
-
fields: validateCertificateFields(args.fields),
|
|
735
|
-
signature: validateOptionalHexString(args.signature, 'signature'),
|
|
736
|
-
certifierUrl: args.certifierUrl,
|
|
737
|
-
keyringRevealer: validateOptionalKeyringRevealer(args.keyringRevealer, 'keyringRevealer'),
|
|
738
|
-
keyringForSubject: validateOptionalKeyringForSubject(args.keyringForSubject, 'keyringForSubject'),
|
|
739
|
-
privileged: defaultFalse(args.privileged),
|
|
740
|
-
privilegedReason: validateOptionalStringLength(args.privilegedReason, 'privilegedReason', 5, 50)
|
|
741
|
-
}
|
|
742
|
-
if (vargs.privileged && !vargs.privilegedReason)
|
|
743
|
-
throw new WERR_INVALID_PARAMETER('privilegedReason', `valid when 'privileged' is true `)
|
|
744
|
-
if (vargs.acquisitionProtocol === 'direct') {
|
|
745
|
-
if (!vargs.serialNumber)
|
|
746
|
-
throw new WERR_INVALID_PARAMETER('serialNumber', 'valid when acquisitionProtocol is "direct"')
|
|
747
|
-
if (!vargs.signature) throw new WERR_INVALID_PARAMETER('signature', 'valid when acquisitionProtocol is "direct"')
|
|
748
|
-
if (!vargs.revocationOutpoint)
|
|
749
|
-
throw new WERR_INVALID_PARAMETER('revocationOutpoint', 'valid when acquisitionProtocol is "direct"')
|
|
750
|
-
}
|
|
751
|
-
return vargs
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
export interface ValidAcquireDirectCertificateArgs extends ValidWalletSignerArgs {
|
|
755
|
-
type: Base64String
|
|
756
|
-
serialNumber: Base64String
|
|
757
|
-
certifier: PubKeyHex
|
|
758
|
-
revocationOutpoint: OutpointString
|
|
759
|
-
fields: Record<CertificateFieldNameUnder50Bytes, string>
|
|
760
|
-
signature: HexString
|
|
761
|
-
|
|
762
|
-
/**
|
|
763
|
-
* validated to an empty string, must be provided by wallet and must
|
|
764
|
-
* match expectations of keyringForSubject
|
|
765
|
-
*/
|
|
766
|
-
subject: PubKeyHex
|
|
767
|
-
|
|
768
|
-
keyringRevealer: KeyringRevealer
|
|
769
|
-
keyringForSubject: Record<CertificateFieldNameUnder50Bytes, Base64String>
|
|
770
|
-
|
|
771
|
-
privileged: boolean
|
|
772
|
-
privilegedReason?: DescriptionString5to50Bytes
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
export interface ValidAcquireIssuanceCertificateArgs extends ValidWalletSignerArgs {
|
|
776
|
-
type: Base64String
|
|
777
|
-
certifier: PubKeyHex
|
|
778
|
-
certifierUrl: string
|
|
779
|
-
fields: Record<CertificateFieldNameUnder50Bytes, string>
|
|
780
|
-
|
|
781
|
-
/**
|
|
782
|
-
* validated to an empty string, must be provided by wallet and must
|
|
783
|
-
* match expectations of keyringForSubject
|
|
784
|
-
*/
|
|
785
|
-
subject: PubKeyHex
|
|
786
|
-
|
|
787
|
-
privileged: boolean
|
|
788
|
-
privilegedReason?: DescriptionString5to50Bytes
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
export function validateAcquireIssuanceCertificateArgs(
|
|
792
|
-
args: AcquireCertificateArgs
|
|
793
|
-
): ValidAcquireIssuanceCertificateArgs {
|
|
794
|
-
if (args.acquisitionProtocol !== 'issuance')
|
|
795
|
-
throw new WERR_INTERNAL('Only acquire certificate via issuance requests allowed here.')
|
|
796
|
-
if (args.serialNumber) throw new WERR_INVALID_PARAMETER('serialNumber', 'valid when acquisitionProtocol is "direct"')
|
|
797
|
-
if (args.signature) throw new WERR_INVALID_PARAMETER('signature', 'valid when acquisitionProtocol is "direct"')
|
|
798
|
-
if (args.revocationOutpoint)
|
|
799
|
-
throw new WERR_INVALID_PARAMETER('revocationOutpoint', 'valid when acquisitionProtocol is "direct"')
|
|
800
|
-
if (args.keyringRevealer)
|
|
801
|
-
throw new WERR_INVALID_PARAMETER('keyringRevealer', 'valid when acquisitionProtocol is "direct"')
|
|
802
|
-
if (args.keyringForSubject)
|
|
803
|
-
throw new WERR_INVALID_PARAMETER('keyringForSubject', 'valid when acquisitionProtocol is "direct"')
|
|
804
|
-
if (!args.certifierUrl)
|
|
805
|
-
throw new WERR_INVALID_PARAMETER('certifierUrl', 'valid when acquisitionProtocol is "issuance"')
|
|
806
|
-
if (args.privileged && !args.privilegedReason)
|
|
807
|
-
throw new WERR_INVALID_PARAMETER('privilegedReason', `valid when 'privileged' is true `)
|
|
808
|
-
|
|
809
|
-
const vargs: ValidAcquireIssuanceCertificateArgs = {
|
|
810
|
-
type: validateBase64String(args.type, 'type'),
|
|
811
|
-
certifier: validateHexString(args.certifier, 'certifier'),
|
|
812
|
-
certifierUrl: args.certifierUrl,
|
|
813
|
-
fields: validateCertificateFields(args.fields),
|
|
814
|
-
privileged: defaultFalse(args.privileged),
|
|
815
|
-
privilegedReason: validateOptionalStringLength(args.privilegedReason, 'privilegedReason', 5, 50),
|
|
816
|
-
subject: ''
|
|
817
|
-
}
|
|
818
|
-
return vargs
|
|
819
|
-
}
|
|
820
|
-
export function validateAcquireDirectCertificateArgs(args: AcquireCertificateArgs): ValidAcquireDirectCertificateArgs {
|
|
821
|
-
if (args.acquisitionProtocol !== 'direct')
|
|
822
|
-
throw new WERR_INTERNAL('Only acquire direct certificate requests allowed here.')
|
|
823
|
-
if (!args.serialNumber) throw new WERR_INVALID_PARAMETER('serialNumber', 'valid when acquisitionProtocol is "direct"')
|
|
824
|
-
if (!args.signature) throw new WERR_INVALID_PARAMETER('signature', 'valid when acquisitionProtocol is "direct"')
|
|
825
|
-
if (!args.revocationOutpoint)
|
|
826
|
-
throw new WERR_INVALID_PARAMETER('revocationOutpoint', 'valid when acquisitionProtocol is "direct"')
|
|
827
|
-
if (!args.keyringRevealer)
|
|
828
|
-
throw new WERR_INVALID_PARAMETER('keyringRevealer', 'valid when acquisitionProtocol is "direct"')
|
|
829
|
-
if (!args.keyringForSubject)
|
|
830
|
-
throw new WERR_INVALID_PARAMETER('keyringForSubject', 'valid when acquisitionProtocol is "direct"')
|
|
831
|
-
if (args.privileged && !args.privilegedReason)
|
|
832
|
-
throw new WERR_INVALID_PARAMETER('privilegedReason', `valid when 'privileged' is true `)
|
|
833
|
-
|
|
834
|
-
const vargs: ValidAcquireDirectCertificateArgs = {
|
|
835
|
-
type: validateBase64String(args.type, 'type'),
|
|
836
|
-
serialNumber: validateBase64String(args.serialNumber, 'serialNumber'),
|
|
837
|
-
certifier: validateHexString(args.certifier, 'certifier'),
|
|
838
|
-
revocationOutpoint: validateOutpointString(args.revocationOutpoint, 'revocationOutpoint'),
|
|
839
|
-
fields: validateCertificateFields(args.fields),
|
|
840
|
-
signature: validateHexString(args.signature, 'signature'),
|
|
841
|
-
keyringRevealer: validateKeyringRevealer(args.keyringRevealer, 'keyringRevealer'),
|
|
842
|
-
keyringForSubject: validateKeyringForSubject(args.keyringForSubject, 'keyringForSubject'),
|
|
843
|
-
privileged: defaultFalse(args.privileged),
|
|
844
|
-
privilegedReason: validateOptionalStringLength(args.privilegedReason, 'privilegedReason', 5, 50),
|
|
845
|
-
subject: ''
|
|
846
|
-
}
|
|
847
|
-
return vargs
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
export interface ValidProveCertificateArgs extends ValidWalletSignerArgs {
|
|
851
|
-
type?: Base64String
|
|
852
|
-
serialNumber?: Base64String
|
|
853
|
-
certifier?: PubKeyHex
|
|
854
|
-
subject?: PubKeyHex
|
|
855
|
-
revocationOutpoint?: OutpointString
|
|
856
|
-
signature?: HexString
|
|
857
|
-
|
|
858
|
-
fieldsToReveal: CertificateFieldNameUnder50Bytes[]
|
|
859
|
-
verifier: PubKeyHex
|
|
860
|
-
privileged: boolean
|
|
861
|
-
privilegedReason?: DescriptionString5to50Bytes
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
export function validateProveCertificateArgs(args: ProveCertificateArgs): ValidProveCertificateArgs {
|
|
865
|
-
if (args.privileged && !args.privilegedReason)
|
|
866
|
-
throw new WERR_INVALID_PARAMETER('privilegedReason', `valid when 'privileged' is true `)
|
|
867
|
-
|
|
868
|
-
const vargs: ValidProveCertificateArgs = {
|
|
869
|
-
type: validateOptionalBase64String(args.certificate.type, 'certificate.type'),
|
|
870
|
-
serialNumber: validateOptionalBase64String(args.certificate.serialNumber, 'certificate.serialNumber'),
|
|
871
|
-
certifier: validateOptionalHexString(args.certificate.certifier, 'certificate.certifier'),
|
|
872
|
-
subject: validateOptionalHexString(args.certificate.subject, 'certificate.subject'),
|
|
873
|
-
revocationOutpoint: validateOptionalOutpointString(
|
|
874
|
-
args.certificate.revocationOutpoint,
|
|
875
|
-
'certificate.revocationOutpoint'
|
|
876
|
-
),
|
|
877
|
-
signature: validateOptionalHexString(args.certificate.signature, 'certificate.signature'),
|
|
878
|
-
fieldsToReveal: defaultEmpty(args.fieldsToReveal).map(fieldName =>
|
|
879
|
-
validateStringLength(fieldName, `fieldsToReveal ${fieldName}`, 1, 50)
|
|
880
|
-
),
|
|
881
|
-
verifier: validateHexString(args.verifier, 'verifier'),
|
|
882
|
-
privileged: defaultFalse(args.privileged),
|
|
883
|
-
privilegedReason: validateOptionalStringLength(args.privilegedReason, 'privilegedReason', 5, 50)
|
|
884
|
-
}
|
|
885
|
-
return vargs
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
export interface ValidDiscoverByIdentityKeyArgs extends ValidWalletSignerArgs {
|
|
889
|
-
identityKey: PubKeyHex
|
|
890
|
-
limit: PositiveIntegerDefault10Max10000
|
|
891
|
-
offset: PositiveIntegerOrZero
|
|
892
|
-
seekPermission: boolean
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
export function validateDiscoverByIdentityKeyArgs(args: DiscoverByIdentityKeyArgs): ValidDiscoverByIdentityKeyArgs {
|
|
896
|
-
const vargs: ValidDiscoverByIdentityKeyArgs = {
|
|
897
|
-
identityKey: validateHexString(args.identityKey, 'identityKey', 66, 66),
|
|
898
|
-
limit: validateInteger(args.limit, 'limit', 10, 1, 10000),
|
|
899
|
-
offset: validatePositiveIntegerOrZero(defaultZero(args.offset), 'offset'),
|
|
900
|
-
seekPermission: defaultFalse(args.seekPermission)
|
|
901
|
-
}
|
|
902
|
-
return vargs
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
export interface ValidDiscoverByAttributesArgs extends ValidWalletSignerArgs {
|
|
906
|
-
attributes: Record<CertificateFieldNameUnder50Bytes, string>
|
|
907
|
-
limit: PositiveIntegerDefault10Max10000
|
|
908
|
-
offset: PositiveIntegerOrZero
|
|
909
|
-
seekPermission: boolean
|
|
910
|
-
}
|
|
911
|
-
|
|
912
|
-
function validateAttributes(
|
|
913
|
-
attributes: Record<CertificateFieldNameUnder50Bytes, string>
|
|
914
|
-
): Record<CertificateFieldNameUnder50Bytes, string> {
|
|
915
|
-
for (const fieldName of Object.keys(attributes)) {
|
|
916
|
-
validateStringLength(fieldName, `field name ${fieldName}`, 1, 50)
|
|
917
|
-
}
|
|
918
|
-
return attributes
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
export function validateDiscoverByAttributesArgs(args: DiscoverByAttributesArgs): ValidDiscoverByAttributesArgs {
|
|
922
|
-
const vargs: ValidDiscoverByAttributesArgs = {
|
|
923
|
-
attributes: validateAttributes(args.attributes),
|
|
924
|
-
limit: validateInteger(args.limit, 'limit', 10, 1, 10000),
|
|
925
|
-
offset: validatePositiveIntegerOrZero(defaultZero(args.offset), 'offset'),
|
|
926
|
-
seekPermission: defaultFalse(args.seekPermission)
|
|
927
|
-
}
|
|
928
|
-
return vargs
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
export interface ValidListOutputsArgs extends ValidWalletSignerArgs {
|
|
932
|
-
basket: BasketStringUnder300Bytes
|
|
933
|
-
tags: OutputTagStringUnder300Bytes[]
|
|
934
|
-
tagQueryMode: 'all' | 'any'
|
|
935
|
-
includeLockingScripts: boolean
|
|
936
|
-
includeTransactions: boolean
|
|
937
|
-
includeCustomInstructions: BooleanDefaultFalse
|
|
938
|
-
includeTags: BooleanDefaultFalse
|
|
939
|
-
includeLabels: BooleanDefaultFalse
|
|
940
|
-
limit: PositiveIntegerDefault10Max10000
|
|
941
|
-
offset: number
|
|
942
|
-
seekPermission: BooleanDefaultTrue
|
|
943
|
-
knownTxids: string[]
|
|
944
|
-
}
|
|
945
|
-
|
|
946
|
-
/**
|
|
947
|
-
* @param {BasketStringUnder300Bytes} args.basket - Required. The associated basket name whose outputs should be listed.
|
|
948
|
-
* @param {OutputTagStringUnder300Bytes[]} [args.tags] - Optional. Filter outputs based on these tags.
|
|
949
|
-
* @param {'all' | 'any'} [args.tagQueryMode] - Optional. Filter mode, defining whether all or any of the tags must match. By default, any tag can match.
|
|
950
|
-
* @param {'locking scripts' | 'entire transactions'} [args.include] - Optional. Whether to include locking scripts (with each output) or entire transactions (as aggregated BEEF, at the top level) in the result. By default, unless specified, neither are returned.
|
|
951
|
-
* @param {BooleanDefaultFalse} [args.includeEntireTransactions] - Optional. Whether to include the entire transaction(s) in the result.
|
|
952
|
-
* @param {BooleanDefaultFalse} [args.includeCustomInstructions] - Optional. Whether custom instructions should be returned in the result.
|
|
953
|
-
* @param {BooleanDefaultFalse} [args.includeTags] - Optional. Whether the tags associated with the output should be returned.
|
|
954
|
-
* @param {BooleanDefaultFalse} [args.includeLabels] - Optional. Whether the labels associated with the transaction containing the output should be returned.
|
|
955
|
-
* @param {PositiveIntegerDefault10Max10000} [args.limit] - Optional limit on the number of outputs to return.
|
|
956
|
-
* @param {number} [args.offset] - If positive or zero: Number of outputs to skip before starting to return results, oldest first.
|
|
957
|
-
* If negative: Outputs are returned newest first and offset of -1 is the newest output.
|
|
958
|
-
* When using negative offsets, caution is required as new outputs may be added between calls,
|
|
959
|
-
* potentially causing outputs to be duplicated across calls.
|
|
960
|
-
* @param {BooleanDefaultTrue} [args.seekPermission] — Optional. Whether to seek permission from the user for this operation if required. Default true, will return an error rather than proceed if set to false.
|
|
961
|
-
*/
|
|
962
|
-
export function validateListOutputsArgs(args: ListOutputsArgs): ValidListOutputsArgs {
|
|
963
|
-
let tagQueryMode: 'any' | 'all'
|
|
964
|
-
if (args.tagQueryMode === undefined || args.tagQueryMode === 'any') tagQueryMode = 'any'
|
|
965
|
-
else if (args.tagQueryMode === 'all') tagQueryMode = 'all'
|
|
966
|
-
else throw new WERR_INVALID_PARAMETER('tagQueryMode', `undefined, 'any', or 'all'`)
|
|
967
|
-
|
|
968
|
-
const vargs: ValidListOutputsArgs = {
|
|
969
|
-
basket: validateStringLength(args.basket, 'basket', 1, 300),
|
|
970
|
-
tags: (args.tags || []).map(t => validateStringLength(t, 'tag', 1, 300)),
|
|
971
|
-
tagQueryMode,
|
|
972
|
-
includeLockingScripts: args.include === 'locking scripts',
|
|
973
|
-
includeTransactions: args.include === 'entire transactions',
|
|
974
|
-
includeCustomInstructions: defaultFalse(args.includeCustomInstructions),
|
|
975
|
-
includeTags: defaultFalse(args.includeTags),
|
|
976
|
-
includeLabels: defaultFalse(args.includeLabels),
|
|
977
|
-
limit: validateInteger(args.limit, 'limit', 10, 1, 10000),
|
|
978
|
-
offset: validateInteger(args.offset, 'offset', 0, undefined, undefined),
|
|
979
|
-
seekPermission: defaultTrue(args.seekPermission),
|
|
980
|
-
knownTxids: []
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
return vargs
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
export interface ValidListActionsArgs extends ValidWalletSignerArgs {
|
|
987
|
-
labels: LabelStringUnder300Bytes[]
|
|
988
|
-
labelQueryMode: 'any' | 'all'
|
|
989
|
-
includeLabels: BooleanDefaultFalse
|
|
990
|
-
includeInputs: BooleanDefaultFalse
|
|
991
|
-
includeInputSourceLockingScripts: BooleanDefaultFalse
|
|
992
|
-
includeInputUnlockingScripts: BooleanDefaultFalse
|
|
993
|
-
includeOutputs: BooleanDefaultFalse
|
|
994
|
-
includeOutputLockingScripts: BooleanDefaultFalse
|
|
995
|
-
limit: PositiveIntegerDefault10Max10000
|
|
996
|
-
offset: PositiveIntegerOrZero
|
|
997
|
-
seekPermission: BooleanDefaultTrue
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
|
-
/**
|
|
1001
|
-
* @param {LabelStringUnder300Bytes[]} args.labels - An array of labels used to filter actions.
|
|
1002
|
-
* @param {'any' | 'all'} [args.labelQueryMode] - Optional. Specifies how to match labels (default is any which matches any of the labels).
|
|
1003
|
-
* @param {BooleanDefaultFalse} [args.includeLabels] - Optional. Whether to include transaction labels in the result set.
|
|
1004
|
-
* @param {BooleanDefaultFalse} [args.includeInputs] - Optional. Whether to include input details in the result set.
|
|
1005
|
-
* @param {BooleanDefaultFalse} [args.includeInputSourceLockingScripts] - Optional. Whether to include input source locking scripts in the result set.
|
|
1006
|
-
* @param {BooleanDefaultFalse} [args.includeInputUnlockingScripts] - Optional. Whether to include input unlocking scripts in the result set.
|
|
1007
|
-
* @param {BooleanDefaultFalse} [args.includeOutputs] - Optional. Whether to include output details in the result set.
|
|
1008
|
-
* @param {BooleanDefaultFalse} [args.includeOutputLockingScripts] - Optional. Whether to include output locking scripts in the result set.
|
|
1009
|
-
* @param {PositiveIntegerDefault10Max10000} [args.limit] - Optional. The maximum number of transactions to retrieve.
|
|
1010
|
-
* @param {PositiveIntegerOrZero} [args.offset] - Optional. Number of transactions to skip before starting to return the results.
|
|
1011
|
-
* @param {BooleanDefaultTrue} [args.seekPermission] — Optional. Whether to seek permission from the user for this operation if required. Default true, will return an error rather than proceed if set to false.
|
|
1012
|
-
*/
|
|
1013
|
-
export function validateListActionsArgs(args: ListActionsArgs): ValidListActionsArgs {
|
|
1014
|
-
let labelQueryMode: 'any' | 'all'
|
|
1015
|
-
if (args.labelQueryMode === undefined || args.labelQueryMode === 'any') labelQueryMode = 'any'
|
|
1016
|
-
else if (args.labelQueryMode === 'all') labelQueryMode = 'all'
|
|
1017
|
-
else throw new WERR_INVALID_PARAMETER('labelQueryMode', `undefined, 'any', or 'all'`)
|
|
1018
|
-
|
|
1019
|
-
const vargs: ValidListActionsArgs = {
|
|
1020
|
-
labels: (args.labels || []).map(t => validateLabel(t)),
|
|
1021
|
-
labelQueryMode,
|
|
1022
|
-
includeLabels: defaultFalse(args.includeLabels),
|
|
1023
|
-
includeInputs: defaultFalse(args.includeInputs),
|
|
1024
|
-
includeInputSourceLockingScripts: defaultFalse(args.includeInputSourceLockingScripts),
|
|
1025
|
-
includeInputUnlockingScripts: defaultFalse(args.includeInputUnlockingScripts),
|
|
1026
|
-
includeOutputs: defaultFalse(args.includeOutputs),
|
|
1027
|
-
includeOutputLockingScripts: defaultFalse(args.includeOutputLockingScripts),
|
|
1028
|
-
limit: validateInteger(args.limit, 'limit', 10, 1, 10000),
|
|
1029
|
-
offset: validateInteger(args.offset, 'offset', 0, 0),
|
|
1030
|
-
seekPermission: defaultTrue(args.seekPermission)
|
|
1031
|
-
}
|
|
1032
|
-
|
|
1033
|
-
return vargs
|
|
1034
|
-
}
|