@arkade-os/sdk 0.4.27 → 0.4.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -100
- package/dist/adapters/asyncStorage.cjs +48 -0
- package/dist/adapters/asyncStorage.cjs.map +1 -0
- package/dist/adapters/asyncStorage.d.cts +16 -0
- package/dist/{types/storage → adapters}/asyncStorage.d.ts +5 -2
- package/dist/adapters/asyncStorage.js +46 -0
- package/dist/adapters/asyncStorage.js.map +1 -0
- package/dist/adapters/expo.cjs +19 -0
- package/dist/adapters/expo.cjs.map +1 -0
- package/dist/adapters/expo.d.cts +48 -0
- package/dist/adapters/expo.d.ts +48 -0
- package/dist/adapters/expo.js +6 -0
- package/dist/adapters/expo.js.map +1 -0
- package/dist/adapters/fileSystem.cjs +116 -0
- package/dist/adapters/fileSystem.cjs.map +1 -0
- package/dist/adapters/fileSystem.d.cts +17 -0
- package/dist/{types/storage → adapters}/fileSystem.d.ts +5 -2
- package/dist/adapters/fileSystem.js +93 -0
- package/dist/adapters/fileSystem.js.map +1 -0
- package/dist/adapters/indexedDB.cjs +103 -0
- package/dist/adapters/indexedDB.cjs.map +1 -0
- package/dist/adapters/indexedDB.d.cts +18 -0
- package/dist/{types/storage → adapters}/indexedDB.d.ts +5 -2
- package/dist/adapters/indexedDB.js +101 -0
- package/dist/adapters/indexedDB.js.map +1 -0
- package/dist/adapters/localStorage.cjs +50 -0
- package/dist/adapters/localStorage.cjs.map +1 -0
- package/dist/{types/storage/inMemory.d.ts → adapters/localStorage.d.cts} +6 -3
- package/dist/{types/storage → adapters}/localStorage.d.ts +5 -2
- package/dist/adapters/localStorage.js +48 -0
- package/dist/adapters/localStorage.js.map +1 -0
- package/dist/ark-TZ1gXAXU.d.cts +3880 -0
- package/dist/ark-TZ1gXAXU.d.ts +3880 -0
- package/dist/{types/worker/expo/asyncStorageTaskQueue.d.ts → asyncStorageTaskQueue-Cb1F_Z9s.d.ts} +6 -3
- package/dist/asyncStorageTaskQueue-EFqSmYTg.d.cts +49 -0
- package/dist/chunk-5BLDMQED.cjs +18 -0
- package/dist/chunk-5BLDMQED.cjs.map +1 -0
- package/dist/chunk-5PG7DV7A.cjs +805 -0
- package/dist/chunk-5PG7DV7A.cjs.map +1 -0
- package/dist/chunk-A3EMF7RN.js +95 -0
- package/dist/chunk-A3EMF7RN.js.map +1 -0
- package/dist/chunk-ADV27S4N.cjs +2701 -0
- package/dist/chunk-ADV27S4N.cjs.map +1 -0
- package/dist/chunk-BQLHADL7.js +13805 -0
- package/dist/chunk-BQLHADL7.js.map +1 -0
- package/dist/chunk-CFZMTDWI.js +209 -0
- package/dist/chunk-CFZMTDWI.js.map +1 -0
- package/dist/chunk-FG5ACJJW.cjs +212 -0
- package/dist/chunk-FG5ACJJW.cjs.map +1 -0
- package/dist/chunk-HW3JJ323.js +768 -0
- package/dist/chunk-HW3JJ323.js.map +1 -0
- package/dist/chunk-I3DGUUCT.cjs +838 -0
- package/dist/chunk-I3DGUUCT.cjs.map +1 -0
- package/dist/chunk-IPX2R7FR.cjs +100 -0
- package/dist/chunk-IPX2R7FR.cjs.map +1 -0
- package/dist/chunk-NSBPE2FW.js +15 -0
- package/dist/chunk-NSBPE2FW.js.map +1 -0
- package/dist/chunk-T64LAI7L.js +829 -0
- package/dist/chunk-T64LAI7L.js.map +1 -0
- package/dist/chunk-ZBUDLTBO.js +2671 -0
- package/dist/chunk-ZBUDLTBO.js.map +1 -0
- package/dist/chunk-ZLO6NETT.cjs +13910 -0
- package/dist/chunk-ZLO6NETT.cjs.map +1 -0
- package/dist/contracts/handlers/index.cjs +26 -0
- package/dist/contracts/handlers/index.cjs.map +1 -0
- package/dist/contracts/handlers/index.d.cts +7 -0
- package/dist/contracts/handlers/index.d.ts +7 -0
- package/dist/contracts/handlers/index.js +5 -0
- package/dist/contracts/handlers/index.js.map +1 -0
- package/dist/delegate-BFZs69hp.d.cts +84 -0
- package/dist/delegate-aaVGfWsV.d.ts +84 -0
- package/dist/index-B22cA64m.d.cts +199 -0
- package/dist/{types/storage/index.d.ts → index-C0IanN1m.d.cts} +3 -1
- package/dist/index-C0IanN1m.d.ts +11 -0
- package/dist/index-NDla_UoJ.d.ts +199 -0
- package/dist/index.cjs +480 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3343 -0
- package/dist/index.d.ts +3343 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/repositories/realm/index.cjs +513 -0
- package/dist/repositories/realm/index.cjs.map +1 -0
- package/dist/repositories/realm/index.d.cts +217 -0
- package/dist/{types/repositories/realm/schemas.d.ts → repositories/realm/index.d.ts} +80 -112
- package/dist/repositories/realm/index.js +507 -0
- package/dist/repositories/realm/index.js.map +1 -0
- package/dist/repositories/sqlite/index.cjs +588 -0
- package/dist/repositories/sqlite/index.cjs.map +1 -0
- package/dist/repositories/sqlite/index.d.cts +118 -0
- package/dist/{types/repositories/sqlite/walletRepository.d.ts → repositories/sqlite/index.d.ts} +58 -5
- package/dist/repositories/sqlite/index.js +585 -0
- package/dist/repositories/sqlite/index.js.map +1 -0
- package/dist/taskRunner-C6Ff4OaU.d.cts +114 -0
- package/dist/taskRunner-yvPN8Z0K.d.ts +114 -0
- package/dist/wallet/expo/background.cjs +93 -0
- package/dist/wallet/expo/background.cjs.map +1 -0
- package/dist/wallet/expo/background.d.cts +84 -0
- package/dist/wallet/expo/background.d.ts +84 -0
- package/dist/wallet/expo/background.js +68 -0
- package/dist/wallet/expo/background.js.map +1 -0
- package/dist/wallet/expo/index.cjs +171 -0
- package/dist/wallet/expo/index.cjs.map +1 -0
- package/dist/wallet/expo/index.d.cts +122 -0
- package/dist/{types/wallet/expo/wallet.d.ts → wallet/expo/index.d.ts} +45 -22
- package/dist/wallet/expo/index.js +169 -0
- package/dist/wallet/expo/index.js.map +1 -0
- package/dist/wallet-AF-p-OWj.d.cts +774 -0
- package/dist/wallet-D9NBRqvC.d.ts +774 -0
- package/dist/worker/expo/index.cjs +140 -0
- package/dist/worker/expo/index.cjs.map +1 -0
- package/dist/worker/expo/index.d.cts +29 -0
- package/dist/worker/expo/index.d.ts +29 -0
- package/dist/worker/expo/index.js +121 -0
- package/dist/worker/expo/index.js.map +1 -0
- package/package.json +110 -76
- package/dist/cjs/adapters/asyncStorage.js +0 -5
- package/dist/cjs/adapters/expo.js +0 -8
- package/dist/cjs/adapters/fileSystem.js +0 -5
- package/dist/cjs/adapters/indexedDB.js +0 -5
- package/dist/cjs/adapters/localStorage.js +0 -5
- package/dist/cjs/arkfee/celenv.js +0 -43
- package/dist/cjs/arkfee/estimator.js +0 -143
- package/dist/cjs/arkfee/index.js +0 -5
- package/dist/cjs/arkfee/types.js +0 -26
- package/dist/cjs/arknote/index.js +0 -128
- package/dist/cjs/bip322/index.js +0 -270
- package/dist/cjs/contracts/arkcontract.js +0 -147
- package/dist/cjs/contracts/contractManager.js +0 -649
- package/dist/cjs/contracts/contractWatcher.js +0 -598
- package/dist/cjs/contracts/handlers/default.js +0 -93
- package/dist/cjs/contracts/handlers/delegate.js +0 -90
- package/dist/cjs/contracts/handlers/helpers.js +0 -115
- package/dist/cjs/contracts/handlers/index.js +0 -19
- package/dist/cjs/contracts/handlers/registry.js +0 -89
- package/dist/cjs/contracts/handlers/vhtlc.js +0 -194
- package/dist/cjs/contracts/index.js +0 -41
- package/dist/cjs/contracts/types.js +0 -2
- package/dist/cjs/contracts/vtxoOwnership.js +0 -78
- package/dist/cjs/extension/asset/assetGroup.js +0 -228
- package/dist/cjs/extension/asset/assetId.js +0 -152
- package/dist/cjs/extension/asset/assetInput.js +0 -222
- package/dist/cjs/extension/asset/assetOutput.js +0 -174
- package/dist/cjs/extension/asset/assetRef.js +0 -148
- package/dist/cjs/extension/asset/index.js +0 -23
- package/dist/cjs/extension/asset/metadata.js +0 -187
- package/dist/cjs/extension/asset/packet.js +0 -114
- package/dist/cjs/extension/asset/types.js +0 -22
- package/dist/cjs/extension/asset/utils.js +0 -105
- package/dist/cjs/extension/index.js +0 -254
- package/dist/cjs/extension/packet.js +0 -20
- package/dist/cjs/forfeit.js +0 -45
- package/dist/cjs/identity/descriptor.js +0 -169
- package/dist/cjs/identity/descriptorProvider.js +0 -2
- package/dist/cjs/identity/hdCapableIdentity.js +0 -20
- package/dist/cjs/identity/index.js +0 -40
- package/dist/cjs/identity/seedIdentity.js +0 -477
- package/dist/cjs/identity/serialize.js +0 -171
- package/dist/cjs/identity/singleKey.js +0 -126
- package/dist/cjs/identity/staticDescriptorProvider.js +0 -65
- package/dist/cjs/index.js +0 -202
- package/dist/cjs/intent/index.js +0 -259
- package/dist/cjs/musig2/index.js +0 -11
- package/dist/cjs/musig2/keys.js +0 -57
- package/dist/cjs/musig2/nonces.js +0 -48
- package/dist/cjs/musig2/sign.js +0 -102
- package/dist/cjs/networks.js +0 -26
- package/dist/cjs/package.json +0 -3
- package/dist/cjs/providers/ark.js +0 -577
- package/dist/cjs/providers/delegator.js +0 -85
- package/dist/cjs/providers/electrum.js +0 -869
- package/dist/cjs/providers/errors.js +0 -59
- package/dist/cjs/providers/expoArk.js +0 -82
- package/dist/cjs/providers/expoIndexer.js +0 -111
- package/dist/cjs/providers/expoUtils.js +0 -124
- package/dist/cjs/providers/indexer.js +0 -630
- package/dist/cjs/providers/onchain.js +0 -262
- package/dist/cjs/providers/utils.js +0 -121
- package/dist/cjs/repositories/contractRepository.js +0 -2
- package/dist/cjs/repositories/inMemory/contractRepository.js +0 -55
- package/dist/cjs/repositories/inMemory/walletRepository.js +0 -115
- package/dist/cjs/repositories/index.js +0 -34
- package/dist/cjs/repositories/indexedDB/contractRepository.js +0 -187
- package/dist/cjs/repositories/indexedDB/db.js +0 -19
- package/dist/cjs/repositories/indexedDB/manager.js +0 -100
- package/dist/cjs/repositories/indexedDB/schema.js +0 -204
- package/dist/cjs/repositories/indexedDB/walletRepository.js +0 -474
- package/dist/cjs/repositories/indexedDB/websqlAdapter.js +0 -144
- package/dist/cjs/repositories/migrations/contractRepositoryImpl.js +0 -127
- package/dist/cjs/repositories/migrations/fromStorageAdapter.js +0 -66
- package/dist/cjs/repositories/migrations/walletRepositoryImpl.js +0 -184
- package/dist/cjs/repositories/realm/contractRepository.js +0 -116
- package/dist/cjs/repositories/realm/index.js +0 -11
- package/dist/cjs/repositories/realm/schemas.js +0 -157
- package/dist/cjs/repositories/realm/types.js +0 -7
- package/dist/cjs/repositories/realm/walletRepository.js +0 -305
- package/dist/cjs/repositories/scriptFromAddress.js +0 -16
- package/dist/cjs/repositories/serialization.js +0 -82
- package/dist/cjs/repositories/sqlite/contractRepository.js +0 -135
- package/dist/cjs/repositories/sqlite/index.js +0 -7
- package/dist/cjs/repositories/sqlite/types.js +0 -2
- package/dist/cjs/repositories/sqlite/walletRepository.js +0 -441
- package/dist/cjs/repositories/walletRepository.js +0 -2
- package/dist/cjs/script/address.js +0 -108
- package/dist/cjs/script/base.js +0 -185
- package/dist/cjs/script/default.js +0 -57
- package/dist/cjs/script/delegate.js +0 -53
- package/dist/cjs/script/tapscript.js +0 -619
- package/dist/cjs/script/vhtlc.js +0 -170
- package/dist/cjs/storage/asyncStorage.js +0 -50
- package/dist/cjs/storage/fileSystem.js +0 -141
- package/dist/cjs/storage/inMemory.js +0 -24
- package/dist/cjs/storage/index.js +0 -2
- package/dist/cjs/storage/indexedDB.js +0 -101
- package/dist/cjs/storage/localStorage.js +0 -51
- package/dist/cjs/tree/signingSession.js +0 -229
- package/dist/cjs/tree/txTree.js +0 -192
- package/dist/cjs/tree/validation.js +0 -107
- package/dist/cjs/utils/anchor.js +0 -35
- package/dist/cjs/utils/arkTransaction.js +0 -271
- package/dist/cjs/utils/bip21.js +0 -127
- package/dist/cjs/utils/syncCursors.js +0 -128
- package/dist/cjs/utils/timelock.js +0 -59
- package/dist/cjs/utils/transaction.js +0 -28
- package/dist/cjs/utils/transactionHistory.js +0 -183
- package/dist/cjs/utils/txSizeEstimator.js +0 -132
- package/dist/cjs/utils/unknownFields.js +0 -174
- package/dist/cjs/wallet/asset-manager.js +0 -330
- package/dist/cjs/wallet/asset.js +0 -119
- package/dist/cjs/wallet/batch.js +0 -183
- package/dist/cjs/wallet/delegator.js +0 -308
- package/dist/cjs/wallet/expo/background.js +0 -116
- package/dist/cjs/wallet/expo/index.js +0 -9
- package/dist/cjs/wallet/expo/wallet.js +0 -230
- package/dist/cjs/wallet/hdDescriptorProvider.js +0 -188
- package/dist/cjs/wallet/index.js +0 -82
- package/dist/cjs/wallet/inputSignerRouter.js +0 -98
- package/dist/cjs/wallet/onchain.js +0 -290
- package/dist/cjs/wallet/ramps.js +0 -216
- package/dist/cjs/wallet/serviceWorker/wallet-message-handler.js +0 -953
- package/dist/cjs/wallet/serviceWorker/wallet.js +0 -1174
- package/dist/cjs/wallet/signingErrors.js +0 -32
- package/dist/cjs/wallet/unroll.js +0 -293
- package/dist/cjs/wallet/utils.js +0 -111
- package/dist/cjs/wallet/validation.js +0 -154
- package/dist/cjs/wallet/vtxo-manager.js +0 -1142
- package/dist/cjs/wallet/wallet.js +0 -2195
- package/dist/cjs/wallet/walletReceiveRotator.js +0 -547
- package/dist/cjs/worker/browser/service-worker-manager.js +0 -183
- package/dist/cjs/worker/browser/utils.js +0 -67
- package/dist/cjs/worker/errors.js +0 -16
- package/dist/cjs/worker/expo/asyncStorageTaskQueue.js +0 -78
- package/dist/cjs/worker/expo/index.js +0 -13
- package/dist/cjs/worker/expo/processors/contractPollProcessor.js +0 -62
- package/dist/cjs/worker/expo/processors/index.js +0 -6
- package/dist/cjs/worker/expo/taskQueue.js +0 -41
- package/dist/cjs/worker/expo/taskRunner.js +0 -73
- package/dist/cjs/worker/messageBus.js +0 -474
- package/dist/esm/adapters/asyncStorage.js +0 -1
- package/dist/esm/adapters/expo.js +0 -3
- package/dist/esm/adapters/fileSystem.js +0 -1
- package/dist/esm/adapters/indexedDB.js +0 -1
- package/dist/esm/adapters/localStorage.js +0 -1
- package/dist/esm/arkfee/celenv.js +0 -40
- package/dist/esm/arkfee/estimator.js +0 -139
- package/dist/esm/arkfee/index.js +0 -1
- package/dist/esm/arkfee/types.js +0 -22
- package/dist/esm/arknote/index.js +0 -124
- package/dist/esm/bip322/index.js +0 -267
- package/dist/esm/contracts/arkcontract.js +0 -140
- package/dist/esm/contracts/contractManager.js +0 -645
- package/dist/esm/contracts/contractWatcher.js +0 -594
- package/dist/esm/contracts/handlers/default.js +0 -90
- package/dist/esm/contracts/handlers/delegate.js +0 -87
- package/dist/esm/contracts/handlers/helpers.js +0 -110
- package/dist/esm/contracts/handlers/index.js +0 -12
- package/dist/esm/contracts/handlers/registry.js +0 -86
- package/dist/esm/contracts/handlers/vhtlc.js +0 -191
- package/dist/esm/contracts/index.js +0 -13
- package/dist/esm/contracts/types.js +0 -1
- package/dist/esm/contracts/vtxoOwnership.js +0 -69
- package/dist/esm/extension/asset/assetGroup.js +0 -224
- package/dist/esm/extension/asset/assetId.js +0 -148
- package/dist/esm/extension/asset/assetInput.js +0 -217
- package/dist/esm/extension/asset/assetOutput.js +0 -169
- package/dist/esm/extension/asset/assetRef.js +0 -144
- package/dist/esm/extension/asset/index.js +0 -8
- package/dist/esm/extension/asset/metadata.js +0 -182
- package/dist/esm/extension/asset/packet.js +0 -110
- package/dist/esm/extension/asset/types.js +0 -19
- package/dist/esm/extension/asset/utils.js +0 -99
- package/dist/esm/extension/index.js +0 -248
- package/dist/esm/extension/packet.js +0 -16
- package/dist/esm/forfeit.js +0 -41
- package/dist/esm/identity/descriptor.js +0 -161
- package/dist/esm/identity/descriptorProvider.js +0 -1
- package/dist/esm/identity/hdCapableIdentity.js +0 -17
- package/dist/esm/identity/index.js +0 -13
- package/dist/esm/identity/seedIdentity.js +0 -469
- package/dist/esm/identity/serialize.js +0 -164
- package/dist/esm/identity/singleKey.js +0 -121
- package/dist/esm/identity/staticDescriptorProvider.js +0 -61
- package/dist/esm/index.js +0 -87
- package/dist/esm/intent/index.js +0 -255
- package/dist/esm/musig2/index.js +0 -3
- package/dist/esm/musig2/keys.js +0 -21
- package/dist/esm/musig2/nonces.js +0 -11
- package/dist/esm/musig2/sign.js +0 -63
- package/dist/esm/networks.js +0 -22
- package/dist/esm/package.json +0 -3
- package/dist/esm/providers/ark.js +0 -572
- package/dist/esm/providers/delegator.js +0 -81
- package/dist/esm/providers/electrum.js +0 -864
- package/dist/esm/providers/errors.js +0 -54
- package/dist/esm/providers/expoArk.js +0 -78
- package/dist/esm/providers/expoIndexer.js +0 -107
- package/dist/esm/providers/expoUtils.js +0 -87
- package/dist/esm/providers/indexer.js +0 -626
- package/dist/esm/providers/onchain.js +0 -258
- package/dist/esm/providers/utils.js +0 -117
- package/dist/esm/repositories/contractRepository.js +0 -1
- package/dist/esm/repositories/inMemory/contractRepository.js +0 -51
- package/dist/esm/repositories/inMemory/walletRepository.js +0 -111
- package/dist/esm/repositories/index.js +0 -10
- package/dist/esm/repositories/indexedDB/contractRepository.js +0 -183
- package/dist/esm/repositories/indexedDB/db.js +0 -4
- package/dist/esm/repositories/indexedDB/manager.js +0 -95
- package/dist/esm/repositories/indexedDB/schema.js +0 -199
- package/dist/esm/repositories/indexedDB/walletRepository.js +0 -470
- package/dist/esm/repositories/indexedDB/websqlAdapter.js +0 -138
- package/dist/esm/repositories/migrations/contractRepositoryImpl.js +0 -121
- package/dist/esm/repositories/migrations/fromStorageAdapter.js +0 -58
- package/dist/esm/repositories/migrations/walletRepositoryImpl.js +0 -180
- package/dist/esm/repositories/realm/contractRepository.js +0 -112
- package/dist/esm/repositories/realm/index.js +0 -3
- package/dist/esm/repositories/realm/schemas.js +0 -153
- package/dist/esm/repositories/realm/types.js +0 -6
- package/dist/esm/repositories/realm/walletRepository.js +0 -301
- package/dist/esm/repositories/scriptFromAddress.js +0 -13
- package/dist/esm/repositories/serialization.js +0 -67
- package/dist/esm/repositories/sqlite/contractRepository.js +0 -131
- package/dist/esm/repositories/sqlite/index.js +0 -2
- package/dist/esm/repositories/sqlite/types.js +0 -1
- package/dist/esm/repositories/sqlite/walletRepository.js +0 -437
- package/dist/esm/repositories/walletRepository.js +0 -1
- package/dist/esm/script/address.js +0 -104
- package/dist/esm/script/base.js +0 -179
- package/dist/esm/script/default.js +0 -54
- package/dist/esm/script/delegate.js +0 -50
- package/dist/esm/script/tapscript.js +0 -615
- package/dist/esm/script/vhtlc.js +0 -167
- package/dist/esm/storage/asyncStorage.js +0 -46
- package/dist/esm/storage/fileSystem.js +0 -104
- package/dist/esm/storage/inMemory.js +0 -20
- package/dist/esm/storage/index.js +0 -1
- package/dist/esm/storage/indexedDB.js +0 -97
- package/dist/esm/storage/localStorage.js +0 -47
- package/dist/esm/tree/signingSession.js +0 -191
- package/dist/esm/tree/txTree.js +0 -188
- package/dist/esm/tree/validation.js +0 -101
- package/dist/esm/utils/anchor.js +0 -31
- package/dist/esm/utils/arkTransaction.js +0 -264
- package/dist/esm/utils/bip21.js +0 -123
- package/dist/esm/utils/syncCursors.js +0 -119
- package/dist/esm/utils/timelock.js +0 -22
- package/dist/esm/utils/transaction.js +0 -24
- package/dist/esm/utils/transactionHistory.js +0 -180
- package/dist/esm/utils/txSizeEstimator.js +0 -128
- package/dist/esm/utils/unknownFields.js +0 -169
- package/dist/esm/wallet/asset-manager.js +0 -325
- package/dist/esm/wallet/asset.js +0 -113
- package/dist/esm/wallet/batch.js +0 -180
- package/dist/esm/wallet/delegator.js +0 -303
- package/dist/esm/wallet/expo/background.js +0 -111
- package/dist/esm/wallet/expo/index.js +0 -2
- package/dist/esm/wallet/expo/wallet.js +0 -193
- package/dist/esm/wallet/hdDescriptorProvider.js +0 -184
- package/dist/esm/wallet/index.js +0 -75
- package/dist/esm/wallet/inputSignerRouter.js +0 -94
- package/dist/esm/wallet/onchain.js +0 -285
- package/dist/esm/wallet/ramps.js +0 -212
- package/dist/esm/wallet/serviceWorker/wallet-message-handler.js +0 -946
- package/dist/esm/wallet/serviceWorker/wallet.js +0 -1169
- package/dist/esm/wallet/signingErrors.js +0 -27
- package/dist/esm/wallet/unroll.js +0 -289
- package/dist/esm/wallet/utils.js +0 -103
- package/dist/esm/wallet/validation.js +0 -142
- package/dist/esm/wallet/vtxo-manager.js +0 -1136
- package/dist/esm/wallet/wallet.js +0 -2186
- package/dist/esm/wallet/walletReceiveRotator.js +0 -540
- package/dist/esm/worker/browser/service-worker-manager.js +0 -177
- package/dist/esm/worker/browser/utils.js +0 -63
- package/dist/esm/worker/errors.js +0 -11
- package/dist/esm/worker/expo/asyncStorageTaskQueue.js +0 -74
- package/dist/esm/worker/expo/index.js +0 -4
- package/dist/esm/worker/expo/processors/contractPollProcessor.js +0 -59
- package/dist/esm/worker/expo/processors/index.js +0 -1
- package/dist/esm/worker/expo/taskQueue.js +0 -37
- package/dist/esm/worker/expo/taskRunner.js +0 -69
- package/dist/esm/worker/messageBus.js +0 -470
- package/dist/types/adapters/asyncStorage.d.ts +0 -2
- package/dist/types/adapters/expo.d.ts +0 -4
- package/dist/types/adapters/fileSystem.d.ts +0 -2
- package/dist/types/adapters/indexedDB.d.ts +0 -2
- package/dist/types/adapters/localStorage.d.ts +0 -2
- package/dist/types/arkfee/celenv.d.ts +0 -25
- package/dist/types/arkfee/estimator.d.ts +0 -49
- package/dist/types/arkfee/index.d.ts +0 -2
- package/dist/types/arkfee/types.d.ts +0 -38
- package/dist/types/arknote/index.d.ts +0 -84
- package/dist/types/bip322/index.d.ts +0 -55
- package/dist/types/contracts/arkcontract.d.ts +0 -99
- package/dist/types/contracts/contractManager.d.ts +0 -411
- package/dist/types/contracts/contractWatcher.d.ts +0 -217
- package/dist/types/contracts/handlers/default.d.ts +0 -19
- package/dist/types/contracts/handlers/delegate.d.ts +0 -21
- package/dist/types/contracts/handlers/helpers.d.ts +0 -19
- package/dist/types/contracts/handlers/index.d.ts +0 -7
- package/dist/types/contracts/handlers/registry.d.ts +0 -65
- package/dist/types/contracts/handlers/vhtlc.d.ts +0 -32
- package/dist/types/contracts/index.d.ts +0 -14
- package/dist/types/contracts/types.d.ts +0 -250
- package/dist/types/contracts/vtxoOwnership.d.ts +0 -33
- package/dist/types/extension/asset/assetGroup.d.ts +0 -119
- package/dist/types/extension/asset/assetId.d.ts +0 -83
- package/dist/types/extension/asset/assetInput.d.ts +0 -64
- package/dist/types/extension/asset/assetOutput.d.ts +0 -54
- package/dist/types/extension/asset/assetRef.d.ts +0 -91
- package/dist/types/extension/asset/index.d.ts +0 -8
- package/dist/types/extension/asset/metadata.d.ts +0 -52
- package/dist/types/extension/asset/packet.d.ts +0 -41
- package/dist/types/extension/asset/types.d.ts +0 -16
- package/dist/types/extension/asset/utils.d.ts +0 -21
- package/dist/types/extension/index.d.ts +0 -56
- package/dist/types/extension/packet.d.ts +0 -21
- package/dist/types/forfeit.d.ts +0 -18
- package/dist/types/identity/descriptor.d.ts +0 -61
- package/dist/types/identity/descriptorProvider.d.ts +0 -42
- package/dist/types/identity/hdCapableIdentity.d.ts +0 -71
- package/dist/types/identity/index.d.ts +0 -57
- package/dist/types/identity/seedIdentity.d.ts +0 -270
- package/dist/types/identity/serialize.d.ts +0 -96
- package/dist/types/identity/singleKey.d.ts +0 -62
- package/dist/types/identity/staticDescriptorProvider.d.ts +0 -18
- package/dist/types/index.d.ts +0 -59
- package/dist/types/intent/index.d.ts +0 -86
- package/dist/types/musig2/index.d.ts +0 -4
- package/dist/types/musig2/keys.d.ts +0 -9
- package/dist/types/musig2/nonces.d.ts +0 -14
- package/dist/types/musig2/sign.d.ts +0 -27
- package/dist/types/networks.d.ts +0 -16
- package/dist/types/providers/ark.d.ts +0 -369
- package/dist/types/providers/delegator.d.ts +0 -82
- package/dist/types/providers/electrum.d.ts +0 -312
- package/dist/types/providers/errors.d.ts +0 -13
- package/dist/types/providers/expoArk.d.ts +0 -22
- package/dist/types/providers/expoIndexer.d.ts +0 -18
- package/dist/types/providers/expoUtils.d.ts +0 -18
- package/dist/types/providers/indexer.d.ts +0 -301
- package/dist/types/providers/onchain.d.ts +0 -148
- package/dist/types/providers/utils.d.ts +0 -12
- package/dist/types/repositories/contractRepository.d.ts +0 -32
- package/dist/types/repositories/inMemory/contractRepository.d.ts +0 -17
- package/dist/types/repositories/inMemory/walletRepository.d.ts +0 -29
- package/dist/types/repositories/index.d.ts +0 -9
- package/dist/types/repositories/indexedDB/contractRepository.d.ts +0 -21
- package/dist/types/repositories/indexedDB/db.d.ts +0 -4
- package/dist/types/repositories/indexedDB/manager.d.ts +0 -25
- package/dist/types/repositories/indexedDB/schema.d.ts +0 -9
- package/dist/types/repositories/indexedDB/walletRepository.d.ts +0 -28
- package/dist/types/repositories/indexedDB/websqlAdapter.d.ts +0 -49
- package/dist/types/repositories/migrations/contractRepositoryImpl.d.ts +0 -24
- package/dist/types/repositories/migrations/fromStorageAdapter.d.ts +0 -19
- package/dist/types/repositories/migrations/walletRepositoryImpl.d.ts +0 -27
- package/dist/types/repositories/realm/contractRepository.d.ts +0 -24
- package/dist/types/repositories/realm/index.d.ts +0 -4
- package/dist/types/repositories/realm/types.d.ts +0 -16
- package/dist/types/repositories/realm/walletRepository.d.ts +0 -34
- package/dist/types/repositories/scriptFromAddress.d.ts +0 -9
- package/dist/types/repositories/serialization.d.ts +0 -65
- package/dist/types/repositories/sqlite/contractRepository.d.ts +0 -33
- package/dist/types/repositories/sqlite/index.d.ts +0 -3
- package/dist/types/repositories/sqlite/types.d.ts +0 -18
- package/dist/types/repositories/walletRepository.d.ts +0 -72
- package/dist/types/script/address.d.ts +0 -67
- package/dist/types/script/base.d.ts +0 -105
- package/dist/types/script/default.d.ts +0 -44
- package/dist/types/script/delegate.d.ts +0 -40
- package/dist/types/script/tapscript.d.ts +0 -169
- package/dist/types/script/vhtlc.d.ts +0 -66
- package/dist/types/tree/signingSession.d.ts +0 -37
- package/dist/types/tree/txTree.d.ts +0 -28
- package/dist/types/tree/validation.d.ts +0 -15
- package/dist/types/utils/anchor.d.ts +0 -19
- package/dist/types/utils/arkTransaction.d.ts +0 -49
- package/dist/types/utils/bip21.d.ts +0 -38
- package/dist/types/utils/syncCursors.d.ts +0 -60
- package/dist/types/utils/timelock.d.ts +0 -9
- package/dist/types/utils/transaction.d.ts +0 -13
- package/dist/types/utils/transactionHistory.d.ts +0 -15
- package/dist/types/utils/txSizeEstimator.d.ts +0 -40
- package/dist/types/utils/unknownFields.d.ts +0 -83
- package/dist/types/wallet/asset-manager.d.ts +0 -69
- package/dist/types/wallet/asset.d.ts +0 -21
- package/dist/types/wallet/batch.d.ts +0 -107
- package/dist/types/wallet/delegator.d.ts +0 -48
- package/dist/types/wallet/expo/background.d.ts +0 -66
- package/dist/types/wallet/expo/index.d.ts +0 -4
- package/dist/types/wallet/hdDescriptorProvider.d.ts +0 -114
- package/dist/types/wallet/index.d.ts +0 -789
- package/dist/types/wallet/inputSignerRouter.d.ts +0 -35
- package/dist/types/wallet/onchain.d.ts +0 -109
- package/dist/types/wallet/ramps.d.ts +0 -64
- package/dist/types/wallet/serviceWorker/wallet-message-handler.d.ts +0 -543
- package/dist/types/wallet/serviceWorker/wallet.d.ts +0 -248
- package/dist/types/wallet/signingErrors.d.ts +0 -19
- package/dist/types/wallet/unroll.d.ts +0 -114
- package/dist/types/wallet/utils.d.ts +0 -36
- package/dist/types/wallet/validation.d.ts +0 -24
- package/dist/types/wallet/vtxo-manager.d.ts +0 -476
- package/dist/types/wallet/wallet.d.ts +0 -409
- package/dist/types/wallet/walletReceiveRotator.d.ts +0 -306
- package/dist/types/worker/browser/service-worker-manager.d.ts +0 -32
- package/dist/types/worker/browser/utils.d.ts +0 -17
- package/dist/types/worker/errors.d.ts +0 -7
- package/dist/types/worker/expo/index.d.ts +0 -7
- package/dist/types/worker/expo/processors/contractPollProcessor.d.ts +0 -19
- package/dist/types/worker/expo/processors/index.d.ts +0 -1
- package/dist/types/worker/expo/taskQueue.d.ts +0 -50
- package/dist/types/worker/expo/taskRunner.d.ts +0 -66
- package/dist/types/worker/messageBus.d.ts +0 -189
|
@@ -0,0 +1,3880 @@
|
|
|
1
|
+
import { TxOpts, Transaction as Transaction$2 } from '@scure/btc-signer/transaction.js';
|
|
2
|
+
import { Bytes } from '@scure/btc-signer/utils.js';
|
|
3
|
+
import { PSBTOutput, TransactionInput, TransactionOutput } from '@scure/btc-signer/psbt.js';
|
|
4
|
+
import { Transaction as Transaction$1, NETWORK } from '@scure/btc-signer';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Transaction is a wrapper around the @scure/btc-signer Transaction class.
|
|
8
|
+
* It adds the Arkade protocol specific options to the transaction.
|
|
9
|
+
*/
|
|
10
|
+
declare class Transaction extends Transaction$1 {
|
|
11
|
+
static ARK_TX_OPTS: TxOpts;
|
|
12
|
+
constructor(opts?: TxOpts);
|
|
13
|
+
static fromPSBT(psbt_: Bytes, opts?: TxOpts): Transaction;
|
|
14
|
+
static fromRaw(raw: Bytes, opts?: TxOpts): Transaction;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* MuSig2 nonce pair containing public and secret values.
|
|
19
|
+
* Public nonces are two compressed points (33 bytes each).
|
|
20
|
+
* Secret nonces are the corresponding private scalars plus pubkey.
|
|
21
|
+
*/
|
|
22
|
+
type Nonces = {
|
|
23
|
+
pubNonce: Uint8Array;
|
|
24
|
+
secNonce: Uint8Array;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
declare class PartialSig {
|
|
28
|
+
s: Uint8Array;
|
|
29
|
+
R: Uint8Array;
|
|
30
|
+
constructor(s: Uint8Array, R: Uint8Array);
|
|
31
|
+
/**
|
|
32
|
+
* Encodes the partial signature into bytes
|
|
33
|
+
* Returns a 32-byte array containing just the s value
|
|
34
|
+
*/
|
|
35
|
+
encode(): Uint8Array;
|
|
36
|
+
/**
|
|
37
|
+
* Decodes a partial signature from bytes
|
|
38
|
+
* @param bytes - 32-byte array containing s value
|
|
39
|
+
*/
|
|
40
|
+
static decode(bytes: Uint8Array): PartialSig;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* TxTreeNode is a node of the tree.
|
|
45
|
+
* It contains the transaction id, the transaction and the children.
|
|
46
|
+
* any TxTree can be serialized as a list of TxTreeNode.
|
|
47
|
+
*/
|
|
48
|
+
type TxTreeNode = {
|
|
49
|
+
txid: string;
|
|
50
|
+
tx: string;
|
|
51
|
+
children: Record<number, string>;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* TxTree is a graph of bitcoin transactions.
|
|
55
|
+
* It is used to represent batch tree created during settlement session
|
|
56
|
+
*/
|
|
57
|
+
declare class TxTree {
|
|
58
|
+
readonly root: Transaction$2;
|
|
59
|
+
readonly children: Map<number, TxTree>;
|
|
60
|
+
constructor(root: Transaction$2, children?: Map<number, TxTree>);
|
|
61
|
+
static create(chunks: TxTreeNode[]): TxTree;
|
|
62
|
+
nbOfNodes(): number;
|
|
63
|
+
validate(): void;
|
|
64
|
+
leaves(): Transaction$2[];
|
|
65
|
+
get txid(): string;
|
|
66
|
+
find(txid: string): TxTree | null;
|
|
67
|
+
update(txid: string, fn: (tx: Transaction$2) => void): void;
|
|
68
|
+
iterator(): Generator<TxTree, void, unknown>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
type Musig2PublicNonce = Pick<Nonces, "pubNonce">;
|
|
72
|
+
type TreeNonces = Map<string, Musig2PublicNonce>;
|
|
73
|
+
type TreePartialSigs = Map<string, PartialSig>;
|
|
74
|
+
interface SignerSession {
|
|
75
|
+
getPublicKey(): Promise<Uint8Array>;
|
|
76
|
+
init(tree: TxTree, scriptRoot: Uint8Array, rootInputAmount: bigint): Promise<void>;
|
|
77
|
+
getNonces(): Promise<TreeNonces>;
|
|
78
|
+
aggregatedNonces(txid: string, noncesByPubkey: TreeNonces): Promise<{
|
|
79
|
+
hasAllNonces: boolean;
|
|
80
|
+
}>;
|
|
81
|
+
sign(): Promise<TreePartialSigs>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** A signing request that pairs a descriptor with a transaction. */
|
|
85
|
+
interface DescriptorSigningRequest {
|
|
86
|
+
/** Descriptor identifying which key to sign with */
|
|
87
|
+
descriptor: string;
|
|
88
|
+
/** Transaction to sign */
|
|
89
|
+
tx: Transaction;
|
|
90
|
+
/** Specific input indexes to sign (signs all if omitted) */
|
|
91
|
+
inputIndexes?: number[];
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Provider interface for descriptor-based signing.
|
|
95
|
+
*
|
|
96
|
+
* Implementations include:
|
|
97
|
+
* - {@link StaticDescriptorProvider}: wraps a legacy {@link Identity} with a single key.
|
|
98
|
+
* - {@link HDDescriptorProvider}: rotates through HD-derived descriptors.
|
|
99
|
+
*
|
|
100
|
+
* The provider has no read accessor for "current" — it is a pure descriptor
|
|
101
|
+
* allocator. "What addresses am I currently bound to?" is a question the
|
|
102
|
+
* contract repository answers, not the provider.
|
|
103
|
+
*
|
|
104
|
+
* Providers that want to participate in HD receive rotation can also
|
|
105
|
+
* implement the wallet-side `ReceiveRotatorFactory` interface (see
|
|
106
|
+
* `src/wallet/walletReceiveRotator.ts`). That extension is opt-in — the
|
|
107
|
+
* core `DescriptorProvider` contract intentionally stays free of
|
|
108
|
+
* wallet-specific concerns so HSM-backed and other minimal providers
|
|
109
|
+
* don't have to know about the receive-rotation lifecycle.
|
|
110
|
+
*/
|
|
111
|
+
interface DescriptorProvider {
|
|
112
|
+
/**
|
|
113
|
+
* Allocate a new signing descriptor. For HD providers each call advances
|
|
114
|
+
* the internal index and returns a fresh descriptor; for single-key
|
|
115
|
+
* providers each call returns the same descriptor.
|
|
116
|
+
*/
|
|
117
|
+
getNextSigningDescriptor(): Promise<string>;
|
|
118
|
+
/** Checks if a descriptor belongs to this provider. */
|
|
119
|
+
isOurs(descriptor: string): boolean;
|
|
120
|
+
/** Signs transactions, each with its own descriptor-derived key. */
|
|
121
|
+
signWithDescriptor(requests: DescriptorSigningRequest[]): Promise<Transaction[]>;
|
|
122
|
+
/** Signs a message using the key derived from the descriptor. */
|
|
123
|
+
signMessageWithDescriptor(descriptor: string, message: Uint8Array, type?: "schnorr" | "ecdsa"): Promise<Uint8Array>;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
interface Identity extends ReadonlyIdentity {
|
|
127
|
+
/** Returns a signer session used for musig2 tree signing flows. */
|
|
128
|
+
signerSession(): SignerSession;
|
|
129
|
+
/** Sign an arbitrary message using the requested signature type. */
|
|
130
|
+
signMessage(message: Uint8Array, signatureType: "schnorr" | "ecdsa"): Promise<Uint8Array>;
|
|
131
|
+
/**
|
|
132
|
+
* Sign the provided transaction inputs.
|
|
133
|
+
*
|
|
134
|
+
* @param tx - Transaction to sign
|
|
135
|
+
* @param inputIndexes - Optional input indexes to sign. When omitted, the implementation should sign every signable input.
|
|
136
|
+
*/
|
|
137
|
+
sign(tx: Transaction, inputIndexes?: number[]): Promise<Transaction>;
|
|
138
|
+
}
|
|
139
|
+
interface ReadonlyIdentity {
|
|
140
|
+
/** Returns the x-only public key used by Taproot scripts. */
|
|
141
|
+
xOnlyPublicKey(): Promise<Uint8Array>;
|
|
142
|
+
/** Returns the compressed public key for this identity. */
|
|
143
|
+
compressedPublicKey(): Promise<Uint8Array>;
|
|
144
|
+
}
|
|
145
|
+
/** A single PSBT signing request within a batch. */
|
|
146
|
+
interface SignRequest {
|
|
147
|
+
tx: Transaction;
|
|
148
|
+
inputIndexes?: number[];
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Identity that supports signing multiple PSBTs in a single wallet interaction.
|
|
152
|
+
* Browser wallet providers that support batch signing (e.g. Xverse, UniSat, OKX)
|
|
153
|
+
* should implement this interface to reduce the number of confirmation popups
|
|
154
|
+
* from N+1 to 1 during Arkade send transactions.
|
|
155
|
+
*
|
|
156
|
+
* Contract: implementations MUST return exactly one `Transaction` per request,
|
|
157
|
+
* in the same order as the input array. The SDK validates this at runtime and
|
|
158
|
+
* will throw if the lengths do not match.
|
|
159
|
+
*/
|
|
160
|
+
interface BatchSignableIdentity extends Identity {
|
|
161
|
+
/**
|
|
162
|
+
* Sign multiple transactions in a single wallet interaction.
|
|
163
|
+
*
|
|
164
|
+
* @param requests - Transactions and optional input indexes to sign
|
|
165
|
+
* @returns Signed transactions in the same order as the input requests
|
|
166
|
+
*/
|
|
167
|
+
signMultiple(requests: SignRequest[]): Promise<Transaction[]>;
|
|
168
|
+
}
|
|
169
|
+
/** Type guard for identities that support batch signing. */
|
|
170
|
+
declare function isBatchSignable(identity: Identity): identity is BatchSignableIdentity;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* ArkAddress allows creating and decoding bech32m-encoded Arkade addresses.
|
|
174
|
+
*
|
|
175
|
+
* An Arkade address is composed of:
|
|
176
|
+
* - a human readable prefix (hrp)
|
|
177
|
+
* - a version byte (1 byte)
|
|
178
|
+
* - a server public key (32 bytes)
|
|
179
|
+
* - a vtxo taproot public key (32 bytes)
|
|
180
|
+
*
|
|
181
|
+
* @remarks
|
|
182
|
+
* This is an Arkade-specific address format.
|
|
183
|
+
* It is distinct from the Taproot onchain address returned by `VtxoScript.onchainAddress`.
|
|
184
|
+
*
|
|
185
|
+
* @see VtxoScript
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* const address = new ArkAddress(
|
|
190
|
+
* new Uint8Array(32), // server public key
|
|
191
|
+
* new Uint8Array(32), // vtxo taproot public key
|
|
192
|
+
* "ark"
|
|
193
|
+
* );
|
|
194
|
+
*
|
|
195
|
+
* const encoded = address.encode();
|
|
196
|
+
* console.log("address: ", encoded);
|
|
197
|
+
*
|
|
198
|
+
* const decoded = ArkAddress.decode(encoded);
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
declare class ArkAddress {
|
|
202
|
+
readonly serverPubKey: Bytes;
|
|
203
|
+
readonly vtxoTaprootKey: Bytes;
|
|
204
|
+
readonly hrp: string;
|
|
205
|
+
readonly version: number;
|
|
206
|
+
/**
|
|
207
|
+
* Create an Arkade address from its server public key, Taproot output key, and prefix.
|
|
208
|
+
*
|
|
209
|
+
* @param serverPubKey - 32-byte Arkade server public key
|
|
210
|
+
* @param vtxoTaprootKey - 32-byte Taproot output key (a.k.a. tweaked public key)
|
|
211
|
+
* @param hrp - Bech32 human-readable prefix
|
|
212
|
+
* @param version - Address version byte
|
|
213
|
+
* @defaultValue `version = 0`
|
|
214
|
+
* @throws Error if either public key is not 32 bytes long
|
|
215
|
+
*/
|
|
216
|
+
constructor(serverPubKey: Bytes, vtxoTaprootKey: Bytes, hrp?: string, version?: number);
|
|
217
|
+
/**
|
|
218
|
+
* Decode an Arkade address from its bech32m string form.
|
|
219
|
+
*
|
|
220
|
+
* @param address - Bech32m-encoded Arkade address
|
|
221
|
+
* @returns Decoded Arkade address
|
|
222
|
+
* @throws Error if the address is malformed or has an invalid payload length
|
|
223
|
+
* @see encode
|
|
224
|
+
*/
|
|
225
|
+
static decode(address: string): ArkAddress;
|
|
226
|
+
/**
|
|
227
|
+
* Encode the address to its bech32m string form.
|
|
228
|
+
*
|
|
229
|
+
* @returns Bech32m-encoded Arkade address
|
|
230
|
+
* @see decode
|
|
231
|
+
*/
|
|
232
|
+
encode(): string;
|
|
233
|
+
/** ScriptPubKey used to send non-dust funds to the address. */
|
|
234
|
+
get pkScript(): Bytes;
|
|
235
|
+
/** ScriptPubKey used to send sub-dust funds to the address. */
|
|
236
|
+
get subdustPkScript(): Bytes;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* RelativeTimelock lets to create timelocked with CHECKSEQUENCEVERIFY script.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* const timelock = { value: 144n, type: "blocks" }; // 1 day in blocks
|
|
245
|
+
* const timelock = { value: 512n, type: "seconds" }; // 8 minutes in seconds
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
type RelativeTimelock = {
|
|
249
|
+
value: bigint;
|
|
250
|
+
type: "seconds" | "blocks";
|
|
251
|
+
};
|
|
252
|
+
declare enum TapscriptType {
|
|
253
|
+
Multisig = "multisig",
|
|
254
|
+
CSVMultisig = "csv-multisig",
|
|
255
|
+
ConditionCSVMultisig = "condition-csv-multisig",
|
|
256
|
+
ConditionMultisig = "condition-multisig",
|
|
257
|
+
CLTVMultisig = "cltv-multisig"
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* ArkTapscript is the base element of vtxo scripts.
|
|
261
|
+
* It is used to encode and decode the different types of vtxo scripts.
|
|
262
|
+
*/
|
|
263
|
+
interface ArkTapscript<T extends TapscriptType, Params> {
|
|
264
|
+
type: T;
|
|
265
|
+
params: Params;
|
|
266
|
+
script: Uint8Array;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* decodeTapscript is a function that decodes an Arkade tapscript from a raw script.
|
|
270
|
+
*
|
|
271
|
+
* @throws {Error} if the script is not a valid Arkade tapscript
|
|
272
|
+
* @example
|
|
273
|
+
* ```typescript
|
|
274
|
+
* const arkTapscript = decodeTapscript(new Uint8Array(32));
|
|
275
|
+
* console.log("type:", arkTapscript.type);
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
declare function decodeTapscript(script: Uint8Array): ArkTapscript<TapscriptType, any>;
|
|
279
|
+
/**
|
|
280
|
+
* Implements a multi-signature tapscript.
|
|
281
|
+
*
|
|
282
|
+
* <pubkey> CHECKSIGVERIFY <pubkey> CHECKSIG
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```typescript
|
|
286
|
+
* const multisigTapscript = MultisigTapscript.encode({ pubkeys: [new Uint8Array(32), new Uint8Array(32)] });
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
289
|
+
declare namespace MultisigTapscript {
|
|
290
|
+
type Type = ArkTapscript<TapscriptType.Multisig, Params>;
|
|
291
|
+
enum MultisigType {
|
|
292
|
+
CHECKSIG = 0,
|
|
293
|
+
CHECKSIGADD = 1
|
|
294
|
+
}
|
|
295
|
+
type Params = {
|
|
296
|
+
pubkeys: Bytes[];
|
|
297
|
+
type?: MultisigType;
|
|
298
|
+
};
|
|
299
|
+
/** Encode a plain multisig tapscript. */
|
|
300
|
+
function encode(params: Params): Type;
|
|
301
|
+
/** Decode a plain multisig tapscript from raw script bytes. */
|
|
302
|
+
function decode(script: Uint8Array): Type;
|
|
303
|
+
/** Return true when the tapscript is a plain multisig tapscript. */
|
|
304
|
+
function is(tapscript: ArkTapscript<any, any>): tapscript is Type;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Implements a relative timelock script that requires all specified pubkeys to sign
|
|
308
|
+
* after the relative timelock has expired. The timelock can be specified in blocks or seconds.
|
|
309
|
+
*
|
|
310
|
+
* This is the standard exit closure and it is also used for the sweep closure in vtxo trees.
|
|
311
|
+
*
|
|
312
|
+
* <sequence> CHECKSEQUENCEVERIFY DROP <pubkey> CHECKSIG
|
|
313
|
+
*
|
|
314
|
+
* @example
|
|
315
|
+
* ```typescript
|
|
316
|
+
* const csvMultisigTapscript = CSVMultisigTapscript.encode({ timelock: { type: "blocks", value: 144 }, pubkeys: [new Uint8Array(32), new Uint8Array(32)] });
|
|
317
|
+
* ```
|
|
318
|
+
*/
|
|
319
|
+
declare namespace CSVMultisigTapscript {
|
|
320
|
+
type Type = ArkTapscript<TapscriptType.CSVMultisig, Params>;
|
|
321
|
+
type Params = {
|
|
322
|
+
timelock: RelativeTimelock;
|
|
323
|
+
} & MultisigTapscript.Params;
|
|
324
|
+
/** Encode a CSV multisig tapscript. */
|
|
325
|
+
function encode(params: Params): Type;
|
|
326
|
+
/** Decode a CSV multisig tapscript from raw script bytes. */
|
|
327
|
+
function decode(script: Uint8Array): Type;
|
|
328
|
+
/** Return true when the tapscript is a CSV multisig tapscript. */
|
|
329
|
+
function is(tapscript: ArkTapscript<any, any>): tapscript is Type;
|
|
330
|
+
function isScriptValid(script: Uint8Array): true | Error;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Combines a condition script with an exit closure. The resulting script requires
|
|
334
|
+
* the condition to be met, followed by the standard exit closure requirements
|
|
335
|
+
* (timelock and signatures).
|
|
336
|
+
*
|
|
337
|
+
* <conditionScript> VERIFY <sequence> CHECKSEQUENCEVERIFY DROP <pubkey> CHECKSIGVERIFY <pubkey> CHECKSIG
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* ```typescript
|
|
341
|
+
* const conditionCSVMultisigTapscript = ConditionCSVMultisigTapscript.encode({ conditionScript: new Uint8Array(32), pubkeys: [new Uint8Array(32), new Uint8Array(32)] });
|
|
342
|
+
* ```
|
|
343
|
+
*/
|
|
344
|
+
declare namespace ConditionCSVMultisigTapscript {
|
|
345
|
+
type Type = ArkTapscript<TapscriptType.ConditionCSVMultisig, Params>;
|
|
346
|
+
type Params = {
|
|
347
|
+
conditionScript: Bytes;
|
|
348
|
+
} & CSVMultisigTapscript.Params;
|
|
349
|
+
/** Encode a condition + CSV multisig tapscript. */
|
|
350
|
+
function encode(params: Params): Type;
|
|
351
|
+
/** Decode a condition + CSV multisig tapscript from raw script bytes. */
|
|
352
|
+
function decode(script: Uint8Array): Type;
|
|
353
|
+
/** Return true when the tapscript is a condition + CSV multisig tapscript. */
|
|
354
|
+
function is(tapscript: ArkTapscript<any, any>): tapscript is Type;
|
|
355
|
+
function isScriptValid(script: Uint8Array): true | Error;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Combines a condition script with a forfeit closure. The resulting script requires
|
|
359
|
+
* the condition to be met, followed by the standard forfeit closure requirements
|
|
360
|
+
* (multi-signature).
|
|
361
|
+
*
|
|
362
|
+
* <conditionScript> VERIFY <pubkey> CHECKSIGVERIFY <pubkey> CHECKSIG
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* ```typescript
|
|
366
|
+
* const conditionMultisigTapscript = ConditionMultisigTapscript.encode({ conditionScript: new Uint8Array(32), pubkeys: [new Uint8Array(32), new Uint8Array(32)] });
|
|
367
|
+
* ```
|
|
368
|
+
*/
|
|
369
|
+
declare namespace ConditionMultisigTapscript {
|
|
370
|
+
type Type = ArkTapscript<TapscriptType.ConditionMultisig, Params>;
|
|
371
|
+
type Params = {
|
|
372
|
+
conditionScript: Bytes;
|
|
373
|
+
} & MultisigTapscript.Params;
|
|
374
|
+
/** Encode a condition + multisig tapscript. */
|
|
375
|
+
function encode(params: Params): Type;
|
|
376
|
+
/** Decode a condition + multisig tapscript from raw script bytes. */
|
|
377
|
+
function decode(script: Uint8Array): Type;
|
|
378
|
+
/** Return true when the tapscript is a condition + multisig tapscript. */
|
|
379
|
+
function is(tapscript: ArkTapscript<any, any>): tapscript is Type;
|
|
380
|
+
function isScriptValid(script: Uint8Array): true | Error;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Implements an absolute timelock (CLTV) script combined with a forfeit closure.
|
|
384
|
+
* The script requires waiting until a specific block height/timestamp before the
|
|
385
|
+
* forfeit closure conditions can be met.
|
|
386
|
+
*
|
|
387
|
+
* <locktime> CHECKLOCKTIMEVERIFY DROP <pubkey> CHECKSIGVERIFY <pubkey> CHECKSIG
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* ```typescript
|
|
391
|
+
* const cltvMultisigTapscript = CLTVMultisigTapscript.encode({ absoluteTimelock: 144, pubkeys: [new Uint8Array(32), new Uint8Array(32)] });
|
|
392
|
+
* ```
|
|
393
|
+
*/
|
|
394
|
+
declare namespace CLTVMultisigTapscript {
|
|
395
|
+
type Type = ArkTapscript<TapscriptType.CLTVMultisig, Params>;
|
|
396
|
+
type Params = {
|
|
397
|
+
absoluteTimelock: bigint;
|
|
398
|
+
} & MultisigTapscript.Params;
|
|
399
|
+
/** Encode a CLTV multisig tapscript. */
|
|
400
|
+
function encode(params: Params): Type;
|
|
401
|
+
/** Decode a CLTV multisig tapscript from raw script bytes. */
|
|
402
|
+
function decode(script: Uint8Array): Type;
|
|
403
|
+
/** Return true when the tapscript is a CLTV multisig tapscript. */
|
|
404
|
+
function is(tapscript: ArkTapscript<any, any>): tapscript is Type;
|
|
405
|
+
function isScriptValid(script: Uint8Array): true | Error;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
type TapLeafScript = [
|
|
409
|
+
{
|
|
410
|
+
version: number;
|
|
411
|
+
internalKey: Bytes;
|
|
412
|
+
merklePath: Bytes[];
|
|
413
|
+
},
|
|
414
|
+
Bytes
|
|
415
|
+
];
|
|
416
|
+
declare const TapTreeCoder: (typeof PSBTOutput.tapTree)[2];
|
|
417
|
+
/**
|
|
418
|
+
* VtxoScript is a script that contains a list of tapleaf scripts.
|
|
419
|
+
* It is used to create virtual output scripts.
|
|
420
|
+
*
|
|
421
|
+
* @see ArkAddress
|
|
422
|
+
*
|
|
423
|
+
* @example
|
|
424
|
+
* ```typescript
|
|
425
|
+
* const vtxoScript = new VtxoScript([new Uint8Array(32), new Uint8Array(32)]);
|
|
426
|
+
* ```
|
|
427
|
+
*/
|
|
428
|
+
declare class VtxoScript {
|
|
429
|
+
readonly scripts: Bytes[];
|
|
430
|
+
readonly leaves: TapLeafScript[];
|
|
431
|
+
readonly tweakedPublicKey: Bytes;
|
|
432
|
+
/**
|
|
433
|
+
* Decode a virtual output script from an encoded TapTree.
|
|
434
|
+
*
|
|
435
|
+
* @param tapTree - Encoded TapTree bytes
|
|
436
|
+
* @returns Decoded virtual output script
|
|
437
|
+
* @throws Error if the TapTree cannot be decoded into a valid script set
|
|
438
|
+
* @see encode
|
|
439
|
+
*/
|
|
440
|
+
static decode(tapTree: Bytes): VtxoScript;
|
|
441
|
+
/**
|
|
442
|
+
* Create a virtual output script from its tapleaf scripts.
|
|
443
|
+
*
|
|
444
|
+
* @param scripts - Raw tapscript bytes for each leaf
|
|
445
|
+
* @throws Error if the provided leaves cannot produce a valid Taproot tree
|
|
446
|
+
*/
|
|
447
|
+
constructor(scripts: Bytes[]);
|
|
448
|
+
/**
|
|
449
|
+
* Encode the virtual output script to a TapTree byte representation.
|
|
450
|
+
*
|
|
451
|
+
* @returns Encoded TapTree bytes
|
|
452
|
+
* @see decode
|
|
453
|
+
*/
|
|
454
|
+
encode(): Bytes;
|
|
455
|
+
/**
|
|
456
|
+
* Build the Arkade address corresponding to this virtual output script.
|
|
457
|
+
*
|
|
458
|
+
* @param prefix - Bech32 human-readable prefix
|
|
459
|
+
* @param serverPubKey - 32-byte Arkade server public key
|
|
460
|
+
* @returns Arkade address for this script
|
|
461
|
+
* @see ArkAddress
|
|
462
|
+
*/
|
|
463
|
+
address(prefix: string, serverPubKey: Bytes): ArkAddress;
|
|
464
|
+
get pkScript(): Bytes;
|
|
465
|
+
/**
|
|
466
|
+
* Build the Taproot onchain address corresponding to this virtual output script.
|
|
467
|
+
*
|
|
468
|
+
* @param network - Bitcoin network descriptor
|
|
469
|
+
* @returns Taproot onchain address
|
|
470
|
+
* @see address
|
|
471
|
+
*/
|
|
472
|
+
onchainAddress(network: typeof NETWORK): string;
|
|
473
|
+
/**
|
|
474
|
+
* Look up a tapleaf script by its hex-encoded tapscript body.
|
|
475
|
+
*
|
|
476
|
+
* @param scriptHex - Hex-encoded tapscript body without the leaf version byte
|
|
477
|
+
* @returns Matching tapleaf script
|
|
478
|
+
* @throws Error if no matching leaf exists
|
|
479
|
+
*/
|
|
480
|
+
findLeaf(scriptHex: string): TapLeafScript;
|
|
481
|
+
/**
|
|
482
|
+
* Return all unilateral exit paths embedded in the virtual output script.
|
|
483
|
+
*
|
|
484
|
+
* @returns CSV-based exit paths found in the leaves
|
|
485
|
+
* @see getSequence
|
|
486
|
+
*/
|
|
487
|
+
exitPaths(): Array<CSVMultisigTapscript.Type | ConditionCSVMultisigTapscript.Type>;
|
|
488
|
+
}
|
|
489
|
+
type EncodedVtxoScript = {
|
|
490
|
+
tapTree: Bytes;
|
|
491
|
+
};
|
|
492
|
+
/**
|
|
493
|
+
* Extract the timelock value encoded in a timelocked tapleaf, if any.
|
|
494
|
+
*
|
|
495
|
+
* The return value is unit-ambiguous: for a CSV leaf it is a BIP-68
|
|
496
|
+
* nSequence (relative timelock); for a CLTV leaf it is an absolute
|
|
497
|
+
* nLockTime. Callers must know which leaf shape they are inspecting to
|
|
498
|
+
* interpret the number correctly, and must not copy a CSV result into
|
|
499
|
+
* `Transaction.lockTime` (or vice versa).
|
|
500
|
+
*
|
|
501
|
+
* @param tapLeafScript - Tapleaf script to inspect
|
|
502
|
+
* @returns The encoded timelock value, or `undefined` when neither a CSV
|
|
503
|
+
* nor CLTV path is present
|
|
504
|
+
* @see VtxoScript.exitPaths
|
|
505
|
+
*/
|
|
506
|
+
declare function getSequence(tapLeafScript: TapLeafScript): number | undefined;
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Configuration options for automatic virtual output renewal
|
|
510
|
+
*
|
|
511
|
+
* @see DEFAULT_RENEWAL_CONFIG
|
|
512
|
+
* @deprecated Leave `renewalConfig` undefined and use `settlementConfig` instead.
|
|
513
|
+
* @see SettlementConfig
|
|
514
|
+
*/
|
|
515
|
+
interface RenewalConfig {
|
|
516
|
+
/**
|
|
517
|
+
* Enable automatic renewal monitoring
|
|
518
|
+
*
|
|
519
|
+
* @defaultValue `false`
|
|
520
|
+
* @deprecated Explicitly set `settlementConfig` to `false` to disable VTXO renewal.
|
|
521
|
+
*/
|
|
522
|
+
enabled?: boolean;
|
|
523
|
+
/**
|
|
524
|
+
* Threshold in milliseconds to use as threshold for renewal
|
|
525
|
+
* E.g., 86_400_000 means renew when 24 hours until expiry remains
|
|
526
|
+
*
|
|
527
|
+
* @defaultValue `259_200_000` (3 days).
|
|
528
|
+
* @deprecated Use `SettlementConfig.vtxoThreshold` (in seconds) instead.
|
|
529
|
+
*/
|
|
530
|
+
thresholdMs?: number;
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Configuration for automatic settlement and renewal.
|
|
534
|
+
*
|
|
535
|
+
* Controls two behaviors:
|
|
536
|
+
* 1. **VTXO renewal**: Automatically renew virtual outputs that are close to expiry
|
|
537
|
+
* 2. **Boarding UTXO sweep**: Sweep expired boarding inputs back to a fresh boarding address
|
|
538
|
+
* via the unilateral exit path (onchain self-spend to restart the timelock)
|
|
539
|
+
*
|
|
540
|
+
* Enabled by default when no config is provided.
|
|
541
|
+
* Pass `false` to explicitly disable all settlement behavior.
|
|
542
|
+
*
|
|
543
|
+
* @remarks
|
|
544
|
+
* VTXO renewal and boarding UTXO sweep are both coordinated by `VtxoManager`, which periodically
|
|
545
|
+
* inspects wallet virtual outputs and boarding inputs and decides whether action is needed.
|
|
546
|
+
*
|
|
547
|
+
* @see DEFAULT_SETTLEMENT_CONFIG
|
|
548
|
+
*
|
|
549
|
+
* @example
|
|
550
|
+
* ```typescript
|
|
551
|
+
* // Default behavior: virtual output renewal at 3 days, boarding sweep enabled, polling every minute
|
|
552
|
+
* const wallet = await Wallet.create({
|
|
553
|
+
* identity: MnemonicIdentity.fromMnemonic('abandon abandon...'),
|
|
554
|
+
* arkServerUrl: 'https://arkade.computer',
|
|
555
|
+
* });
|
|
556
|
+
*
|
|
557
|
+
* // Custom expiry threshold of 24 hours
|
|
558
|
+
* const wallet = await Wallet.create({
|
|
559
|
+
* identity: MnemonicIdentity.fromMnemonic('abandon abandon...'),
|
|
560
|
+
* arkServerUrl: 'https://arkade.computer',
|
|
561
|
+
* settlementConfig: {
|
|
562
|
+
* vtxoThreshold: 60 * 60 * 24, // 24 hours in seconds
|
|
563
|
+
* },
|
|
564
|
+
* });
|
|
565
|
+
*
|
|
566
|
+
* // Explicitly disable
|
|
567
|
+
* const wallet = await Wallet.create({
|
|
568
|
+
* identity: MnemonicIdentity.fromMnemonic('abandon abandon...'),
|
|
569
|
+
* arkServerUrl: 'https://arkade.computer',
|
|
570
|
+
* settlementConfig: false,
|
|
571
|
+
* });
|
|
572
|
+
* ```
|
|
573
|
+
*/
|
|
574
|
+
interface SettlementConfig {
|
|
575
|
+
/**
|
|
576
|
+
* Seconds before virtual output expiry to trigger renewal.
|
|
577
|
+
*
|
|
578
|
+
* @defaultValue `259_200` (3 days)
|
|
579
|
+
*/
|
|
580
|
+
vtxoThreshold?: number;
|
|
581
|
+
/**
|
|
582
|
+
* Sweep expired boarding inputs back to a fresh boarding address
|
|
583
|
+
* via the unilateral exit path (onchain self-spend to restart the timelock).
|
|
584
|
+
*
|
|
585
|
+
* When enabled, expired boarding inputs are batched into a single onchain
|
|
586
|
+
* transaction with multiple inputs and one output.
|
|
587
|
+
*
|
|
588
|
+
* A dust check ensures the sweep is only performed when the output
|
|
589
|
+
* after fees is above dust.
|
|
590
|
+
*
|
|
591
|
+
* @defaultValue `true`
|
|
592
|
+
*/
|
|
593
|
+
boardingUtxoSweep?: boolean;
|
|
594
|
+
/**
|
|
595
|
+
* Polling interval in milliseconds for checking boarding inputs.
|
|
596
|
+
* The poll loop auto-settles new boarding inputs into Arkade and
|
|
597
|
+
* sweeps expired ones (when boardingUtxoSweep is enabled).
|
|
598
|
+
*
|
|
599
|
+
* @defaultValue `60_000` (1 minute)
|
|
600
|
+
*/
|
|
601
|
+
pollIntervalMs?: number;
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Check if a virtual output is expiring soon based on threshold
|
|
605
|
+
*
|
|
606
|
+
* @param vtxo - The virtual output to check
|
|
607
|
+
* @param thresholdMs - Threshold in milliseconds from now
|
|
608
|
+
* @returns true if virtual output expires within threshold, false otherwise
|
|
609
|
+
*/
|
|
610
|
+
declare function isVtxoExpiringSoon(vtxo: ExtendedVirtualCoin, thresholdMs: number): boolean;
|
|
611
|
+
/**
|
|
612
|
+
* VtxoManager is a unified class for managing virtual output lifecycle operations including
|
|
613
|
+
* recovery of swept/expired virtual outputs and renewal to prevent expiration.
|
|
614
|
+
*
|
|
615
|
+
* Key Features:
|
|
616
|
+
* - **Recovery**: Reclaim swept or expired virtual outputs back to the wallet
|
|
617
|
+
* - **Renewal**: Refresh virtual output expiration time before they expire
|
|
618
|
+
* - **Smart subdust handling**: Automatically includes subdust virtual outputs when economically viable
|
|
619
|
+
* - **Expiry monitoring**: Check for virtual outputs that are expiring soon
|
|
620
|
+
*
|
|
621
|
+
* Virtual outputs become recoverable when:
|
|
622
|
+
* - The Arkade server sweeps them (virtualStatus.state === "swept") and they remain spendable
|
|
623
|
+
* - They are preconfirmed subdust (to consolidate small amounts without locking liquidity on settled virtual outputs)
|
|
624
|
+
*
|
|
625
|
+
* @example
|
|
626
|
+
* ```typescript
|
|
627
|
+
* const wallet = await Wallet.create({
|
|
628
|
+
* identity,
|
|
629
|
+
* arkServerUrl: 'https://arkade.computer',
|
|
630
|
+
* settlementConfig: {
|
|
631
|
+
* // Seconds before virtual output expiry to trigger renewal
|
|
632
|
+
* vtxoThreshold: 259_200, // 3 days
|
|
633
|
+
* // Whether to sweep expired boarding inputs back to a fresh boarding address
|
|
634
|
+
* boardingUtxoSweep: true,
|
|
635
|
+
* // Polling interval in milliseconds for checking boarding inputs
|
|
636
|
+
* pollIntervalMs: 60_000 // 1 minute
|
|
637
|
+
* },
|
|
638
|
+
* });
|
|
639
|
+
* const manager = await wallet.getVtxoManager();
|
|
640
|
+
*
|
|
641
|
+
* // Check recoverable balance
|
|
642
|
+
* const balance = await manager.getRecoverableBalance();
|
|
643
|
+
* if (balance.recoverable > 0n) {
|
|
644
|
+
* console.log(`Can recover ${balance.recoverable} sats`);
|
|
645
|
+
* const txid = await manager.recoverVtxos();
|
|
646
|
+
* }
|
|
647
|
+
*
|
|
648
|
+
* // Check for expiring virtual outputs
|
|
649
|
+
* const expiring = await manager.getExpiringVtxos();
|
|
650
|
+
* if (expiring.length > 0) {
|
|
651
|
+
* console.log(`${expiring.length} virtual outputs expiring soon`);
|
|
652
|
+
* const txid = await manager.renewVtxos();
|
|
653
|
+
* }
|
|
654
|
+
* ```
|
|
655
|
+
*/
|
|
656
|
+
interface IVtxoManager {
|
|
657
|
+
recoverVtxos(eventCallback?: (event: SettlementEvent) => void): Promise<string>;
|
|
658
|
+
getRecoverableBalance(): Promise<{
|
|
659
|
+
recoverable: bigint;
|
|
660
|
+
subdust: bigint;
|
|
661
|
+
includesSubdust: boolean;
|
|
662
|
+
vtxoCount: number;
|
|
663
|
+
}>;
|
|
664
|
+
getExpiringVtxos(thresholdMs?: number): Promise<ExtendedVirtualCoin[]>;
|
|
665
|
+
renewVtxos(eventCallback?: (event: SettlementEvent) => void): Promise<string>;
|
|
666
|
+
getExpiredBoardingUtxos(): Promise<ExtendedCoin[]>;
|
|
667
|
+
sweepExpiredBoardingUtxos(): Promise<string>;
|
|
668
|
+
dispose(): Promise<void>;
|
|
669
|
+
}
|
|
670
|
+
declare class VtxoManager implements AsyncDisposable, IVtxoManager {
|
|
671
|
+
readonly wallet: IWallet;
|
|
672
|
+
/** @deprecated Use settlementConfig instead */
|
|
673
|
+
readonly renewalConfig?: RenewalConfig | undefined;
|
|
674
|
+
readonly settlementConfig: SettlementConfig | false;
|
|
675
|
+
private contractEventsSubscription?;
|
|
676
|
+
private readonly contractEventsSubscriptionReady;
|
|
677
|
+
private disposePromise?;
|
|
678
|
+
private pollTimeoutId?;
|
|
679
|
+
private knownBoardingUtxos;
|
|
680
|
+
private sweptBoardingUtxos;
|
|
681
|
+
private pollInProgress;
|
|
682
|
+
private pollDone?;
|
|
683
|
+
private disposed;
|
|
684
|
+
private consecutivePollFailures;
|
|
685
|
+
private startupPollTimeoutId?;
|
|
686
|
+
private static readonly MAX_BACKOFF_MS;
|
|
687
|
+
private renewalInProgress;
|
|
688
|
+
private lastRenewalTimestamp;
|
|
689
|
+
private static readonly RENEWAL_COOLDOWN_MS;
|
|
690
|
+
private lastPeriodicSettleTimestamp;
|
|
691
|
+
private consecutivePeriodicSettleFailures;
|
|
692
|
+
private static readonly PERIODIC_SETTLE_COOLDOWN_MS;
|
|
693
|
+
private static readonly PERIODIC_SETTLE_MAX_BACKOFF_MS;
|
|
694
|
+
private lastVtxoSpentRefreshTimestamp;
|
|
695
|
+
private vtxoSpentRefreshPromise?;
|
|
696
|
+
private static readonly VTXO_SPENT_REFRESH_COOLDOWN_MS;
|
|
697
|
+
constructor(wallet: IWallet,
|
|
698
|
+
/** @deprecated Use settlementConfig instead */
|
|
699
|
+
renewalConfig?: RenewalConfig | undefined, settlementConfig?: SettlementConfig | false);
|
|
700
|
+
/**
|
|
701
|
+
* Recover swept/expired virtual outputs by settling them back to the wallet's Arkade address.
|
|
702
|
+
*
|
|
703
|
+
* This method:
|
|
704
|
+
* 1. Fetches all virtual outputs (including recoverable ones)
|
|
705
|
+
* 2. Filters for swept but still spendable virtual outputs and preconfirmed subdust
|
|
706
|
+
* 3. Includes subdust virtual outputs if the total value >= dust threshold
|
|
707
|
+
* 4. Settles everything back to the wallet's Arkade address
|
|
708
|
+
*
|
|
709
|
+
* Note: Settled virtual outputs with long expiry are NOT recovered to avoid locking liquidity unnecessarily.
|
|
710
|
+
* Only preconfirmed subdust is recovered to consolidate small amounts.
|
|
711
|
+
*
|
|
712
|
+
* @param eventCallback - Optional callback to receive settlement events
|
|
713
|
+
* @returns Settlement transaction ID
|
|
714
|
+
* @throws Error if no recoverable virtual outputs found
|
|
715
|
+
*
|
|
716
|
+
* @example
|
|
717
|
+
* ```typescript
|
|
718
|
+
* const manager = await wallet.getVtxoManager();
|
|
719
|
+
*
|
|
720
|
+
* // Simple recovery
|
|
721
|
+
* const txid = await manager.recoverVtxos();
|
|
722
|
+
*
|
|
723
|
+
* // With event callback
|
|
724
|
+
* const txid = await manager.recoverVtxos((event) => {
|
|
725
|
+
* console.log('Settlement event:', event.type);
|
|
726
|
+
* });
|
|
727
|
+
* ```
|
|
728
|
+
*/
|
|
729
|
+
recoverVtxos(eventCallback?: (event: SettlementEvent) => void): Promise<string>;
|
|
730
|
+
/**
|
|
731
|
+
* Get information about recoverable balance without executing recovery.
|
|
732
|
+
*
|
|
733
|
+
* Useful for displaying to users before they decide to recover funds.
|
|
734
|
+
*
|
|
735
|
+
* @returns Object containing recoverable amounts and subdust information
|
|
736
|
+
*
|
|
737
|
+
* @example
|
|
738
|
+
* ```typescript
|
|
739
|
+
* const manager = await wallet.getVtxoManager();
|
|
740
|
+
* const balance = await manager.getRecoverableBalance();
|
|
741
|
+
*
|
|
742
|
+
* if (balance.recoverable > 0n) {
|
|
743
|
+
* console.log(`You can recover ${balance.recoverable} sats`);
|
|
744
|
+
* if (balance.includesSubdust) {
|
|
745
|
+
* console.log(`This includes ${balance.subdust} sats from subdust virtual outputs`);
|
|
746
|
+
* }
|
|
747
|
+
* }
|
|
748
|
+
* ```
|
|
749
|
+
*/
|
|
750
|
+
getRecoverableBalance(): Promise<{
|
|
751
|
+
recoverable: bigint;
|
|
752
|
+
subdust: bigint;
|
|
753
|
+
includesSubdust: boolean;
|
|
754
|
+
vtxoCount: number;
|
|
755
|
+
}>;
|
|
756
|
+
/**
|
|
757
|
+
* Get virtual outputs that are expiring soon based on renewal configuration
|
|
758
|
+
*
|
|
759
|
+
* @param thresholdMs - Optional override for threshold in milliseconds
|
|
760
|
+
* @returns Array of expiring virtual outputs, empty array if renewal is disabled or no virtual outputs expiring
|
|
761
|
+
*
|
|
762
|
+
* @example
|
|
763
|
+
* ```typescript
|
|
764
|
+
* const wallet = await Wallet.create({
|
|
765
|
+
* identity,
|
|
766
|
+
* arkServerUrl: 'https://arkade.computer',
|
|
767
|
+
* settlementConfig: {
|
|
768
|
+
* vtxoThreshold: 86_400 // 24 hours
|
|
769
|
+
* },
|
|
770
|
+
* });
|
|
771
|
+
* const manager = await wallet.getVtxoManager();
|
|
772
|
+
* const expiringVtxos = await manager.getExpiringVtxos();
|
|
773
|
+
* if (expiringVtxos.length > 0) {
|
|
774
|
+
* console.log(`${expiringVtxos.length} virtual outputs expiring soon`);
|
|
775
|
+
* }
|
|
776
|
+
* ```
|
|
777
|
+
*/
|
|
778
|
+
getExpiringVtxos(thresholdMs?: number): Promise<ExtendedVirtualCoin[]>;
|
|
779
|
+
/**
|
|
780
|
+
* Renew expiring virtual outputs by settling them back to the wallet's address
|
|
781
|
+
*
|
|
782
|
+
* This method collects all expiring spendable virtual outputs (including recoverable ones) and settles
|
|
783
|
+
* them back to the wallet, effectively refreshing their expiration time. This is the
|
|
784
|
+
* primary way to prevent virtual outputs from expiring.
|
|
785
|
+
*
|
|
786
|
+
* @param eventCallback - Optional callback for settlement events
|
|
787
|
+
* @returns Settlement transaction ID
|
|
788
|
+
* @throws Error if no virtual outputs available to renew
|
|
789
|
+
* @throws Error if total amount is below dust threshold
|
|
790
|
+
*
|
|
791
|
+
* @example
|
|
792
|
+
* ```typescript
|
|
793
|
+
* const manager = await wallet.getVtxoManager();
|
|
794
|
+
*
|
|
795
|
+
* // Simple renewal
|
|
796
|
+
* const txid = await manager.renewVtxos();
|
|
797
|
+
*
|
|
798
|
+
* // With event callback
|
|
799
|
+
* const txid = await manager.renewVtxos((event) => {
|
|
800
|
+
* console.log('Settlement event:', event.type);
|
|
801
|
+
* });
|
|
802
|
+
* ```
|
|
803
|
+
*/
|
|
804
|
+
renewVtxos(eventCallback?: (event: SettlementEvent) => void): Promise<string>;
|
|
805
|
+
/**
|
|
806
|
+
* Get boarding inputs whose timelock has expired.
|
|
807
|
+
*
|
|
808
|
+
* These inputs can no longer be onboarded cooperatively via `settle()` and
|
|
809
|
+
* must be swept back to a fresh boarding address using the unilateral exit path.
|
|
810
|
+
*
|
|
811
|
+
* @returns Array of expired boarding inputs
|
|
812
|
+
*
|
|
813
|
+
* @example
|
|
814
|
+
* ```typescript
|
|
815
|
+
* const manager = await wallet.getVtxoManager();
|
|
816
|
+
* const expired = await manager.getExpiredBoardingUtxos();
|
|
817
|
+
* if (expired.length > 0) {
|
|
818
|
+
* console.log(`${expired.length} expired boarding inputs to sweep`);
|
|
819
|
+
* }
|
|
820
|
+
* ```
|
|
821
|
+
*/
|
|
822
|
+
getExpiredBoardingUtxos(prefetchedUtxos?: ExtendedCoin[]): Promise<ExtendedCoin[]>;
|
|
823
|
+
/**
|
|
824
|
+
* Sweep expired boarding inputs back to a fresh boarding address via
|
|
825
|
+
* the unilateral exit path (onchain self-spend).
|
|
826
|
+
*
|
|
827
|
+
* This builds a raw onchain transaction that:
|
|
828
|
+
* - Uses all expired boarding inputs as inputs (spent via the CSV exit script path)
|
|
829
|
+
* - Has a single output to the wallet's boarding address (restarts the timelock)
|
|
830
|
+
* - Batches multiple expired boarding inputs into one transaction
|
|
831
|
+
* - Skips the sweep if the output after fees would be below dust
|
|
832
|
+
*
|
|
833
|
+
* No Arkade server involvement is needed — this is a pure onchain transaction.
|
|
834
|
+
*
|
|
835
|
+
* @returns The broadcast transaction ID
|
|
836
|
+
* @throws Error if no expired boarding inputs are found
|
|
837
|
+
* @throws Error if output after fees is below dust (not economical to sweep)
|
|
838
|
+
* @throws Error if boarding input sweep is not enabled in settlementConfig
|
|
839
|
+
*
|
|
840
|
+
* @example
|
|
841
|
+
* ```typescript
|
|
842
|
+
* const wallet = await Wallet.create({
|
|
843
|
+
* identity,
|
|
844
|
+
* arkServerUrl: 'https://arkade.computer',
|
|
845
|
+
* settlementConfig: {
|
|
846
|
+
* boardingUtxoSweep: true,
|
|
847
|
+
* },
|
|
848
|
+
* });
|
|
849
|
+
* const manager = await wallet.getVtxoManager();
|
|
850
|
+
*
|
|
851
|
+
* try {
|
|
852
|
+
* const txid = await manager.sweepExpiredBoardingUtxos();
|
|
853
|
+
* console.log('Swept expired boarding inputs:', txid);
|
|
854
|
+
* } catch (e) {
|
|
855
|
+
* console.log('No sweep needed or not economical');
|
|
856
|
+
* }
|
|
857
|
+
* ```
|
|
858
|
+
*/
|
|
859
|
+
sweepExpiredBoardingUtxos(prefetchedUtxos?: ExtendedCoin[]): Promise<string>;
|
|
860
|
+
/** Asserts sweep capability and returns the typed wallet. */
|
|
861
|
+
private getSweepWallet;
|
|
862
|
+
/** Decodes the boarding tapscript exit path to extract the CSV timelock. */
|
|
863
|
+
private getBoardingTimelock;
|
|
864
|
+
/** Returns the TapLeafScript for the boarding tapscript's exit (CSV) path. */
|
|
865
|
+
private getBoardingExitLeaf;
|
|
866
|
+
/** Returns the pkScript (output script) of the boarding tapscript. */
|
|
867
|
+
private getBoardingOutputScript;
|
|
868
|
+
/** Returns the onchain provider for fee estimation and broadcasting. */
|
|
869
|
+
private getOnchainProvider;
|
|
870
|
+
/** Returns the Ark provider for intent fee and server info lookups. */
|
|
871
|
+
private getArkProvider;
|
|
872
|
+
/** Returns the Bitcoin network configuration from the wallet. */
|
|
873
|
+
private getNetwork;
|
|
874
|
+
/** Returns the wallet's identity for transaction signing. */
|
|
875
|
+
private getIdentity;
|
|
876
|
+
private initializeSubscription;
|
|
877
|
+
/**
|
|
878
|
+
* VTXO_ALREADY_SPENT means the server's authoritative view of VTXO state
|
|
879
|
+
* is ahead of ours — cross-instance race, pre-lock snapshot drift, or an
|
|
880
|
+
* SSE gap left stale data in the local cache. Silent-swallowing
|
|
881
|
+
* guarantees the same error on the next cycle because nothing
|
|
882
|
+
* reconciles the cache.
|
|
883
|
+
*
|
|
884
|
+
* The cursor-derived delta sync filters by `created_at`, so a VTXO that
|
|
885
|
+
* was created before the cursor but spent recently can never be
|
|
886
|
+
* reconciled by `refreshVtxos()`. Use `refreshOutpoints` for surgical
|
|
887
|
+
* recovery: query the indexer for the specific stale outpoint and
|
|
888
|
+
* upsert its authoritative state into the wallet repository.
|
|
889
|
+
*
|
|
890
|
+
* Throttled because the same VTXO can fire repeatedly before the
|
|
891
|
+
* upsert observably propagates through the renewal selector.
|
|
892
|
+
*/
|
|
893
|
+
private maybeRefreshAfterVtxoSpent;
|
|
894
|
+
/**
|
|
895
|
+
* Extract the offending VTXO outpoint from a `VTXO_ALREADY_SPENT` error,
|
|
896
|
+
* if the server attached one in `metadata.vtxo_outpoint`. Returns
|
|
897
|
+
* `undefined` when the error isn't a parsed ArkError, isn't this code,
|
|
898
|
+
* or doesn't carry the metadata.
|
|
899
|
+
*/
|
|
900
|
+
private extractSpentOutpoint;
|
|
901
|
+
/**
|
|
902
|
+
* Reconcile the chosen VTXOs with the indexer's authoritative state
|
|
903
|
+
* before submitting a settle intent. Pulls the canonical record for
|
|
904
|
+
* each candidate outpoint via {@link IContractManager.refreshOutpoints}
|
|
905
|
+
* (which upserts the result into the wallet repository), then
|
|
906
|
+
* re-selects through the standard expiring-vtxo filter so anything
|
|
907
|
+
* the refresh flagged as spent is dropped.
|
|
908
|
+
*
|
|
909
|
+
* Best-effort: a failed refresh just falls back to the original
|
|
910
|
+
* candidates and lets the post-submit `VTXO_ALREADY_SPENT` recovery
|
|
911
|
+
* handle whatever slipped through.
|
|
912
|
+
*/
|
|
913
|
+
private revalidateBeforeSettle;
|
|
914
|
+
/** Computes the next poll delay, applying exponential backoff on failures. */
|
|
915
|
+
private getNextPollDelay;
|
|
916
|
+
/**
|
|
917
|
+
* Starts a polling loop that:
|
|
918
|
+
* 1. Auto-settles new boarding inputs into Arkade
|
|
919
|
+
* 2. Sweeps expired boarding inputs (when boardingUtxoSweep is enabled)
|
|
920
|
+
*
|
|
921
|
+
* Uses setTimeout chaining (not setInterval) so a slow/blocked poll
|
|
922
|
+
* cannot stack up and the next delay can incorporate backoff.
|
|
923
|
+
*/
|
|
924
|
+
private startBoardingUtxoPoll;
|
|
925
|
+
private schedulePoll;
|
|
926
|
+
private pollBoardingUtxos;
|
|
927
|
+
/**
|
|
928
|
+
* Auto-settle new (unexpired) boarding inputs AND near-expiry VTXOs into
|
|
929
|
+
* Arkade in a single intent. Skips boarding UTXOs that are already expired
|
|
930
|
+
* (those are handled by sweep) and those already in-flight (tracked in
|
|
931
|
+
* knownBoardingUtxos). If the event-driven renewal path is currently
|
|
932
|
+
* running, VTXOs are omitted from this cycle to avoid double-spending.
|
|
933
|
+
*
|
|
934
|
+
* Failure bookkeeping: after every settle *attempt*, lastPeriodicSettleTimestamp
|
|
935
|
+
* is armed and consecutive failures are counted so the next attempt is
|
|
936
|
+
* blocked by an exponentially growing cooldown (capped). This stops a
|
|
937
|
+
* persistently failing input from producing identical RegisterIntent +
|
|
938
|
+
* DeleteIntent retries on every 60s poll.
|
|
939
|
+
*/
|
|
940
|
+
private runPeriodicSettle;
|
|
941
|
+
dispose(): Promise<void>;
|
|
942
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
type NetworkName = "bitcoin" | "testnet" | "signet" | "mutinynet" | "regtest";
|
|
946
|
+
interface Network {
|
|
947
|
+
hrp: string;
|
|
948
|
+
bech32: string;
|
|
949
|
+
pubKeyHash: number;
|
|
950
|
+
scriptHash: number;
|
|
951
|
+
wif: number;
|
|
952
|
+
}
|
|
953
|
+
declare const networks: {
|
|
954
|
+
bitcoin: Network;
|
|
955
|
+
testnet: Network;
|
|
956
|
+
signet: Network;
|
|
957
|
+
mutinynet: Network;
|
|
958
|
+
regtest: Network;
|
|
959
|
+
};
|
|
960
|
+
|
|
961
|
+
/**
|
|
962
|
+
* The default base URLs for esplora API providers.
|
|
963
|
+
*
|
|
964
|
+
* Mainnet, mutinynet, and signet point at Ark Labs–operated
|
|
965
|
+
* mempool deployments (mempool.space-compatible esplora API).
|
|
966
|
+
* Testnet falls back to the public mempool.space deployment
|
|
967
|
+
* because Ark doesn't host it. Regtest assumes a local nigiri
|
|
968
|
+
* stack on the standard port.
|
|
969
|
+
*/
|
|
970
|
+
declare const ESPLORA_URL: Record<NetworkName, string>;
|
|
971
|
+
type ExplorerTransaction = {
|
|
972
|
+
txid: string;
|
|
973
|
+
vout: {
|
|
974
|
+
scriptpubkey_address: string;
|
|
975
|
+
value: string;
|
|
976
|
+
}[];
|
|
977
|
+
status: {
|
|
978
|
+
confirmed: boolean;
|
|
979
|
+
block_time: number;
|
|
980
|
+
};
|
|
981
|
+
};
|
|
982
|
+
interface OnchainProvider {
|
|
983
|
+
/**
|
|
984
|
+
* Fetch spendable onchain outputs for an address.
|
|
985
|
+
*
|
|
986
|
+
* @param address - Bitcoin address to query
|
|
987
|
+
* @returns Spendable onchain outputs for the address
|
|
988
|
+
* @see Coin
|
|
989
|
+
*/
|
|
990
|
+
getCoins(address: string): Promise<Coin[]>;
|
|
991
|
+
/**
|
|
992
|
+
* Fetch the current fastest fee rate estimate.
|
|
993
|
+
*
|
|
994
|
+
* @returns Fee rate in sats/vB, if available
|
|
995
|
+
* @remarks
|
|
996
|
+
* Implementations may return `undefined` when the backing service does not expose
|
|
997
|
+
* a usable fee estimate.
|
|
998
|
+
*/
|
|
999
|
+
getFeeRate(): Promise<number | undefined>;
|
|
1000
|
+
/**
|
|
1001
|
+
* Broadcast a single transaction or a 1P1C package.
|
|
1002
|
+
*
|
|
1003
|
+
* @param txs - One or more raw transaction hex strings
|
|
1004
|
+
* @returns Broadcast transaction id
|
|
1005
|
+
* @throws Error if the broadcast request fails or the package shape is invalid
|
|
1006
|
+
*/
|
|
1007
|
+
broadcastTransaction(...txs: string[]): Promise<string>;
|
|
1008
|
+
/**
|
|
1009
|
+
* Fetch outspend information for every output in a transaction.
|
|
1010
|
+
*
|
|
1011
|
+
* @param txid - Transaction id to inspect
|
|
1012
|
+
* @returns Per-output spend status information
|
|
1013
|
+
* @see getTxStatus
|
|
1014
|
+
*/
|
|
1015
|
+
getTxOutspends(txid: string): Promise<{
|
|
1016
|
+
spent: boolean;
|
|
1017
|
+
txid: string;
|
|
1018
|
+
}[]>;
|
|
1019
|
+
/**
|
|
1020
|
+
* Fetch transactions associated with an address.
|
|
1021
|
+
*
|
|
1022
|
+
* @param address - Bitcoin address to query
|
|
1023
|
+
* @returns Transactions involving the address
|
|
1024
|
+
* @see ExplorerTransaction
|
|
1025
|
+
*/
|
|
1026
|
+
getTransactions(address: string): Promise<ExplorerTransaction[]>;
|
|
1027
|
+
/**
|
|
1028
|
+
* Fetch confirmation status for a transaction.
|
|
1029
|
+
*
|
|
1030
|
+
* @param txid - Transaction id to inspect
|
|
1031
|
+
* @returns Confirmation status and block metadata when confirmed
|
|
1032
|
+
* @see getTxOutspends
|
|
1033
|
+
*/
|
|
1034
|
+
getTxStatus(txid: string): Promise<{
|
|
1035
|
+
confirmed: false;
|
|
1036
|
+
} | {
|
|
1037
|
+
confirmed: true;
|
|
1038
|
+
blockTime: number;
|
|
1039
|
+
blockHeight: number;
|
|
1040
|
+
}>;
|
|
1041
|
+
/**
|
|
1042
|
+
* Fetch the current chain tip.
|
|
1043
|
+
*
|
|
1044
|
+
* @returns Current chain height, block time, and block hash
|
|
1045
|
+
*/
|
|
1046
|
+
getChainTip(): Promise<{
|
|
1047
|
+
height: number;
|
|
1048
|
+
time: number;
|
|
1049
|
+
hash: string;
|
|
1050
|
+
}>;
|
|
1051
|
+
/**
|
|
1052
|
+
* Watch a set of addresses and invoke the callback when transactions are observed.
|
|
1053
|
+
*
|
|
1054
|
+
* @param addresses - Addresses to monitor
|
|
1055
|
+
* @param eventCallback - Callback invoked when matching transactions are seen
|
|
1056
|
+
* @returns Stop function that cancels the watch
|
|
1057
|
+
* @remarks
|
|
1058
|
+
* Implementations may use websockets, server-sent events, polling, or a hybrid strategy.
|
|
1059
|
+
* @see getTransactions
|
|
1060
|
+
*/
|
|
1061
|
+
watchAddresses(addresses: string[], eventCallback: (txs: ExplorerTransaction[]) => void): Promise<() => void>;
|
|
1062
|
+
}
|
|
1063
|
+
/**
|
|
1064
|
+
* Implementation of the onchain provider interface for esplora REST API.
|
|
1065
|
+
*
|
|
1066
|
+
* @see https://mempool.space/docs/api/rest
|
|
1067
|
+
* @example
|
|
1068
|
+
* ```typescript
|
|
1069
|
+
* const provider = new EsploraProvider("https://mempool.space/api");
|
|
1070
|
+
* const outputs = await provider.getCoins("bcrt1q679zsd45msawvr7782r0twvmukns3drlstjt77");
|
|
1071
|
+
* ```
|
|
1072
|
+
*/
|
|
1073
|
+
declare class EsploraProvider implements OnchainProvider {
|
|
1074
|
+
private baseUrl;
|
|
1075
|
+
readonly pollingInterval: number;
|
|
1076
|
+
readonly forcePolling: boolean;
|
|
1077
|
+
constructor(baseUrl: string, opts?: {
|
|
1078
|
+
/** Polling interval in milliseconds. */
|
|
1079
|
+
pollingInterval?: number;
|
|
1080
|
+
/** Force polling even when websocket transport is available. */
|
|
1081
|
+
forcePolling?: boolean;
|
|
1082
|
+
});
|
|
1083
|
+
getCoins(address: string): Promise<Coin[]>;
|
|
1084
|
+
getFeeRate(): Promise<number | undefined>;
|
|
1085
|
+
broadcastTransaction(...txs: string[]): Promise<string>;
|
|
1086
|
+
getTxOutspends(txid: string): Promise<{
|
|
1087
|
+
spent: boolean;
|
|
1088
|
+
txid: string;
|
|
1089
|
+
}[]>;
|
|
1090
|
+
getTransactions(address: string): Promise<ExplorerTransaction[]>;
|
|
1091
|
+
getTxStatus(txid: string): Promise<{
|
|
1092
|
+
confirmed: false;
|
|
1093
|
+
} | {
|
|
1094
|
+
confirmed: true;
|
|
1095
|
+
blockTime: number;
|
|
1096
|
+
blockHeight: number;
|
|
1097
|
+
}>;
|
|
1098
|
+
watchAddresses(addresses: string[], callback: (txs: ExplorerTransaction[]) => void): Promise<() => void>;
|
|
1099
|
+
getChainTip(): Promise<{
|
|
1100
|
+
height: number;
|
|
1101
|
+
time: number;
|
|
1102
|
+
hash: string;
|
|
1103
|
+
}>;
|
|
1104
|
+
private broadcastPackage;
|
|
1105
|
+
private broadcastTx;
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
interface WalletState {
|
|
1109
|
+
/** Arbitrary stored wallet settings. */
|
|
1110
|
+
settings?: Record<string, any>;
|
|
1111
|
+
/**
|
|
1112
|
+
* High-water mark for VTXO indexer syncs, in milliseconds.
|
|
1113
|
+
*
|
|
1114
|
+
* Reused the legacy `lastSyncTime` column name to avoid an
|
|
1115
|
+
* `ALTER TABLE` migration; the value is interpreted as the new
|
|
1116
|
+
* "max indexer `updatedAt`" cursor only after `settings.vtxoCursorMigrated`
|
|
1117
|
+
* is set, so pre-existing values written by the buggy pre-PR sync
|
|
1118
|
+
* are ignored and force a one-shot re-bootstrap on upgrade.
|
|
1119
|
+
*/
|
|
1120
|
+
lastSyncTime?: number;
|
|
1121
|
+
}
|
|
1122
|
+
interface VtxoRepositoryKey {
|
|
1123
|
+
/** Authoritative ownership key. */
|
|
1124
|
+
script: string;
|
|
1125
|
+
/** Legacy storage bucket. Required by all current backends; throw if absent. */
|
|
1126
|
+
address?: string;
|
|
1127
|
+
}
|
|
1128
|
+
interface WalletRepository extends AsyncDisposable {
|
|
1129
|
+
readonly version: 1;
|
|
1130
|
+
/**
|
|
1131
|
+
* Clear all data from storage.
|
|
1132
|
+
*/
|
|
1133
|
+
clear(): Promise<void>;
|
|
1134
|
+
/** Fetch stored virtual outputs for an address. */
|
|
1135
|
+
getVtxos(address: string): Promise<ExtendedVirtualCoin[]>;
|
|
1136
|
+
/** Save virtual outputs for an address. */
|
|
1137
|
+
saveVtxos(address: string, vtxos: ExtendedVirtualCoin[]): Promise<void>;
|
|
1138
|
+
/** Delete stored virtual outputs for an address. */
|
|
1139
|
+
deleteVtxos(address: string): Promise<void>;
|
|
1140
|
+
/**
|
|
1141
|
+
* Fetch stored virtual outputs for a script.
|
|
1142
|
+
* @optional SDK backends implement this; custom backends fall back to Tier 1.
|
|
1143
|
+
*/
|
|
1144
|
+
getVtxosForScript?(script: string): Promise<ExtendedVirtualCoin[]>;
|
|
1145
|
+
/**
|
|
1146
|
+
* Save virtual outputs for a script.
|
|
1147
|
+
* @optional SDK backends implement this; custom backends fall back to Tier 1.
|
|
1148
|
+
*/
|
|
1149
|
+
saveVtxosForScript?(key: VtxoRepositoryKey, vtxos: ExtendedVirtualCoin[]): Promise<void>;
|
|
1150
|
+
/**
|
|
1151
|
+
* Delete stored virtual outputs for a script.
|
|
1152
|
+
* @optional SDK backends implement this; custom backends fall back to Tier 1.
|
|
1153
|
+
*/
|
|
1154
|
+
deleteVtxosForScript?(script: string): Promise<void>;
|
|
1155
|
+
/** Fetch stored boarding inputs for an address. */
|
|
1156
|
+
getUtxos(address: string): Promise<ExtendedCoin[]>;
|
|
1157
|
+
/** Save boarding inputs for an address. */
|
|
1158
|
+
saveUtxos(address: string, utxos: ExtendedCoin[]): Promise<void>;
|
|
1159
|
+
/** Delete stored boarding inputs for an address. */
|
|
1160
|
+
deleteUtxos(address: string): Promise<void>;
|
|
1161
|
+
/** Fetch stored transaction history for an address. */
|
|
1162
|
+
getTransactionHistory(address: string): Promise<ArkTransaction[]>;
|
|
1163
|
+
/** Save transaction history for an address. */
|
|
1164
|
+
saveTransactions(address: string, txs: ArkTransaction[]): Promise<void>;
|
|
1165
|
+
/** Delete stored transaction history for an address. */
|
|
1166
|
+
deleteTransactions(address: string): Promise<void>;
|
|
1167
|
+
/** Fetch stored wallet state. */
|
|
1168
|
+
getWalletState(): Promise<WalletState | null>;
|
|
1169
|
+
/** Save wallet state. */
|
|
1170
|
+
saveWalletState(state: WalletState): Promise<void>;
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
/**
|
|
1174
|
+
* Filter options for querying contracts.
|
|
1175
|
+
*/
|
|
1176
|
+
interface ContractFilter {
|
|
1177
|
+
/** Filter by script(s) */
|
|
1178
|
+
script?: string | string[];
|
|
1179
|
+
/** Filter by state(s) */
|
|
1180
|
+
state?: ContractState | ContractState[];
|
|
1181
|
+
/** Filter by contract type(s) */
|
|
1182
|
+
type?: string | string[];
|
|
1183
|
+
}
|
|
1184
|
+
interface ContractRepository extends AsyncDisposable {
|
|
1185
|
+
readonly version: 1;
|
|
1186
|
+
/**
|
|
1187
|
+
* Clear all data from storage.
|
|
1188
|
+
*/
|
|
1189
|
+
clear(): Promise<void>;
|
|
1190
|
+
/**
|
|
1191
|
+
* Get contracts with optional filter.
|
|
1192
|
+
* Returns all contracts if no filter provided.
|
|
1193
|
+
*/
|
|
1194
|
+
getContracts(filter?: ContractFilter): Promise<Contract[]>;
|
|
1195
|
+
/**
|
|
1196
|
+
* Save or update a contract.
|
|
1197
|
+
*/
|
|
1198
|
+
saveContract(contract: Contract): Promise<void>;
|
|
1199
|
+
/**
|
|
1200
|
+
* Delete a contract by script.
|
|
1201
|
+
*/
|
|
1202
|
+
deleteContract(script: string): Promise<void>;
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
type RefreshVtxosOptions = {
|
|
1206
|
+
scripts?: string[];
|
|
1207
|
+
after?: number;
|
|
1208
|
+
before?: number;
|
|
1209
|
+
/**
|
|
1210
|
+
* When true and `scripts` is not set, refresh every contract in
|
|
1211
|
+
* the repository — including those marked `inactive` and those
|
|
1212
|
+
* that have dropped out of the watcher's active set. Useful for
|
|
1213
|
+
* "did anyone send funds to a stale rotated display address?"
|
|
1214
|
+
* audits.
|
|
1215
|
+
*
|
|
1216
|
+
* Because this is a *superset* of the watcher's watched set, the
|
|
1217
|
+
* cursor invariant still holds and the cursor advances normally
|
|
1218
|
+
* (unless an explicit `after` / `before` window is also supplied).
|
|
1219
|
+
*
|
|
1220
|
+
* Ignored when `scripts` is set (the explicit list already
|
|
1221
|
+
* specifies what to refresh, regardless of contract state).
|
|
1222
|
+
*
|
|
1223
|
+
* @defaultValue `false`
|
|
1224
|
+
*/
|
|
1225
|
+
includeInactive?: boolean;
|
|
1226
|
+
};
|
|
1227
|
+
/**
|
|
1228
|
+
* A single `Discoverable` handler's `discoverAt` rejection, captured during
|
|
1229
|
+
* a {@link IContractManager.scanContracts} run instead of aborting the loop.
|
|
1230
|
+
*/
|
|
1231
|
+
interface HandlerError {
|
|
1232
|
+
handler: string;
|
|
1233
|
+
index: number;
|
|
1234
|
+
error: unknown;
|
|
1235
|
+
}
|
|
1236
|
+
/**
|
|
1237
|
+
* Outcome of a {@link IContractManager.scanContracts} run.
|
|
1238
|
+
*
|
|
1239
|
+
* `lastIndexUsed` is the highest HD index at which any handler discovered a
|
|
1240
|
+
* contract (`-1` if nothing was found). `handlerErrors` collects per-handler
|
|
1241
|
+
* `discoverAt` failures — non-empty means the gap window may have closed
|
|
1242
|
+
* early and the caller should surface this (the scan itself still resolved).
|
|
1243
|
+
*/
|
|
1244
|
+
interface ScanResult {
|
|
1245
|
+
lastIndexUsed: number;
|
|
1246
|
+
handlerErrors: HandlerError[];
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1249
|
+
* Options for {@link IContractManager.scanContracts}.
|
|
1250
|
+
*/
|
|
1251
|
+
interface ScanContractsOptions {
|
|
1252
|
+
/** Default 20. A non-positive / non-integer value throws. */
|
|
1253
|
+
gapLimit?: number;
|
|
1254
|
+
/** HD mode → unbounded gap loop guided by the gap counter; false → probe only index 0 (single static pass). */
|
|
1255
|
+
hd: boolean;
|
|
1256
|
+
/**
|
|
1257
|
+
* Materialize the descriptor at an HD index. Pure derivation; a throw
|
|
1258
|
+
* here is structural/fatal and propagates out of `scanContracts`.
|
|
1259
|
+
*/
|
|
1260
|
+
materialize: (index: number) => string;
|
|
1261
|
+
/** Read-only context injected into every `discoverAt` call. */
|
|
1262
|
+
deps: DiscoveryDeps;
|
|
1263
|
+
}
|
|
1264
|
+
interface IContractManager extends Disposable {
|
|
1265
|
+
/**
|
|
1266
|
+
* Create and register a new contract.
|
|
1267
|
+
*
|
|
1268
|
+
* Implementations may validate that:
|
|
1269
|
+
* - A handler exists for `params.type`
|
|
1270
|
+
* - `params.script` matches the script derived from `params.params`
|
|
1271
|
+
*
|
|
1272
|
+
* The contract script is used as the unique identifier.
|
|
1273
|
+
*/
|
|
1274
|
+
createContract(params: CreateContractParams): Promise<Contract>;
|
|
1275
|
+
/**
|
|
1276
|
+
* List contracts with optional filters.
|
|
1277
|
+
*
|
|
1278
|
+
* @example
|
|
1279
|
+
* ```typescript
|
|
1280
|
+
* const vhtlcs = await manager.getContracts({ type: "vhtlc" });
|
|
1281
|
+
* const active = await manager.getContracts({ state: "active" });
|
|
1282
|
+
* ```
|
|
1283
|
+
*/
|
|
1284
|
+
getContracts(filter?: GetContractsFilter): Promise<Contract[]>;
|
|
1285
|
+
/**
|
|
1286
|
+
* List contracts and their current virtual outputs.
|
|
1287
|
+
*
|
|
1288
|
+
* If no filter is provided, returns all contracts with their virtual outputs.
|
|
1289
|
+
*/
|
|
1290
|
+
getContractsWithVtxos(filter?: GetContractsFilter): Promise<ContractWithVtxos[]>;
|
|
1291
|
+
/**
|
|
1292
|
+
* Stamp raw virtual outputs with the correct per-contract tapscripts
|
|
1293
|
+
* (forfeit, intent, tap tree).
|
|
1294
|
+
*
|
|
1295
|
+
* Resolves each vtxo's `script` to its owning contract via the contract
|
|
1296
|
+
* repository and attaches the matching tapscripts. Throws when any vtxo
|
|
1297
|
+
* references a script with no registered contract — callers are expected
|
|
1298
|
+
* to register the contract before asking for annotation. This is the
|
|
1299
|
+
* single shared path that replaces scattered `extendVirtualCoin*` calls
|
|
1300
|
+
* in wallet/handler code, and keeps the wallet from silently stamping the
|
|
1301
|
+
* default tapscript onto a non-default vtxo.
|
|
1302
|
+
*/
|
|
1303
|
+
annotateVtxos(vtxos: VirtualCoin[]): Promise<ExtendedVirtualCoin[]>;
|
|
1304
|
+
/**
|
|
1305
|
+
* Update mutable contract fields.
|
|
1306
|
+
*
|
|
1307
|
+
* `script` and `createdAt` are immutable.
|
|
1308
|
+
*/
|
|
1309
|
+
updateContract(script: string, updates: Partial<Omit<Contract, "script" | "createdAt">>): Promise<Contract>;
|
|
1310
|
+
/**
|
|
1311
|
+
* Convenience helper to update only the contract state.
|
|
1312
|
+
*/
|
|
1313
|
+
setContractState(script: string, state: ContractState): Promise<void>;
|
|
1314
|
+
/**
|
|
1315
|
+
* Delete a contract by script and stop watching it (if applicable).
|
|
1316
|
+
*/
|
|
1317
|
+
deleteContract(script: string): Promise<void>;
|
|
1318
|
+
/**
|
|
1319
|
+
* Get all currently spendable paths for a contract.
|
|
1320
|
+
*
|
|
1321
|
+
* Returns an empty array if the contract or its handler cannot be found.
|
|
1322
|
+
*/
|
|
1323
|
+
getSpendablePaths(options: GetSpendablePathsOptions): Promise<PathSelection[]>;
|
|
1324
|
+
/**
|
|
1325
|
+
* Get all possible spending paths for a contract.
|
|
1326
|
+
*
|
|
1327
|
+
* Returns an empty array if the contract or its handler cannot be found.
|
|
1328
|
+
*/
|
|
1329
|
+
getAllSpendingPaths(options: GetAllSpendingPathsOptions): Promise<PathSelection[]>;
|
|
1330
|
+
/**
|
|
1331
|
+
* Subscribe to contract events.
|
|
1332
|
+
*
|
|
1333
|
+
* @returns Unsubscribe function
|
|
1334
|
+
*/
|
|
1335
|
+
onContractEvent(callback: ContractEventCallback): () => void;
|
|
1336
|
+
/**
|
|
1337
|
+
* Force a virtual output refresh from the indexer.
|
|
1338
|
+
*
|
|
1339
|
+
* Without options, refreshes all contracts from scratch.
|
|
1340
|
+
* With options, narrows the refresh to specific scripts and/or a time window.
|
|
1341
|
+
*/
|
|
1342
|
+
refreshVtxos(opts?: RefreshVtxosOptions): Promise<void>;
|
|
1343
|
+
/**
|
|
1344
|
+
* Reconcile specific outpoints with the indexer's authoritative state and
|
|
1345
|
+
* upsert the result into the wallet repository.
|
|
1346
|
+
*
|
|
1347
|
+
* The cursor-derived delta sync filters by `created_at`, so a VTXO that
|
|
1348
|
+
* was created before the cursor but spent recently won't surface in a
|
|
1349
|
+
* standard `refreshVtxos()` call. This method is the surgical recovery
|
|
1350
|
+
* path for that case: when something hands us a stale outpoint (e.g. the
|
|
1351
|
+
* server returns `VTXO_ALREADY_SPENT` with a `vtxo_outpoint` in its
|
|
1352
|
+
* error metadata), call this to pull the latest state and unblock the
|
|
1353
|
+
* caller — no full re-scan, no cursor change.
|
|
1354
|
+
*
|
|
1355
|
+
* Outpoints not owned by any tracked contract are silently dropped.
|
|
1356
|
+
*/
|
|
1357
|
+
refreshOutpoints(outpoints: Outpoint[]): Promise<void>;
|
|
1358
|
+
/**
|
|
1359
|
+
* Explicit, gap-limit contract discovery used by `wallet.restore()`.
|
|
1360
|
+
*
|
|
1361
|
+
* Walks HD indices from 0, asking every registered `Discoverable`
|
|
1362
|
+
* handler whether it owns a contract anchored at that index, and
|
|
1363
|
+
* registers each find via the idempotent {@link createContract}. A hit
|
|
1364
|
+
* at index `i` (by any handler, including an injected swap handler)
|
|
1365
|
+
* resets the gap counter, so swap discovery keeps the HD window open.
|
|
1366
|
+
*
|
|
1367
|
+
* Error contract (safety-critical — see spec §4):
|
|
1368
|
+
* - A handler's `discoverAt` rejecting is **collected** into
|
|
1369
|
+
* `handlerErrors` and the loop **continues**; it never aborts the
|
|
1370
|
+
* scan or throws.
|
|
1371
|
+
* - A fatal operational error — `materialize()` throwing, or
|
|
1372
|
+
* `createContract` rejecting — **propagates** out of `scanContracts`
|
|
1373
|
+
* (it invalidates the gap-window signal, so a silent truncation
|
|
1374
|
+
* would risk hiding user funds).
|
|
1375
|
+
*
|
|
1376
|
+
* @param opts See {@link ScanContractsOptions}.
|
|
1377
|
+
* @returns `{ lastIndexUsed, handlerErrors }` — the caller surfaces
|
|
1378
|
+
* `handlerErrors` *after* the inline VTXO pull.
|
|
1379
|
+
*/
|
|
1380
|
+
scanContracts(opts: ScanContractsOptions): Promise<ScanResult>;
|
|
1381
|
+
/**
|
|
1382
|
+
* Whether the underlying watcher is currently active.
|
|
1383
|
+
*/
|
|
1384
|
+
isWatching(): Promise<boolean>;
|
|
1385
|
+
/**
|
|
1386
|
+
* Release resources (stop watching, clear listeners).
|
|
1387
|
+
*/
|
|
1388
|
+
dispose(): void;
|
|
1389
|
+
}
|
|
1390
|
+
/**
|
|
1391
|
+
* Options for getting spendable paths.
|
|
1392
|
+
*/
|
|
1393
|
+
type GetSpendablePathsOptions = {
|
|
1394
|
+
/** The contract script */
|
|
1395
|
+
contractScript: string;
|
|
1396
|
+
/** The specific virtual output being evaluated */
|
|
1397
|
+
vtxo: VirtualCoin;
|
|
1398
|
+
/** Whether collaborative spending is available (default: true) */
|
|
1399
|
+
collaborative?: boolean;
|
|
1400
|
+
/** Wallet's public key (hex) to determine role */
|
|
1401
|
+
walletPubKey?: string;
|
|
1402
|
+
};
|
|
1403
|
+
/**
|
|
1404
|
+
* Options for getting all possible spending paths.
|
|
1405
|
+
*/
|
|
1406
|
+
type GetAllSpendingPathsOptions = {
|
|
1407
|
+
/** The contract script */
|
|
1408
|
+
contractScript: string;
|
|
1409
|
+
/** Whether collaborative spending is available (default: true) */
|
|
1410
|
+
collaborative?: boolean;
|
|
1411
|
+
/** Wallet's public key (hex) to determine role */
|
|
1412
|
+
walletPubKey?: string;
|
|
1413
|
+
};
|
|
1414
|
+
/**
|
|
1415
|
+
* Configuration for the ContractManager.
|
|
1416
|
+
*/
|
|
1417
|
+
interface ContractManagerConfig {
|
|
1418
|
+
/** The indexer provider */
|
|
1419
|
+
indexerProvider: IndexerProvider;
|
|
1420
|
+
/** The contract repository for persistence */
|
|
1421
|
+
contractRepository: ContractRepository;
|
|
1422
|
+
/** The wallet repository for virtual output storage (single source of truth) */
|
|
1423
|
+
walletRepository: WalletRepository;
|
|
1424
|
+
/** Watcher configuration */
|
|
1425
|
+
watcherConfig?: Partial<ContractWatcherConfig>;
|
|
1426
|
+
}
|
|
1427
|
+
/**
|
|
1428
|
+
* Parameters for creating a new contract.
|
|
1429
|
+
*/
|
|
1430
|
+
type CreateContractParams = Omit<Contract, "createdAt" | "state"> & {
|
|
1431
|
+
/** Initial state (defaults to "active") */
|
|
1432
|
+
state?: ContractState;
|
|
1433
|
+
};
|
|
1434
|
+
/**
|
|
1435
|
+
* Central manager for contract lifecycle and operations.
|
|
1436
|
+
*
|
|
1437
|
+
* Responsibilities:
|
|
1438
|
+
* - Create and persist contracts
|
|
1439
|
+
* - Query stored contracts (optionally with their virtual outputs)
|
|
1440
|
+
* - Provide spendable path selection for a contract
|
|
1441
|
+
* - Emit contract-related events (virtual output received/spent, connection reset)
|
|
1442
|
+
*
|
|
1443
|
+
* Notes:
|
|
1444
|
+
* - Implementations typically start watching automatically during initialization
|
|
1445
|
+
* (so `onContractEvent()` is just for subscribing).
|
|
1446
|
+
*
|
|
1447
|
+
* @example
|
|
1448
|
+
* ```typescript
|
|
1449
|
+
* const manager = await ContractManager.create({
|
|
1450
|
+
* indexerProvider: wallet.indexerProvider,
|
|
1451
|
+
* contractRepository: wallet.contractRepository,
|
|
1452
|
+
* });
|
|
1453
|
+
*
|
|
1454
|
+
* // Create a new VHTLC contract
|
|
1455
|
+
* const contract = await manager.createContract({
|
|
1456
|
+
* label: "Lightning Receive",
|
|
1457
|
+
* type: "vhtlc",
|
|
1458
|
+
* params: { sender: "ark1q...", receiver: "ark1q...", ... },
|
|
1459
|
+
* script: "5120...",
|
|
1460
|
+
* address: "ark1q...",
|
|
1461
|
+
* });
|
|
1462
|
+
*
|
|
1463
|
+
* // Start watching for events
|
|
1464
|
+
* const unsubscribe = manager.onContractEvent((event) => {
|
|
1465
|
+
* console.log(`${event.type} on ${event.contractScript}`);
|
|
1466
|
+
* });
|
|
1467
|
+
*
|
|
1468
|
+
* // Query contracts together with their current virtual outputs
|
|
1469
|
+
* const contractsWithVtxos = await manager.getContractsWithVtxos();
|
|
1470
|
+
*
|
|
1471
|
+
* // Get balance across all contracts
|
|
1472
|
+
* const balances = contractsWithVtxos.flatMap(({vtxos}) => vtxos).reduce((acc, vtxo) => acc + vtxo.value, 0)
|
|
1473
|
+
*
|
|
1474
|
+
* // Later: unsubscribe from events
|
|
1475
|
+
* unsubscribe();
|
|
1476
|
+
*
|
|
1477
|
+
* // Clean up
|
|
1478
|
+
* manager.dispose();
|
|
1479
|
+
* ```
|
|
1480
|
+
*/
|
|
1481
|
+
declare class ContractManager implements IContractManager {
|
|
1482
|
+
private config;
|
|
1483
|
+
private watcher;
|
|
1484
|
+
private initialized;
|
|
1485
|
+
private eventCallbacks;
|
|
1486
|
+
private stopWatcherFn?;
|
|
1487
|
+
private constructor();
|
|
1488
|
+
/**
|
|
1489
|
+
* Static factory method for creating a new ContractManager.
|
|
1490
|
+
* Initialize the manager by loading persisted contracts and starting to watch.
|
|
1491
|
+
*
|
|
1492
|
+
* After initialization, the manager automatically watches all active contracts
|
|
1493
|
+
* and contracts with virtual outputs. Use `onContractEvent()` to register event callbacks.
|
|
1494
|
+
*
|
|
1495
|
+
* @param config ContractManagerConfig
|
|
1496
|
+
*/
|
|
1497
|
+
static create(config: ContractManagerConfig): Promise<ContractManager>;
|
|
1498
|
+
private initialize;
|
|
1499
|
+
/**
|
|
1500
|
+
* Delta-sync the full watched set and reconcile the pending frontier.
|
|
1501
|
+
*
|
|
1502
|
+
* Shared recovery path used on initial boot and after a subscription
|
|
1503
|
+
* reconnect. `syncContracts({})` scopes to the current watched set
|
|
1504
|
+
* (see {@link ContractWatcher.getWatchedContracts}), uses the
|
|
1505
|
+
* cursor-derived delta window, and advances the cursor on success.
|
|
1506
|
+
* `reconcilePendingFrontier` catches not-yet-finalized virtual
|
|
1507
|
+
* outputs that could sit outside any delta window.
|
|
1508
|
+
*/
|
|
1509
|
+
private reconcileWatched;
|
|
1510
|
+
/**
|
|
1511
|
+
* Create and register a new contract.
|
|
1512
|
+
*
|
|
1513
|
+
* @param params - Contract parameters
|
|
1514
|
+
* @returns The created contract
|
|
1515
|
+
*/
|
|
1516
|
+
createContract(params: CreateContractParams): Promise<Contract>;
|
|
1517
|
+
/**
|
|
1518
|
+
* Lightweight variant of {@link createContract} for batch discovery
|
|
1519
|
+
* paths (currently: {@link scanContracts}). Validates, dedupes, persists,
|
|
1520
|
+
* and registers the watcher — but skips the per-contract
|
|
1521
|
+
* `fetchContractVxosFromIndexer` round-trip. The caller is responsible
|
|
1522
|
+
* for hydrating VTXOs afterwards via a bulk `refreshVtxos(...)` so a
|
|
1523
|
+
* scan that finds N contracts costs one batched indexer call instead
|
|
1524
|
+
* of N + 1. Error semantics are identical to `createContract`:
|
|
1525
|
+
* validation / type-mismatch / persistence failures propagate.
|
|
1526
|
+
*/
|
|
1527
|
+
private persistAndWatchContract;
|
|
1528
|
+
/**
|
|
1529
|
+
* Shared validate + check-existing + persist core for
|
|
1530
|
+
* {@link createContract} and {@link persistAndWatchContract}. Returns
|
|
1531
|
+
* the resolved contract and whether *this* call wrote it — callers
|
|
1532
|
+
* that need to attach hydration / watcher work do so only when
|
|
1533
|
+
* `persisted` is `true`.
|
|
1534
|
+
*/
|
|
1535
|
+
private upsertContract;
|
|
1536
|
+
/**
|
|
1537
|
+
* Explicit, gap-limit contract discovery (see {@link IContractManager.scanContracts}).
|
|
1538
|
+
*
|
|
1539
|
+
* Each hit is routed through {@link persistAndWatchContract} — the same
|
|
1540
|
+
* dedupe + watcher-register path as {@link createContract} minus the
|
|
1541
|
+
* per-contract indexer round-trip. The caller (`Wallet.restore`) follows
|
|
1542
|
+
* up with a single bulk `refreshVtxos({ includeInactive: true })`, so a
|
|
1543
|
+
* scan that finds N contracts costs one batched indexer call instead of
|
|
1544
|
+
* N + 1.
|
|
1545
|
+
*
|
|
1546
|
+
* Safety-critical invariants (spec §2.C / §4):
|
|
1547
|
+
* - `opts.materialize(i)` throwing is structural/fatal: it is NOT
|
|
1548
|
+
* wrapped — it propagates and aborts the scan.
|
|
1549
|
+
* - A `discoverAt` rejection is collected into `handlerErrors` and the
|
|
1550
|
+
* loop continues (the gap counter still advances for that index if no
|
|
1551
|
+
* other handler hit it).
|
|
1552
|
+
* - `persistAndWatchContract` rejecting is operational/fatal and
|
|
1553
|
+
* propagates (only `discoverAt` is guarded).
|
|
1554
|
+
*/
|
|
1555
|
+
scanContracts(opts: ScanContractsOptions): Promise<ScanResult>;
|
|
1556
|
+
/**
|
|
1557
|
+
* Get contracts with optional filters.
|
|
1558
|
+
*
|
|
1559
|
+
* @param filter - Optional filter criteria
|
|
1560
|
+
* @returns Filtered contracts TODO: filter spent/unspent
|
|
1561
|
+
*
|
|
1562
|
+
* @example
|
|
1563
|
+
* ```typescript
|
|
1564
|
+
* // Get all VHTLC contracts
|
|
1565
|
+
* const vhtlcs = await manager.getContracts({ type: 'vhtlc' });
|
|
1566
|
+
*
|
|
1567
|
+
* // Get all active contracts
|
|
1568
|
+
* const active = await manager.getContracts({ state: 'active' });
|
|
1569
|
+
* ```
|
|
1570
|
+
*/
|
|
1571
|
+
getContracts(filter?: GetContractsFilter): Promise<Contract[]>;
|
|
1572
|
+
getContractsWithVtxos(filter?: GetContractsFilter, pageSize?: number): Promise<ContractWithVtxos[]>;
|
|
1573
|
+
annotateVtxos(vtxos: VirtualCoin[]): Promise<ExtendedVirtualCoin[]>;
|
|
1574
|
+
private buildContractsDbFilter;
|
|
1575
|
+
/**
|
|
1576
|
+
* Update a contract.
|
|
1577
|
+
* Nested fields like `params` and `metadata` are replaced with the provided values.
|
|
1578
|
+
* If you need to preserve existing fields, merge them manually.
|
|
1579
|
+
*
|
|
1580
|
+
* @param script - Contract script
|
|
1581
|
+
* @param updates - Fields to update
|
|
1582
|
+
*/
|
|
1583
|
+
updateContract(script: string, updates: Partial<Omit<Contract, "script" | "createdAt">>): Promise<Contract>;
|
|
1584
|
+
/**
|
|
1585
|
+
* Update a contract's params.
|
|
1586
|
+
* This method preserves existing params by merging the provided values.
|
|
1587
|
+
*
|
|
1588
|
+
* @param script - Contract script
|
|
1589
|
+
* @param updates - The new values to merge with existing params
|
|
1590
|
+
*/
|
|
1591
|
+
updateContractParams(script: string, updates: Contract["params"]): Promise<Contract>;
|
|
1592
|
+
/**
|
|
1593
|
+
* Set a contract's state.
|
|
1594
|
+
*/
|
|
1595
|
+
setContractState(script: string, state: ContractState): Promise<void>;
|
|
1596
|
+
/**
|
|
1597
|
+
* Delete a contract.
|
|
1598
|
+
*
|
|
1599
|
+
* @param script - Contract script
|
|
1600
|
+
*/
|
|
1601
|
+
deleteContract(script: string): Promise<void>;
|
|
1602
|
+
/**
|
|
1603
|
+
* Get currently spendable paths for a contract.
|
|
1604
|
+
*
|
|
1605
|
+
* @param options - Options for getting spendable paths
|
|
1606
|
+
*/
|
|
1607
|
+
getSpendablePaths(options: GetSpendablePathsOptions): Promise<PathSelection[]>;
|
|
1608
|
+
/**
|
|
1609
|
+
* Get every currently valid spending path for a contract.
|
|
1610
|
+
*
|
|
1611
|
+
* @param options - Options for getting spending paths
|
|
1612
|
+
*/
|
|
1613
|
+
getAllSpendingPaths(options: GetAllSpendingPathsOptions): Promise<PathSelection[]>;
|
|
1614
|
+
/**
|
|
1615
|
+
* Register a callback for contract events.
|
|
1616
|
+
*
|
|
1617
|
+
* The manager automatically watches after `initialize()`. This method
|
|
1618
|
+
* allows registering callbacks to receive events.
|
|
1619
|
+
*
|
|
1620
|
+
* @param callback - Event callback
|
|
1621
|
+
* @returns Unsubscribe function to remove this callback
|
|
1622
|
+
*
|
|
1623
|
+
* @example
|
|
1624
|
+
* ```typescript
|
|
1625
|
+
* const unsubscribe = manager.onContractEvent((event) => {
|
|
1626
|
+
* console.log(`${event.type} on ${event.contractScript}`);
|
|
1627
|
+
* });
|
|
1628
|
+
*
|
|
1629
|
+
* // Later: stop receiving events
|
|
1630
|
+
* unsubscribe();
|
|
1631
|
+
* ```
|
|
1632
|
+
*/
|
|
1633
|
+
onContractEvent(callback: ContractEventCallback): () => void;
|
|
1634
|
+
/**
|
|
1635
|
+
* Force refresh virtual outputs from the indexer.
|
|
1636
|
+
*
|
|
1637
|
+
* Without options, re-fetches every contract in the watcher's
|
|
1638
|
+
* watched set and advances the global cursor.
|
|
1639
|
+
*
|
|
1640
|
+
* `scripts` narrows the refresh to a specific list (subset query —
|
|
1641
|
+
* cursor is not advanced because contracts outside the list may
|
|
1642
|
+
* have data we'd skip).
|
|
1643
|
+
*
|
|
1644
|
+
* `includeInactive: true` (and no `scripts`) widens the refresh to
|
|
1645
|
+
* every contract in the repository, including ones marked
|
|
1646
|
+
* `inactive` and ones that have dropped out of the watcher's
|
|
1647
|
+
* active set. This is a *superset* of the watched set, so the
|
|
1648
|
+
* cursor invariant still holds and the cursor advances normally.
|
|
1649
|
+
*
|
|
1650
|
+
* `after` / `before` apply a caller-supplied time window. The
|
|
1651
|
+
* cursor never advances on a windowed query because the window
|
|
1652
|
+
* may skip data outside its bounds.
|
|
1653
|
+
*/
|
|
1654
|
+
refreshVtxos(opts?: RefreshVtxosOptions): Promise<void>;
|
|
1655
|
+
refreshOutpoints(outpoints: Outpoint[]): Promise<void>;
|
|
1656
|
+
/**
|
|
1657
|
+
* Check if currently watching.
|
|
1658
|
+
*/
|
|
1659
|
+
isWatching(): Promise<boolean>;
|
|
1660
|
+
/**
|
|
1661
|
+
* Emit an event to all registered callbacks.
|
|
1662
|
+
*/
|
|
1663
|
+
private emitEvent;
|
|
1664
|
+
/**
|
|
1665
|
+
* Handle events from the watcher.
|
|
1666
|
+
*/
|
|
1667
|
+
private handleContractEvent;
|
|
1668
|
+
private getVtxosForContracts;
|
|
1669
|
+
/**
|
|
1670
|
+
* Sync virtual outputs for the given contracts against the indexer.
|
|
1671
|
+
*
|
|
1672
|
+
* When `options.contracts` is omitted the sync covers the full
|
|
1673
|
+
* watched set (active contracts plus any inactive contracts still
|
|
1674
|
+
* holding cached VTXOs) and the global cursor is advanced on
|
|
1675
|
+
* success. Passing an explicit subset leaves the cursor alone so a
|
|
1676
|
+
* narrow poll can't hide data that other contracts still need to
|
|
1677
|
+
* pick up.
|
|
1678
|
+
*/
|
|
1679
|
+
private syncContracts;
|
|
1680
|
+
/**
|
|
1681
|
+
* Fetch all pending (unfinalized) virtual outputs and upsert them into the
|
|
1682
|
+
* repository. This catches virtual outputs whose state changed outside the delta
|
|
1683
|
+
* window (e.g. a spend that hasn't settled yet).
|
|
1684
|
+
*/
|
|
1685
|
+
private reconcilePendingFrontier;
|
|
1686
|
+
private fetchContractVxosFromIndexer;
|
|
1687
|
+
private fetchContractVtxosBulk;
|
|
1688
|
+
/**
|
|
1689
|
+
* Dispose of the ContractManager and release all resources.
|
|
1690
|
+
*
|
|
1691
|
+
* Stops the watcher, clears callbacks, and marks
|
|
1692
|
+
* the manager as uninitialized.
|
|
1693
|
+
*
|
|
1694
|
+
* Implements the disposable pattern for cleanup.
|
|
1695
|
+
*/
|
|
1696
|
+
dispose(): void;
|
|
1697
|
+
/**
|
|
1698
|
+
* Symbol.dispose implementation for using with `using` keyword.
|
|
1699
|
+
* @example
|
|
1700
|
+
* ```typescript
|
|
1701
|
+
* {
|
|
1702
|
+
* using manager = await wallet.getContractManager();
|
|
1703
|
+
* // ... use manager
|
|
1704
|
+
* } // automatically disposed
|
|
1705
|
+
* ```
|
|
1706
|
+
*/
|
|
1707
|
+
[Symbol.dispose](): void;
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
/**
|
|
1711
|
+
* Contract state indicating whether it should be actively monitored.
|
|
1712
|
+
*/
|
|
1713
|
+
type ContractState = "active" | "inactive";
|
|
1714
|
+
/**
|
|
1715
|
+
* Represents a contract that can receive and manage virtual outputs.
|
|
1716
|
+
*
|
|
1717
|
+
* A contract is defined by its type and parameters, which together
|
|
1718
|
+
* determine the VtxoScript (spending paths). The wallet's default
|
|
1719
|
+
* receiving address is itself a contract of type "default".
|
|
1720
|
+
*
|
|
1721
|
+
* External services (Boltz swaps, atomic swaps, etc.) create additional
|
|
1722
|
+
* contracts with their own types and parameters.
|
|
1723
|
+
*
|
|
1724
|
+
* @example
|
|
1725
|
+
* ```typescript
|
|
1726
|
+
* const vhtlcContract: Contract = {
|
|
1727
|
+
* type: "vhtlc",
|
|
1728
|
+
* params: {
|
|
1729
|
+
* sender: "ab12...",
|
|
1730
|
+
* receiver: "cd34...",
|
|
1731
|
+
* server: "ef56...",
|
|
1732
|
+
* hash: "1234...",
|
|
1733
|
+
* refundLocktime: "800000",
|
|
1734
|
+
* // ... timelocks
|
|
1735
|
+
* },
|
|
1736
|
+
* script: "5120...",
|
|
1737
|
+
* address: "ark1q...",
|
|
1738
|
+
* state: "active",
|
|
1739
|
+
* createdAt: 1704067200000,
|
|
1740
|
+
* };
|
|
1741
|
+
* ```
|
|
1742
|
+
*/
|
|
1743
|
+
interface Contract {
|
|
1744
|
+
/** Human-readable label for display purposes. */
|
|
1745
|
+
label?: string;
|
|
1746
|
+
/**
|
|
1747
|
+
* Contract type identifier.
|
|
1748
|
+
* Built-in types: "default", "vhtlc"
|
|
1749
|
+
* Custom types can be registered via ContractHandler.
|
|
1750
|
+
*/
|
|
1751
|
+
type: string;
|
|
1752
|
+
/**
|
|
1753
|
+
* Type-specific parameters for constructing the VtxoScript.
|
|
1754
|
+
* All values are serialized as strings (hex for bytes, string for bigint).
|
|
1755
|
+
* The ContractHandler for this type knows how to interpret these.
|
|
1756
|
+
*/
|
|
1757
|
+
params: Record<string, string>;
|
|
1758
|
+
/** The pkScript hex, used as the unique identifier and primary key for contracts. */
|
|
1759
|
+
script: string;
|
|
1760
|
+
/** Address derived from the contract script. */
|
|
1761
|
+
address: string;
|
|
1762
|
+
/** Current state of the contract. */
|
|
1763
|
+
state: ContractState;
|
|
1764
|
+
/** Unix timestamp in milliseconds when this contract was created. */
|
|
1765
|
+
createdAt: number;
|
|
1766
|
+
/**
|
|
1767
|
+
* Optional metadata for external integrations.
|
|
1768
|
+
*/
|
|
1769
|
+
metadata?: Record<string, unknown>;
|
|
1770
|
+
}
|
|
1771
|
+
/**
|
|
1772
|
+
* A virtual output that has been associated with a specific contract.
|
|
1773
|
+
*/
|
|
1774
|
+
type ContractVtxo = VirtualCoin & Partial<TapLeaves & EncodedVtxoScript> & {
|
|
1775
|
+
extraWitness?: Bytes[];
|
|
1776
|
+
contractScript: string;
|
|
1777
|
+
};
|
|
1778
|
+
/**
|
|
1779
|
+
* A {@link ContractVtxo} with all taproot annotation fields required.
|
|
1780
|
+
*
|
|
1781
|
+
* Mirrors the {@link ExtendedVirtualCoin} / {@link VirtualCoin} split:
|
|
1782
|
+
* - {@link ContractVtxo} carries `TapLeaves` and `EncodedVtxoScript` as
|
|
1783
|
+
* `Partial<>` because VTXOs fetched raw from the indexer do not yet have
|
|
1784
|
+
* taproot data.
|
|
1785
|
+
* - `ExtendedContractVtxo` narrows those fields to required, guaranteeing
|
|
1786
|
+
* that `annotateVtxos` has run and the taproot leaves are present.
|
|
1787
|
+
*
|
|
1788
|
+
* Use this type (instead of {@link ContractVtxo}) wherever the compiler
|
|
1789
|
+
* should enforce that annotation has happened — e.g. `saveVtxos` and
|
|
1790
|
+
* forfeit transaction construction.
|
|
1791
|
+
*/
|
|
1792
|
+
type ExtendedContractVtxo = ExtendedVirtualCoin & {
|
|
1793
|
+
contractScript: string;
|
|
1794
|
+
};
|
|
1795
|
+
/**
|
|
1796
|
+
* Result of path selection, including the tapleaf to use and any extra witness data.
|
|
1797
|
+
*/
|
|
1798
|
+
interface PathSelection {
|
|
1799
|
+
/** Tapleaf script to use for spending. */
|
|
1800
|
+
leaf: TapLeafScript;
|
|
1801
|
+
/** Additional witness elements, for example a preimage for HTLC-like paths. */
|
|
1802
|
+
extraWitness?: Bytes[];
|
|
1803
|
+
/**
|
|
1804
|
+
* nSequence for the spending input, BIP-68 encoded when the leaf
|
|
1805
|
+
* uses CSV. Decode with `sequenceToTimelock`; do NOT use as an
|
|
1806
|
+
* absolute `Transaction.lockTime`.
|
|
1807
|
+
*/
|
|
1808
|
+
sequence?: number;
|
|
1809
|
+
}
|
|
1810
|
+
/**
|
|
1811
|
+
* Context for path selection decisions.
|
|
1812
|
+
*/
|
|
1813
|
+
interface PathContext {
|
|
1814
|
+
/** Whether collaborative spending is available through server cooperation. */
|
|
1815
|
+
collaborative: boolean;
|
|
1816
|
+
/** Current time in milliseconds. */
|
|
1817
|
+
currentTime: number;
|
|
1818
|
+
/** Current block height, when known. */
|
|
1819
|
+
blockHeight?: number;
|
|
1820
|
+
/**
|
|
1821
|
+
* Wallet's descriptor for signing.
|
|
1822
|
+
* Format: tr(pubkey) for static keys, tr([fingerprint/path']xpub/0/{index}) for HD.
|
|
1823
|
+
* Used by handlers to determine wallet's role in multi-party contracts.
|
|
1824
|
+
*/
|
|
1825
|
+
walletDescriptor?: string;
|
|
1826
|
+
/**
|
|
1827
|
+
* Wallet's public key (x-only, 32 bytes hex).
|
|
1828
|
+
* @deprecated Use walletDescriptor instead.
|
|
1829
|
+
*/
|
|
1830
|
+
walletPubKey?: string;
|
|
1831
|
+
/**
|
|
1832
|
+
* Explicit role override for multi-party contracts such as VHTLC.
|
|
1833
|
+
* If not provided, the handler may derive the role by matching
|
|
1834
|
+
* {@link walletDescriptor} (preferred) — or {@link walletPubKey} as a
|
|
1835
|
+
* fallback — against the contract's sender/receiver params.
|
|
1836
|
+
*/
|
|
1837
|
+
role?: string;
|
|
1838
|
+
/** The specific virtual output being evaluated. */
|
|
1839
|
+
vtxo?: VirtualCoin;
|
|
1840
|
+
}
|
|
1841
|
+
/**
|
|
1842
|
+
* Handler for a specific contract type.
|
|
1843
|
+
*
|
|
1844
|
+
* Each contract type (`default`, `vhtlc`, etc.) has a handler that knows how to:
|
|
1845
|
+
* 1. Create the VtxoScript from parameters
|
|
1846
|
+
* 2. Serialize/deserialize parameters for storage
|
|
1847
|
+
* 3. Select the appropriate spending path based on context
|
|
1848
|
+
*
|
|
1849
|
+
* @example
|
|
1850
|
+
* ```typescript
|
|
1851
|
+
* const vhtlcHandler: ContractHandler = {
|
|
1852
|
+
* type: "vhtlc",
|
|
1853
|
+
* createScript(params) {
|
|
1854
|
+
* return new VHTLC.Script(this.deserializeParams(params));
|
|
1855
|
+
* },
|
|
1856
|
+
* selectPath(script, contract, context) {
|
|
1857
|
+
* const vhtlc = script as VHTLC.Script;
|
|
1858
|
+
* const preimage = contract.data?.preimage;
|
|
1859
|
+
* if (context.collaborative && preimage) {
|
|
1860
|
+
* return { leaf: vhtlc.claim(), extraWitness: [hex.decode(preimage)] };
|
|
1861
|
+
* }
|
|
1862
|
+
* // ... other paths
|
|
1863
|
+
* },
|
|
1864
|
+
* // ...
|
|
1865
|
+
* };
|
|
1866
|
+
* ```
|
|
1867
|
+
*/
|
|
1868
|
+
interface ContractHandler<P = Record<string, unknown>, S extends VtxoScript = VtxoScript> {
|
|
1869
|
+
/** Contract type managed by this handler. */
|
|
1870
|
+
readonly type: string;
|
|
1871
|
+
/**
|
|
1872
|
+
* Create the VtxoScript from serialized parameters.
|
|
1873
|
+
*
|
|
1874
|
+
* @param params - Serialized contract parameters
|
|
1875
|
+
* @returns Contract script instance
|
|
1876
|
+
*/
|
|
1877
|
+
createScript(params: Record<string, string>): S;
|
|
1878
|
+
/**
|
|
1879
|
+
* Serialize typed parameters to string key-value pairs.
|
|
1880
|
+
*
|
|
1881
|
+
* @param params - Typed contract parameters
|
|
1882
|
+
* @returns Serialized key-value representation
|
|
1883
|
+
*/
|
|
1884
|
+
serializeParams(params: P): Record<string, string>;
|
|
1885
|
+
/**
|
|
1886
|
+
* Deserialize string key-value pairs to typed parameters.
|
|
1887
|
+
*/
|
|
1888
|
+
deserializeParams(params: Record<string, string>): P;
|
|
1889
|
+
/**
|
|
1890
|
+
* Select the preferred spending path based on contract state and context.
|
|
1891
|
+
* Returns the best available path (e.g., collaborative over unilateral).
|
|
1892
|
+
*
|
|
1893
|
+
* @returns PathSelection if a viable path exists, null otherwise
|
|
1894
|
+
*/
|
|
1895
|
+
selectPath(script: S, contract: Contract, context: PathContext): PathSelection | null;
|
|
1896
|
+
/**
|
|
1897
|
+
* Get all possible spending paths for the current context.
|
|
1898
|
+
* Returns empty array if no paths are available.
|
|
1899
|
+
*
|
|
1900
|
+
* Useful for showing users which spending options exist regardless of
|
|
1901
|
+
* current spendability.
|
|
1902
|
+
*/
|
|
1903
|
+
getAllSpendingPaths(script: S, contract: Contract, context: PathContext): PathSelection[];
|
|
1904
|
+
/**
|
|
1905
|
+
* Get all currently spendable paths.
|
|
1906
|
+
* Returns empty array if no paths are available.
|
|
1907
|
+
*/
|
|
1908
|
+
getSpendablePaths(script: S, contract: Contract, context: PathContext): PathSelection[];
|
|
1909
|
+
}
|
|
1910
|
+
/**
|
|
1911
|
+
* What a {@link Discoverable.discoverAt} call returns — exactly the
|
|
1912
|
+
* shape `ContractManager.createContract` accepts (script-keyed,
|
|
1913
|
+
* idempotent on re-register).
|
|
1914
|
+
*/
|
|
1915
|
+
interface DiscoveredContract {
|
|
1916
|
+
type: string;
|
|
1917
|
+
params: Record<string, string>;
|
|
1918
|
+
script: string;
|
|
1919
|
+
address: string;
|
|
1920
|
+
metadata?: Record<string, unknown>;
|
|
1921
|
+
label?: string;
|
|
1922
|
+
}
|
|
1923
|
+
/**
|
|
1924
|
+
* Read-only context the scanner injects into every `discoverAt` call.
|
|
1925
|
+
* The boltz/swap handler does NOT receive its Boltz client here — it
|
|
1926
|
+
* closes over its own client at registration time.
|
|
1927
|
+
*/
|
|
1928
|
+
interface DiscoveryDeps {
|
|
1929
|
+
indexerProvider: IndexerProvider;
|
|
1930
|
+
onchainProvider: OnchainProvider;
|
|
1931
|
+
network: {
|
|
1932
|
+
hrp: string;
|
|
1933
|
+
};
|
|
1934
|
+
serverPubKey: Uint8Array;
|
|
1935
|
+
/** Relative timelocks the wallet treats as its baseline matrix. */
|
|
1936
|
+
csvTimelocks: RelativeTimelock[];
|
|
1937
|
+
/** Present only for delegate wallets. */
|
|
1938
|
+
delegatePubKey?: Uint8Array;
|
|
1939
|
+
}
|
|
1940
|
+
/**
|
|
1941
|
+
* Optional capability a {@link ContractHandler} implements to participate
|
|
1942
|
+
* in `wallet.restore()`'s gap-limit scan. The scanner owns the index
|
|
1943
|
+
* loop and the gap counter; the handler answers "do I own a contract
|
|
1944
|
+
* anchored to the pubkey/descriptor at this index?" — checked against
|
|
1945
|
+
* the indexer / explorer / (for swaps) the handler's own source. The
|
|
1946
|
+
* handler MAY batch/cache internally across calls.
|
|
1947
|
+
*/
|
|
1948
|
+
interface Discoverable {
|
|
1949
|
+
discoverAt(index: number, descriptor: string, deps: DiscoveryDeps): Promise<DiscoveredContract[]>;
|
|
1950
|
+
}
|
|
1951
|
+
/** Duck-typed guard (mirrors `hasReceiveRotatorFactory`). */
|
|
1952
|
+
declare function isDiscoverable(handler: ContractHandler<unknown> | undefined): handler is ContractHandler<unknown> & Discoverable;
|
|
1953
|
+
/**
|
|
1954
|
+
* Event emitted when contract-related changes occur.
|
|
1955
|
+
*/
|
|
1956
|
+
type ContractEvent = {
|
|
1957
|
+
type: "vtxo_received";
|
|
1958
|
+
contractScript: string;
|
|
1959
|
+
vtxos: ContractVtxo[];
|
|
1960
|
+
contract: Contract;
|
|
1961
|
+
timestamp: number;
|
|
1962
|
+
} | {
|
|
1963
|
+
type: "vtxo_spent";
|
|
1964
|
+
contractScript: string;
|
|
1965
|
+
vtxos: ContractVtxo[];
|
|
1966
|
+
contract: Contract;
|
|
1967
|
+
timestamp: number;
|
|
1968
|
+
} | {
|
|
1969
|
+
type: "connection_reset";
|
|
1970
|
+
timestamp: number;
|
|
1971
|
+
};
|
|
1972
|
+
/**
|
|
1973
|
+
* Callback for contract events.
|
|
1974
|
+
*/
|
|
1975
|
+
type ContractEventCallback = (event: ContractEvent) => void;
|
|
1976
|
+
/**
|
|
1977
|
+
* Options for retrieving contracts from the Contract Manager.
|
|
1978
|
+
* Currently an alias of the repository's filter type but can be extended in the future.
|
|
1979
|
+
*/
|
|
1980
|
+
type GetContractsFilter = ContractFilter;
|
|
1981
|
+
/**
|
|
1982
|
+
* Contract with its virtual outputs included.
|
|
1983
|
+
*/
|
|
1984
|
+
type ContractWithVtxos = {
|
|
1985
|
+
contract: Contract;
|
|
1986
|
+
vtxos: ExtendedContractVtxo[];
|
|
1987
|
+
};
|
|
1988
|
+
/**
|
|
1989
|
+
* Summary of a contract's balance.
|
|
1990
|
+
*/
|
|
1991
|
+
interface ContractBalance {
|
|
1992
|
+
/** Total balance (settled + pending) in satoshis */
|
|
1993
|
+
total: number;
|
|
1994
|
+
/** Spendable balance in satoshis */
|
|
1995
|
+
spendable: number;
|
|
1996
|
+
/** Number of virtual outputs in this contract */
|
|
1997
|
+
vtxoCount: number;
|
|
1998
|
+
}
|
|
1999
|
+
|
|
2000
|
+
/**
|
|
2001
|
+
* Configuration for the ContractWatcher.
|
|
2002
|
+
*
|
|
2003
|
+
* @see ContractWatcher
|
|
2004
|
+
*
|
|
2005
|
+
* @example
|
|
2006
|
+
* ```typescript
|
|
2007
|
+
* const watcher = new ContractWatcher({
|
|
2008
|
+
* indexerProvider,
|
|
2009
|
+
* walletRepository,
|
|
2010
|
+
* })
|
|
2011
|
+
* ```
|
|
2012
|
+
*/
|
|
2013
|
+
interface ContractWatcherConfig {
|
|
2014
|
+
/** Indexer provider used for subscriptions and queries. */
|
|
2015
|
+
indexerProvider: IndexerProvider;
|
|
2016
|
+
/** Wallet repository used to store virtual output state between watcher updates. */
|
|
2017
|
+
walletRepository: WalletRepository;
|
|
2018
|
+
/**
|
|
2019
|
+
* Interval for failsafe polling (ms).
|
|
2020
|
+
* Polls even when subscription is active to catch missed events.
|
|
2021
|
+
*
|
|
2022
|
+
* @defaultValue `60_000` (1 minute)
|
|
2023
|
+
*/
|
|
2024
|
+
failsafePollIntervalMs?: number;
|
|
2025
|
+
/**
|
|
2026
|
+
* Initial reconnection delay (ms).
|
|
2027
|
+
* Uses exponential backoff on repeated failures.
|
|
2028
|
+
*
|
|
2029
|
+
* @defaultValue `1_000` (1 second)
|
|
2030
|
+
*/
|
|
2031
|
+
reconnectDelayMs?: number;
|
|
2032
|
+
/**
|
|
2033
|
+
* Maximum reconnection delay (ms).
|
|
2034
|
+
*
|
|
2035
|
+
* @defaultValue `30_000` (30 seconds)
|
|
2036
|
+
*/
|
|
2037
|
+
maxReconnectDelayMs?: number;
|
|
2038
|
+
/**
|
|
2039
|
+
* Maximum reconnection attempts before giving up.
|
|
2040
|
+
* Set to 0 for unlimited attempts.
|
|
2041
|
+
*
|
|
2042
|
+
* @defaultValue `0` (unlimited)
|
|
2043
|
+
*/
|
|
2044
|
+
maxReconnectAttempts?: number;
|
|
2045
|
+
}
|
|
2046
|
+
/**
|
|
2047
|
+
* Connection state for the watcher.
|
|
2048
|
+
*/
|
|
2049
|
+
type ConnectionState = "disconnected" | "connecting" | "connected" | "reconnecting";
|
|
2050
|
+
/**
|
|
2051
|
+
* Watches multiple contracts for virtual output state changes with resilient connection handling.
|
|
2052
|
+
*
|
|
2053
|
+
* Features:
|
|
2054
|
+
* - Automatic reconnection with exponential backoff
|
|
2055
|
+
* - Failsafe polling to catch missed events
|
|
2056
|
+
* - Polls immediately after (re)connection to sync state
|
|
2057
|
+
* - Graceful handling of subscription failures
|
|
2058
|
+
*
|
|
2059
|
+
* @example
|
|
2060
|
+
* ```typescript
|
|
2061
|
+
* const watcher = new ContractWatcher({
|
|
2062
|
+
* indexerProvider: wallet.indexerProvider,
|
|
2063
|
+
* });
|
|
2064
|
+
*
|
|
2065
|
+
* // Add the wallet's default contract
|
|
2066
|
+
* await watcher.addContract(defaultContract);
|
|
2067
|
+
*
|
|
2068
|
+
* // Add additional contracts (swaps, etc.)
|
|
2069
|
+
* await watcher.addContract(swapContract);
|
|
2070
|
+
*
|
|
2071
|
+
* // Start watching for events
|
|
2072
|
+
* const stop = await watcher.startWatching((event) => {
|
|
2073
|
+
* console.log(`${event.type} on contract ${event.contractScript}`);
|
|
2074
|
+
* });
|
|
2075
|
+
*
|
|
2076
|
+
* // Later: stop watching
|
|
2077
|
+
* stop();
|
|
2078
|
+
* ```
|
|
2079
|
+
*/
|
|
2080
|
+
declare class ContractWatcher {
|
|
2081
|
+
private config;
|
|
2082
|
+
private contracts;
|
|
2083
|
+
private subscriptionId?;
|
|
2084
|
+
private abortController?;
|
|
2085
|
+
private isWatching;
|
|
2086
|
+
private eventCallback?;
|
|
2087
|
+
private connectionState;
|
|
2088
|
+
private reconnectAttempts;
|
|
2089
|
+
private reconnectTimeoutId?;
|
|
2090
|
+
private failsafePollIntervalId?;
|
|
2091
|
+
/**
|
|
2092
|
+
* Create a contract watcher with the given providers and polling settings.
|
|
2093
|
+
*
|
|
2094
|
+
* @param config - Contract watcher configuration
|
|
2095
|
+
* @see ContractWatcherConfig
|
|
2096
|
+
*/
|
|
2097
|
+
constructor(config: ContractWatcherConfig);
|
|
2098
|
+
/**
|
|
2099
|
+
* Add a contract to be watched.
|
|
2100
|
+
*
|
|
2101
|
+
* Active contracts are immediately subscribed.
|
|
2102
|
+
*
|
|
2103
|
+
* All contracts are polled to discover any existing virtual outputs
|
|
2104
|
+
* (which may cause them to be watched even if inactive).
|
|
2105
|
+
*/
|
|
2106
|
+
addContract(contract: Contract): Promise<void>;
|
|
2107
|
+
/**
|
|
2108
|
+
* Pre-populate `lastKnownVtxos` from the wallet repository.
|
|
2109
|
+
*
|
|
2110
|
+
* Runs on add (and can be re-run after reconnect) so polling always
|
|
2111
|
+
* compares the indexer's view against what is already persisted,
|
|
2112
|
+
* emitting only genuine deltas.
|
|
2113
|
+
*/
|
|
2114
|
+
private seedLastKnownVtxos;
|
|
2115
|
+
/**
|
|
2116
|
+
* Update an existing contract.
|
|
2117
|
+
*/
|
|
2118
|
+
updateContract(contract: Contract): Promise<void>;
|
|
2119
|
+
/**
|
|
2120
|
+
* Remove a contract from watching.
|
|
2121
|
+
*/
|
|
2122
|
+
removeContract(contractScript: string): Promise<void>;
|
|
2123
|
+
/**
|
|
2124
|
+
* Get all in-memory contracts.
|
|
2125
|
+
*/
|
|
2126
|
+
getAllContracts(): Contract[];
|
|
2127
|
+
/**
|
|
2128
|
+
* Contracts the watcher is actually tracking:
|
|
2129
|
+
* - all active contracts, plus
|
|
2130
|
+
* - inactive contracts that still hold known virtual outputs
|
|
2131
|
+
* (the subscription keeps watching them so `vtxo_spent` events for
|
|
2132
|
+
* those unspent outputs are still observed).
|
|
2133
|
+
*
|
|
2134
|
+
* This is the single source of truth for "contracts whose VTXO state
|
|
2135
|
+
* we still care about" — callers and the subscription itself fan out
|
|
2136
|
+
* over the same set so nothing is reconciled that isn't also watched.
|
|
2137
|
+
*/
|
|
2138
|
+
getWatchedContracts(): Contract[];
|
|
2139
|
+
/**
|
|
2140
|
+
* Get virtual outputs for contracts, grouped by contract script.
|
|
2141
|
+
* @see WalletRepository for `repo`
|
|
2142
|
+
*/
|
|
2143
|
+
private getContractVtxos;
|
|
2144
|
+
/**
|
|
2145
|
+
* Start watching for virtual output events across all active contracts.
|
|
2146
|
+
*/
|
|
2147
|
+
startWatching(callback: ContractEventCallback): Promise<() => void>;
|
|
2148
|
+
/**
|
|
2149
|
+
* Stop watching for events.
|
|
2150
|
+
*/
|
|
2151
|
+
stopWatching(): Promise<void>;
|
|
2152
|
+
/**
|
|
2153
|
+
* Check if currently watching.
|
|
2154
|
+
*/
|
|
2155
|
+
isCurrentlyWatching(): boolean;
|
|
2156
|
+
/**
|
|
2157
|
+
* Get current connection state.
|
|
2158
|
+
*/
|
|
2159
|
+
getConnectionState(): ConnectionState;
|
|
2160
|
+
/**
|
|
2161
|
+
* Force a poll of all active contracts.
|
|
2162
|
+
* Useful for manual refresh or after app resume.
|
|
2163
|
+
*/
|
|
2164
|
+
forcePoll(): Promise<void>;
|
|
2165
|
+
/**
|
|
2166
|
+
* Connect to the subscription.
|
|
2167
|
+
*
|
|
2168
|
+
* @param skipUpdate - Skip the leading `updateSubscription` call when
|
|
2169
|
+
* the caller has already established `subscriptionId`.
|
|
2170
|
+
*/
|
|
2171
|
+
private connect;
|
|
2172
|
+
/**
|
|
2173
|
+
* Schedule a reconnection attempt.
|
|
2174
|
+
*/
|
|
2175
|
+
private scheduleReconnect;
|
|
2176
|
+
/**
|
|
2177
|
+
* Start the failsafe polling interval.
|
|
2178
|
+
*/
|
|
2179
|
+
private startFailsafePolling;
|
|
2180
|
+
private pollAllContracts;
|
|
2181
|
+
/**
|
|
2182
|
+
* Poll specific contracts and emit events for changes.
|
|
2183
|
+
*/
|
|
2184
|
+
private pollContracts;
|
|
2185
|
+
private tryUpdateSubscription;
|
|
2186
|
+
/**
|
|
2187
|
+
* Update the subscription with scripts that should be watched.
|
|
2188
|
+
*
|
|
2189
|
+
* Watches both active contracts and contracts with virtual outputs.
|
|
2190
|
+
*/
|
|
2191
|
+
private updateSubscription;
|
|
2192
|
+
/**
|
|
2193
|
+
* Main listening loop for subscription events.
|
|
2194
|
+
*/
|
|
2195
|
+
private listenLoop;
|
|
2196
|
+
/**
|
|
2197
|
+
* Handle a subscription update.
|
|
2198
|
+
*/
|
|
2199
|
+
private handleSubscriptionUpdate;
|
|
2200
|
+
/**
|
|
2201
|
+
* Process virtual outputs from subscription and route each VTXO to the
|
|
2202
|
+
* single contract that actually locks it via `vtxo.script`. If the script
|
|
2203
|
+
* doesn't match any watched contract, skip the VTXO rather than fan it
|
|
2204
|
+
* out to every matching contract — fan-out produced phantom state in
|
|
2205
|
+
* non-owning contracts that then never reconciled.
|
|
2206
|
+
*/
|
|
2207
|
+
private processSubscriptionVtxos;
|
|
2208
|
+
/**
|
|
2209
|
+
* Emit a virtual output event for a contract.
|
|
2210
|
+
*/
|
|
2211
|
+
private emitVtxoEvent;
|
|
2212
|
+
}
|
|
2213
|
+
|
|
2214
|
+
/**
|
|
2215
|
+
* Intent proof implementation for Bitcoin message signing.
|
|
2216
|
+
*
|
|
2217
|
+
* Intent proof defines a standard for signing Bitcoin messages as well as proving
|
|
2218
|
+
* ownership of outputs.
|
|
2219
|
+
*
|
|
2220
|
+
* This namespace provides utilities for creating and validating Intent proof.
|
|
2221
|
+
*
|
|
2222
|
+
* It is greatly inspired by BIP322.
|
|
2223
|
+
* @see https://github.com/bitcoin/bips/blob/master/bip-0322.mediawiki
|
|
2224
|
+
*
|
|
2225
|
+
* @example
|
|
2226
|
+
* ```typescript
|
|
2227
|
+
* // Create a Intent proof
|
|
2228
|
+
* const proof = Intent.create(
|
|
2229
|
+
* "Hello Bitcoin!",
|
|
2230
|
+
* [input],
|
|
2231
|
+
* [output]
|
|
2232
|
+
* );
|
|
2233
|
+
*
|
|
2234
|
+
* // Sign the proof
|
|
2235
|
+
* const signedProof = await identity.sign(proof);
|
|
2236
|
+
*
|
|
2237
|
+
*/
|
|
2238
|
+
declare namespace Intent {
|
|
2239
|
+
type Proof = Transaction;
|
|
2240
|
+
/**
|
|
2241
|
+
* Creates a new Intent proof unsigned transaction.
|
|
2242
|
+
*
|
|
2243
|
+
* This function constructs a special transaction that can be signed to prove
|
|
2244
|
+
* ownership of onchain and virtual outputs. The proof includes the message to be
|
|
2245
|
+
* signed and the inputs/outputs that demonstrate ownership.
|
|
2246
|
+
*
|
|
2247
|
+
* @param message - The Intent message to be signed, either raw string of Message object
|
|
2248
|
+
* @param ins - Array of transaction inputs to prove ownership of
|
|
2249
|
+
* @param outputs - Optional array of transaction outputs
|
|
2250
|
+
* @returns An unsigned Intent proof transaction
|
|
2251
|
+
*/
|
|
2252
|
+
function create(message: string | Message, ins: (TransactionInput | ExtendedCoin)[], outputs?: TransactionOutput[]): Proof;
|
|
2253
|
+
/**
|
|
2254
|
+
* Compute the fee paid by an intent proof transaction.
|
|
2255
|
+
*
|
|
2256
|
+
* @param proof - Intent proof transaction
|
|
2257
|
+
* @returns The fee in satoshis
|
|
2258
|
+
*/
|
|
2259
|
+
function fee(proof: Proof): number;
|
|
2260
|
+
type RegisterMessage = {
|
|
2261
|
+
type: "register";
|
|
2262
|
+
onchain_output_indexes: number[];
|
|
2263
|
+
valid_at: number;
|
|
2264
|
+
expire_at: number;
|
|
2265
|
+
cosigners_public_keys: string[];
|
|
2266
|
+
};
|
|
2267
|
+
type DeleteMessage = {
|
|
2268
|
+
type: "delete";
|
|
2269
|
+
expire_at: number;
|
|
2270
|
+
};
|
|
2271
|
+
type GetPendingTxMessage = {
|
|
2272
|
+
type: "get-pending-tx";
|
|
2273
|
+
expire_at: number;
|
|
2274
|
+
};
|
|
2275
|
+
type Message = RegisterMessage | DeleteMessage | GetPendingTxMessage;
|
|
2276
|
+
/**
|
|
2277
|
+
* Serialize an intent message to the canonical JSON string used for signing.
|
|
2278
|
+
*
|
|
2279
|
+
* @param message - Intent message payload
|
|
2280
|
+
* @returns Canonical string form of the message
|
|
2281
|
+
*/
|
|
2282
|
+
function encodeMessage(message: Message): string;
|
|
2283
|
+
}
|
|
2284
|
+
|
|
2285
|
+
/**
|
|
2286
|
+
* Delegate identity and fee information returned by `getDelegateInfo`.
|
|
2287
|
+
*/
|
|
2288
|
+
interface DelegateInfo {
|
|
2289
|
+
/** Delegate public key. */
|
|
2290
|
+
pubkey: string;
|
|
2291
|
+
/** Delegate fee amount or expression returned by the delegation service. */
|
|
2292
|
+
fee: string;
|
|
2293
|
+
/**
|
|
2294
|
+
* Address controlled by the delegation service.
|
|
2295
|
+
* Naming is confusing: should be thought of as a "delegate address".
|
|
2296
|
+
*/
|
|
2297
|
+
delegatorAddress: string;
|
|
2298
|
+
}
|
|
2299
|
+
/**
|
|
2300
|
+
* Optional delegate behavior flags.
|
|
2301
|
+
*/
|
|
2302
|
+
interface DelegateOptions {
|
|
2303
|
+
/**
|
|
2304
|
+
* Instruct the delegate not to replace an existing delegation
|
|
2305
|
+
* (meaning a signed register intent and its forfeit transactions)
|
|
2306
|
+
* that already includes at least one virtual output from this request.
|
|
2307
|
+
*
|
|
2308
|
+
* @defaultValue `false`
|
|
2309
|
+
*/
|
|
2310
|
+
rejectReplace?: boolean;
|
|
2311
|
+
}
|
|
2312
|
+
/**
|
|
2313
|
+
* Provider interface for remote delegation services.
|
|
2314
|
+
*/
|
|
2315
|
+
interface DelegatorProvider {
|
|
2316
|
+
/**
|
|
2317
|
+
* Request delegation for a signed register intent and its forfeit transactions.
|
|
2318
|
+
*
|
|
2319
|
+
* @param intent - Signed register intent to delegate
|
|
2320
|
+
* @param forfeitTxs - Forfeit transactions associated with the delegation request
|
|
2321
|
+
* @param options - Optional delegate behavior flags
|
|
2322
|
+
*/
|
|
2323
|
+
delegate(intent: SignedIntent<Intent.RegisterMessage>, forfeitTxs: string[], options?: DelegateOptions): Promise<void>;
|
|
2324
|
+
/**
|
|
2325
|
+
* Fetch delegate metadata such as pubkey, fee, and delegate address.
|
|
2326
|
+
*
|
|
2327
|
+
* @returns Delegate identity and fee information
|
|
2328
|
+
*/
|
|
2329
|
+
getDelegateInfo(): Promise<DelegateInfo>;
|
|
2330
|
+
}
|
|
2331
|
+
/**
|
|
2332
|
+
* REST-based delegation provider implementation.
|
|
2333
|
+
* @example
|
|
2334
|
+
* ```typescript
|
|
2335
|
+
* const provider = new RestDelegatorProvider('https://delegator.example.com');
|
|
2336
|
+
* const info = await provider.getDelegateInfo();
|
|
2337
|
+
* await provider.delegate(intent, forfeitTxs);
|
|
2338
|
+
* ```
|
|
2339
|
+
*/
|
|
2340
|
+
declare class RestDelegatorProvider implements DelegatorProvider {
|
|
2341
|
+
url: string;
|
|
2342
|
+
/**
|
|
2343
|
+
* Create a REST delegation provider targeting the given base URL.
|
|
2344
|
+
*
|
|
2345
|
+
* @param url - Base URL of the delegation service
|
|
2346
|
+
*/
|
|
2347
|
+
constructor(url: string);
|
|
2348
|
+
/**
|
|
2349
|
+
* Submit a delegation request to the remote delegation service.
|
|
2350
|
+
*
|
|
2351
|
+
* @param intent - Signed register intent to delegate
|
|
2352
|
+
* @param forfeitTxs - Forfeit transactions associated with the delegation request
|
|
2353
|
+
* @param options - Optional delegate behavior flags
|
|
2354
|
+
* @throws Error if the remote service rejects the request
|
|
2355
|
+
*/
|
|
2356
|
+
delegate(intent: SignedIntent<Intent.RegisterMessage>, forfeitTxs: string[], options?: DelegateOptions): Promise<void>;
|
|
2357
|
+
/**
|
|
2358
|
+
* Fetch delegate metadata exposed by the remote delegation service.
|
|
2359
|
+
*
|
|
2360
|
+
* @returns Delegate identity and fee information
|
|
2361
|
+
* @throws Error if the remote service returns invalid data
|
|
2362
|
+
*/
|
|
2363
|
+
getDelegateInfo(): Promise<DelegateInfo>;
|
|
2364
|
+
}
|
|
2365
|
+
|
|
2366
|
+
interface IDelegatorManager {
|
|
2367
|
+
/**
|
|
2368
|
+
* Delegate virtual outputs to the remote delegation service.
|
|
2369
|
+
*
|
|
2370
|
+
* Vtxos that are not locked to a delegate-type contract (no tap leaf
|
|
2371
|
+
* matches the delegator's pubkey) are filtered out silently, since they
|
|
2372
|
+
* cannot be co-signed by the delegator.
|
|
2373
|
+
*
|
|
2374
|
+
* @param vtxos - Virtual outputs to delegate
|
|
2375
|
+
* @param destination - Arkade address that should receive renewed funds
|
|
2376
|
+
* @param delegateAt - Optional timestamp to force a specific delegation time
|
|
2377
|
+
* @returns Successfully delegated and failed outpoint groups
|
|
2378
|
+
*/
|
|
2379
|
+
delegate(vtxos: ContractVtxo[], destination: string, delegateAt?: Date): Promise<{
|
|
2380
|
+
delegated: Outpoint[];
|
|
2381
|
+
failed: {
|
|
2382
|
+
outpoints: Outpoint[];
|
|
2383
|
+
error: unknown;
|
|
2384
|
+
}[];
|
|
2385
|
+
}>;
|
|
2386
|
+
/** Fetch delegate metadata such as pubkey, fee, and delegate address. */
|
|
2387
|
+
getDelegateInfo(): Promise<DelegateInfo>;
|
|
2388
|
+
}
|
|
2389
|
+
declare class DelegatorManagerImpl implements IDelegatorManager {
|
|
2390
|
+
readonly delegatorProvider: DelegatorProvider;
|
|
2391
|
+
readonly arkInfoProvider: Pick<ArkProvider, "getInfo">;
|
|
2392
|
+
readonly identity: Identity;
|
|
2393
|
+
/** Create a delegator manager from the configured provider, Arkade info source, and wallet identity. */
|
|
2394
|
+
constructor(delegatorProvider: DelegatorProvider, arkInfoProvider: Pick<ArkProvider, "getInfo">, identity: Identity);
|
|
2395
|
+
getDelegateInfo(): Promise<DelegateInfo>;
|
|
2396
|
+
delegate(vtxos: ContractVtxo[], destination: string, delegateAt?: Date): Promise<{
|
|
2397
|
+
delegated: Outpoint[];
|
|
2398
|
+
failed: {
|
|
2399
|
+
outpoints: Outpoint[];
|
|
2400
|
+
error: unknown;
|
|
2401
|
+
}[];
|
|
2402
|
+
}>;
|
|
2403
|
+
}
|
|
2404
|
+
|
|
2405
|
+
/**
|
|
2406
|
+
* Wallet receive-address strategy.
|
|
2407
|
+
*
|
|
2408
|
+
* - `'auto'` *(default)*: **short-term** — currently identical to
|
|
2409
|
+
* `'static'`. The `'auto'` name is reserved for a future change that
|
|
2410
|
+
* will re-enable identity-probing once HD rotation has matured in
|
|
2411
|
+
* the field. Until then, opt into HD explicitly via `'hd'` or a
|
|
2412
|
+
* {@link DescriptorProvider}.
|
|
2413
|
+
* *(See `TODO(hd-maturation)` in
|
|
2414
|
+
* `src/wallet/walletReceiveRotator.ts:resolveDescriptorProvider` for
|
|
2415
|
+
* the flip-back criteria.)*
|
|
2416
|
+
* - `'static'`: never rotate. The wallet uses one receive address derived
|
|
2417
|
+
* from `identity.xOnlyPublicKey()`.
|
|
2418
|
+
* - `'hd'`: must rotate, using the built-in HD provider derived from the
|
|
2419
|
+
* identity. Throws at `Wallet.create` if the identity isn't HD-capable
|
|
2420
|
+
* or its descriptor isn't rangeable — no silent fallback.
|
|
2421
|
+
* - A {@link DescriptorProvider} instance: rotate via the supplied
|
|
2422
|
+
* provider on every incoming VTXO. The wallet does not probe the
|
|
2423
|
+
* identity; the caller is responsible for ensuring the identity can
|
|
2424
|
+
* sign for whatever pubkey the provider returns. Errors thrown by the
|
|
2425
|
+
* provider propagate — there is no silent fallback for an explicit
|
|
2426
|
+
* provider.
|
|
2427
|
+
*/
|
|
2428
|
+
type WalletMode = "auto" | "static" | "hd" | DescriptorProvider;
|
|
2429
|
+
/**
|
|
2430
|
+
* Base configuration options shared by all wallet types.
|
|
2431
|
+
*
|
|
2432
|
+
* Supports URL-based and provider-based configuration.
|
|
2433
|
+
*
|
|
2434
|
+
* URL-based configuration starts from `arkServerUrl` and can optionally override
|
|
2435
|
+
* derived service URLs such as `indexerUrl` and `esploraUrl`.
|
|
2436
|
+
*
|
|
2437
|
+
* Provider-based configuration supplies concrete provider instances directly,
|
|
2438
|
+
* including the ArkProvider, IndexerProvider, OnchainProvider, and DelegatorProvider.
|
|
2439
|
+
*
|
|
2440
|
+
* The wallet will use provided URLs to create default providers if custom provider
|
|
2441
|
+
* instances are not supplied. If optional parameters are not provided, the wallet
|
|
2442
|
+
* will fetch configuration from the Arkade server.
|
|
2443
|
+
*
|
|
2444
|
+
* @remarks
|
|
2445
|
+
* URL-based and provider-based configuration can be mixed, but provider instances
|
|
2446
|
+
* always take precedence over URLs for the corresponding service.
|
|
2447
|
+
*
|
|
2448
|
+
* @see WalletConfig
|
|
2449
|
+
* @see ReadonlyWalletConfig
|
|
2450
|
+
* @see StorageConfig
|
|
2451
|
+
*/
|
|
2452
|
+
interface BaseWalletConfig {
|
|
2453
|
+
/** Base URL of the Arkade server. */
|
|
2454
|
+
arkServerUrl?: string;
|
|
2455
|
+
/** Optional override for the indexer URL. */
|
|
2456
|
+
indexerUrl?: string;
|
|
2457
|
+
/** Optional override for the Esplora API URL. */
|
|
2458
|
+
esploraUrl?: string;
|
|
2459
|
+
/** Optional Arkade server public key used to construct and validate Arkade addresses. */
|
|
2460
|
+
arkServerPublicKey?: string;
|
|
2461
|
+
/** Relative timelock applied to boarding scripts. */
|
|
2462
|
+
boardingTimelock?: RelativeTimelock;
|
|
2463
|
+
/** Relative timelock applied to unilateral exit paths. */
|
|
2464
|
+
exitTimelock?: RelativeTimelock;
|
|
2465
|
+
/**
|
|
2466
|
+
* Repository-backed storage configuration overrides.
|
|
2467
|
+
* Defaults to IndexedDB if unset.
|
|
2468
|
+
*/
|
|
2469
|
+
storage?: StorageConfig;
|
|
2470
|
+
/** Optional Arkade provider instance. */
|
|
2471
|
+
arkProvider?: ArkProvider;
|
|
2472
|
+
/** Optional indexer provider instance. */
|
|
2473
|
+
indexerProvider?: IndexerProvider;
|
|
2474
|
+
/** Optional onchain provider instance. */
|
|
2475
|
+
onchainProvider?: OnchainProvider;
|
|
2476
|
+
/** Optional delegation service instance. */
|
|
2477
|
+
delegatorProvider?: DelegatorProvider;
|
|
2478
|
+
}
|
|
2479
|
+
/**
|
|
2480
|
+
* Configuration options for readonly wallet initialization.
|
|
2481
|
+
*
|
|
2482
|
+
* Use this config when you only need to query wallet state (balance, addresses, transactions)
|
|
2483
|
+
* without the ability to send transactions. This is useful for:
|
|
2484
|
+
* - Watch-only wallets
|
|
2485
|
+
* - Monitoring addresses
|
|
2486
|
+
* - Safe sharing of wallet state without private key exposure
|
|
2487
|
+
*
|
|
2488
|
+
* @see BaseWalletConfig
|
|
2489
|
+
* @see IReadonlyWallet
|
|
2490
|
+
*
|
|
2491
|
+
* @example
|
|
2492
|
+
* ```typescript
|
|
2493
|
+
* // URL-based configuration
|
|
2494
|
+
* const wallet = await ReadonlyWallet.create({
|
|
2495
|
+
* identity: ReadonlySingleKey.fromPublicKey(pubkey),
|
|
2496
|
+
* arkServerUrl: 'https://arkade.computer',
|
|
2497
|
+
* esploraUrl: 'https://mempool.space/api'
|
|
2498
|
+
* });
|
|
2499
|
+
*
|
|
2500
|
+
* // Provider-based configuration (e.g., for Expo/React Native)
|
|
2501
|
+
* const wallet = await ReadonlyWallet.create({
|
|
2502
|
+
* identity: ReadonlySingleKey.fromPublicKey(pubkey),
|
|
2503
|
+
* arkProvider: new ExpoArkProvider('https://arkade.computer'),
|
|
2504
|
+
* indexerProvider: new ExpoIndexerProvider('https://arkade.computer'),
|
|
2505
|
+
* onchainProvider: new EsploraProvider('https://mempool.space/api')
|
|
2506
|
+
* });
|
|
2507
|
+
* ```
|
|
2508
|
+
*/
|
|
2509
|
+
interface ReadonlyWalletConfig extends BaseWalletConfig {
|
|
2510
|
+
/** Readonly identity used to derive wallet addresses. */
|
|
2511
|
+
identity: ReadonlyIdentity;
|
|
2512
|
+
/**
|
|
2513
|
+
* Configuration for the ContractManager's watcher.
|
|
2514
|
+
* Controls reconnection behavior and failsafe polling.
|
|
2515
|
+
*
|
|
2516
|
+
* @see ContractWatcherConfig
|
|
2517
|
+
*/
|
|
2518
|
+
watcherConfig?: Partial<Omit<ContractWatcherConfig, "indexerProvider">>;
|
|
2519
|
+
}
|
|
2520
|
+
/**
|
|
2521
|
+
* Configuration options for full wallet initialization.
|
|
2522
|
+
*
|
|
2523
|
+
* This config provides full wallet capabilities including sending transactions,
|
|
2524
|
+
* settling virtual outputs, and all readonly operations.
|
|
2525
|
+
*
|
|
2526
|
+
* @see ReadonlyWalletConfig
|
|
2527
|
+
* @see IWallet
|
|
2528
|
+
*
|
|
2529
|
+
* @example
|
|
2530
|
+
* ```typescript
|
|
2531
|
+
* // URL-based configuration
|
|
2532
|
+
* const wallet = await Wallet.create({
|
|
2533
|
+
* identity: MnemonicIdentity.fromMnemonic('abandon abandon...'),
|
|
2534
|
+
* arkServerUrl: 'https://arkade.computer',
|
|
2535
|
+
* esploraUrl: 'https://mempool.space/api'
|
|
2536
|
+
* });
|
|
2537
|
+
*
|
|
2538
|
+
* // Provider-based configuration (e.g., for Expo/React Native)
|
|
2539
|
+
* const wallet = await Wallet.create({
|
|
2540
|
+
* identity: MnemonicIdentity.fromMnemonic('abandon abandon...'),
|
|
2541
|
+
* arkProvider: new ExpoArkProvider('https://arkade.computer'),
|
|
2542
|
+
* indexerProvider: new ExpoIndexerProvider('https://arkade.computer'),
|
|
2543
|
+
* onchainProvider: new EsploraProvider('https://mempool.space/api')
|
|
2544
|
+
* });
|
|
2545
|
+
*
|
|
2546
|
+
* // With settlement configuration
|
|
2547
|
+
* const wallet = await Wallet.create({
|
|
2548
|
+
* identity: MnemonicIdentity.fromMnemonic('abandon abandon...'),
|
|
2549
|
+
* arkServerUrl: 'https://arkade.computer',
|
|
2550
|
+
* settlementConfig: {
|
|
2551
|
+
* vtxoThreshold: 60 * 60 * 24, // 24 hours in seconds
|
|
2552
|
+
* boardingUtxoSweep: true,
|
|
2553
|
+
* },
|
|
2554
|
+
* });
|
|
2555
|
+
* ```
|
|
2556
|
+
*/
|
|
2557
|
+
interface WalletConfig extends ReadonlyWalletConfig {
|
|
2558
|
+
/** Signing identity used to authorize transactions. */
|
|
2559
|
+
identity: Identity;
|
|
2560
|
+
/**
|
|
2561
|
+
* Legacy renewal configuration.
|
|
2562
|
+
*
|
|
2563
|
+
* @remarks
|
|
2564
|
+
* This field is still accepted for backwards compatibility, but `settlementConfig`
|
|
2565
|
+
* is the source of truth for new code.
|
|
2566
|
+
*
|
|
2567
|
+
* @deprecated Use `settlementConfig` instead.
|
|
2568
|
+
*/
|
|
2569
|
+
renewalConfig?: RenewalConfig;
|
|
2570
|
+
/**
|
|
2571
|
+
* Configuration for automatic settlement and renewal.
|
|
2572
|
+
* `false` = explicitly disabled, `undefined` or `{}` = enabled with defaults.
|
|
2573
|
+
*
|
|
2574
|
+
* @defaultValue `undefined` (enabled with defaults)
|
|
2575
|
+
* @see SettlementConfig
|
|
2576
|
+
*/
|
|
2577
|
+
settlementConfig?: SettlementConfig | false;
|
|
2578
|
+
/**
|
|
2579
|
+
* Receive-address strategy. Pass `'static'`, `'hd'`, or a
|
|
2580
|
+
* {@link DescriptorProvider} instance to drive rotation; omit (or
|
|
2581
|
+
* pass `'auto'`) for the built-in auto-detect behaviour. See
|
|
2582
|
+
* {@link WalletMode}.
|
|
2583
|
+
*
|
|
2584
|
+
* @defaultValue `'auto'`
|
|
2585
|
+
*/
|
|
2586
|
+
walletMode?: WalletMode;
|
|
2587
|
+
}
|
|
2588
|
+
/**
|
|
2589
|
+
* Repository implementations used to store wallet and contract state.
|
|
2590
|
+
*
|
|
2591
|
+
* @see BaseWalletConfig
|
|
2592
|
+
* @see WalletRepository
|
|
2593
|
+
* @see ContractRepository
|
|
2594
|
+
*/
|
|
2595
|
+
type StorageConfig = {
|
|
2596
|
+
/** Wallet-state repository implementation. */
|
|
2597
|
+
walletRepository: WalletRepository;
|
|
2598
|
+
/** Contract-state repository implementation. */
|
|
2599
|
+
contractRepository: ContractRepository;
|
|
2600
|
+
};
|
|
2601
|
+
/**
|
|
2602
|
+
* Provider class constructor interface for dependency injection.
|
|
2603
|
+
* Ensures provider classes follow the consistent constructor pattern.
|
|
2604
|
+
*/
|
|
2605
|
+
interface ProviderClass<T> {
|
|
2606
|
+
/**
|
|
2607
|
+
* Create a provider instance for the given server URL.
|
|
2608
|
+
*
|
|
2609
|
+
* @param serverUrl - Base server URL used by the provider
|
|
2610
|
+
*/
|
|
2611
|
+
new (serverUrl: string): T;
|
|
2612
|
+
}
|
|
2613
|
+
/**
|
|
2614
|
+
* Balance summary returned by `IWallet.getBalance`.
|
|
2615
|
+
*
|
|
2616
|
+
* @see IWallet.getBalance
|
|
2617
|
+
*
|
|
2618
|
+
* @example
|
|
2619
|
+
* ```typescript
|
|
2620
|
+
* const balance = await wallet.getBalance()
|
|
2621
|
+
* console.log(balance.available, balance.boarding.total)
|
|
2622
|
+
* ```
|
|
2623
|
+
*/
|
|
2624
|
+
interface WalletBalance {
|
|
2625
|
+
/** Boarding funds */
|
|
2626
|
+
boarding: {
|
|
2627
|
+
/** Confirmed funds ready to swap for virtual outputs. */
|
|
2628
|
+
confirmed: number;
|
|
2629
|
+
/** Pending funds awaiting confirmation on mainnet */
|
|
2630
|
+
unconfirmed: number;
|
|
2631
|
+
/** Combined boarding balance (`confirmed` + `unconfirmed`) */
|
|
2632
|
+
total: number;
|
|
2633
|
+
};
|
|
2634
|
+
/** Spendable settled (finalized) balance. */
|
|
2635
|
+
settled: number;
|
|
2636
|
+
/** Spendable preconfirmed (unfinalized) balance. */
|
|
2637
|
+
preconfirmed: number;
|
|
2638
|
+
/** Spendable offchain balance (`settled + preconfirmed`). */
|
|
2639
|
+
available: number;
|
|
2640
|
+
/** Recoverable balance from subdust or expired (swept) virtual outputs. */
|
|
2641
|
+
recoverable: number;
|
|
2642
|
+
/** Total balance across offchain, recoverable, and boarding funds. */
|
|
2643
|
+
total: number;
|
|
2644
|
+
/** Asset balance entries (`assetId` & `amount`) */
|
|
2645
|
+
assets: Asset[];
|
|
2646
|
+
}
|
|
2647
|
+
/**
|
|
2648
|
+
* Parameters accepted by `OnchainWallet.send`.
|
|
2649
|
+
*
|
|
2650
|
+
* @remarks
|
|
2651
|
+
* This shape was also used by the deprecated `Wallet.sendBitcoin` method.
|
|
2652
|
+
* New wallet sends should use `Recipient` via `IWallet.send`.
|
|
2653
|
+
*
|
|
2654
|
+
* @see Recipient
|
|
2655
|
+
*/
|
|
2656
|
+
interface SendBitcoinParams {
|
|
2657
|
+
/** Destination address. */
|
|
2658
|
+
address: string;
|
|
2659
|
+
/** Amount to send in satoshis. */
|
|
2660
|
+
amount: number;
|
|
2661
|
+
/** Optional fee rate override in sats/vB. */
|
|
2662
|
+
feeRate?: number;
|
|
2663
|
+
/**
|
|
2664
|
+
* Optional memo associated with the transaction.
|
|
2665
|
+
* @deprecated Does not appear to have ever been used.
|
|
2666
|
+
*/
|
|
2667
|
+
memo?: string;
|
|
2668
|
+
/** Optional explicit virtual output selection used by `Wallet.sendBitcoin`. */
|
|
2669
|
+
selectedVtxos?: ExtendedVirtualCoin[];
|
|
2670
|
+
}
|
|
2671
|
+
/**
|
|
2672
|
+
* Asset amount paired with an asset id.
|
|
2673
|
+
*
|
|
2674
|
+
* @see AssetDetails
|
|
2675
|
+
*/
|
|
2676
|
+
interface Asset {
|
|
2677
|
+
/** Asset identifier. */
|
|
2678
|
+
assetId: string;
|
|
2679
|
+
/**
|
|
2680
|
+
* Asset amount in base units. Typed as `bigint` because asset
|
|
2681
|
+
* supplies routinely exceed `Number.MAX_SAFE_INTEGER` (2^53 - 1)
|
|
2682
|
+
* and silently truncating in arithmetic would corrupt balances.
|
|
2683
|
+
*/
|
|
2684
|
+
amount: bigint;
|
|
2685
|
+
}
|
|
2686
|
+
/**
|
|
2687
|
+
* Recipient accepted by `IWallet.send`.
|
|
2688
|
+
*
|
|
2689
|
+
* @see IWallet.send
|
|
2690
|
+
*/
|
|
2691
|
+
interface Recipient {
|
|
2692
|
+
address: string;
|
|
2693
|
+
/**
|
|
2694
|
+
* BTC amount in satoshis.
|
|
2695
|
+
*
|
|
2696
|
+
* @defaultValue Dust amount (`330`).
|
|
2697
|
+
*/
|
|
2698
|
+
amount?: number;
|
|
2699
|
+
/** Assets to send to the same recipient (`assetId` & `amount`) */
|
|
2700
|
+
assets?: Asset[];
|
|
2701
|
+
}
|
|
2702
|
+
/**
|
|
2703
|
+
* Known asset metadata fields.
|
|
2704
|
+
*
|
|
2705
|
+
* @remarks
|
|
2706
|
+
* Additional metadata keys are allowed through `AssetMetadata`.
|
|
2707
|
+
*
|
|
2708
|
+
* @see AssetMetadata
|
|
2709
|
+
*/
|
|
2710
|
+
type KnownMetadata = Partial<{
|
|
2711
|
+
/** Asset name, e.g. "Tether USD" */
|
|
2712
|
+
name: string;
|
|
2713
|
+
/** Asset symbol, e.g. "USDT" */
|
|
2714
|
+
ticker: string;
|
|
2715
|
+
/**
|
|
2716
|
+
* Amount of decimal places to adjust the `amount` for
|
|
2717
|
+
* (e.g. `1_000_000` adjusted for `6` decimals = `1`)
|
|
2718
|
+
*/
|
|
2719
|
+
decimals: number;
|
|
2720
|
+
/** Image source that can be passed to an `<img src>` attribute. */
|
|
2721
|
+
icon: string;
|
|
2722
|
+
}>;
|
|
2723
|
+
/**
|
|
2724
|
+
* Asset metadata including known fields and arbitrary extension keys.
|
|
2725
|
+
*
|
|
2726
|
+
* @see KnownMetadata
|
|
2727
|
+
*/
|
|
2728
|
+
type AssetMetadata = KnownMetadata & Record<string, unknown>;
|
|
2729
|
+
/**
|
|
2730
|
+
* Asset details returned by `IAssetManager.getAssetDetails`.
|
|
2731
|
+
*
|
|
2732
|
+
* @see IAssetManager.getAssetDetails
|
|
2733
|
+
* @see AssetMetadata
|
|
2734
|
+
*/
|
|
2735
|
+
type AssetDetails = {
|
|
2736
|
+
/** Asset identifier. */
|
|
2737
|
+
assetId: string;
|
|
2738
|
+
/**
|
|
2739
|
+
* Total issued supply in base units. Typed as `bigint` for the
|
|
2740
|
+
* same reason as {@link Asset.amount} — supplies often exceed
|
|
2741
|
+
* `Number.MAX_SAFE_INTEGER`.
|
|
2742
|
+
*/
|
|
2743
|
+
supply: bigint;
|
|
2744
|
+
/** Optional immutable metadata associated with the asset. */
|
|
2745
|
+
metadata?: AssetMetadata;
|
|
2746
|
+
/** Optional control asset id required for future reissuance. */
|
|
2747
|
+
controlAssetId?: string;
|
|
2748
|
+
};
|
|
2749
|
+
/**
|
|
2750
|
+
* Parameters accepted by `IAssetManager.issue`.
|
|
2751
|
+
*
|
|
2752
|
+
* @see IAssetManager.issue
|
|
2753
|
+
* @see IssuanceResult
|
|
2754
|
+
*/
|
|
2755
|
+
interface IssuanceParams {
|
|
2756
|
+
/** Initial amount of asset to issue */
|
|
2757
|
+
amount: bigint;
|
|
2758
|
+
/** Optional control asset ID that can be used for future reissuance */
|
|
2759
|
+
controlAssetId?: string;
|
|
2760
|
+
/** Immutable asset metadata including `ticker`, `decimals`, `icon` */
|
|
2761
|
+
metadata?: AssetMetadata;
|
|
2762
|
+
}
|
|
2763
|
+
/**
|
|
2764
|
+
* Result returned by `IAssetManager.issue`.
|
|
2765
|
+
*
|
|
2766
|
+
* @see IAssetManager.issue
|
|
2767
|
+
* @see IssuanceParams
|
|
2768
|
+
*/
|
|
2769
|
+
interface IssuanceResult {
|
|
2770
|
+
/** Arkade transaction ID where the asset was issued */
|
|
2771
|
+
arkTxId: string;
|
|
2772
|
+
/** Permanent asset ID, made up of above `arkTxId` and zero-based asset group index */
|
|
2773
|
+
assetId: string;
|
|
2774
|
+
}
|
|
2775
|
+
/**
|
|
2776
|
+
* Parameters accepted by `IAssetManager.reissue`.
|
|
2777
|
+
*
|
|
2778
|
+
* @see IAssetManager.reissue
|
|
2779
|
+
*/
|
|
2780
|
+
interface ReissuanceParams {
|
|
2781
|
+
/** Existing asset ID, made up of genesis (Arkade) transaction ID and zero-based asset group index */
|
|
2782
|
+
assetId: string;
|
|
2783
|
+
/** Amount of asset to issue */
|
|
2784
|
+
amount: bigint;
|
|
2785
|
+
}
|
|
2786
|
+
/**
|
|
2787
|
+
* Parameters accepted by `IAssetManager.burn`.
|
|
2788
|
+
*
|
|
2789
|
+
* @see IAssetManager.burn
|
|
2790
|
+
*/
|
|
2791
|
+
interface BurnParams {
|
|
2792
|
+
/** Existing asset ID, made up of genesis (Arkade) transaction ID and zero-based asset group index */
|
|
2793
|
+
assetId: string;
|
|
2794
|
+
/** Amount of asset to burn */
|
|
2795
|
+
amount: bigint;
|
|
2796
|
+
}
|
|
2797
|
+
/**
|
|
2798
|
+
* Explicit inputs and outputs accepted by `IWallet.settle`.
|
|
2799
|
+
*
|
|
2800
|
+
* @remarks
|
|
2801
|
+
* Inputs can include both offchain virtual outputs and onchain boarding inputs.
|
|
2802
|
+
*
|
|
2803
|
+
* @see IWallet.settle
|
|
2804
|
+
* @see Output
|
|
2805
|
+
*/
|
|
2806
|
+
interface SettleParams {
|
|
2807
|
+
/** Offchain virtual outputs and/or onchain boarding inputs to settle. */
|
|
2808
|
+
inputs: ExtendedCoin[];
|
|
2809
|
+
/** Optional onchain outputs to create (i.e., exit to). */
|
|
2810
|
+
outputs: Output[];
|
|
2811
|
+
}
|
|
2812
|
+
/**
|
|
2813
|
+
* Onchain output status
|
|
2814
|
+
*/
|
|
2815
|
+
interface Status {
|
|
2816
|
+
/** Whether the output is confirmed */
|
|
2817
|
+
confirmed: boolean;
|
|
2818
|
+
/**
|
|
2819
|
+
* Whether the output exists as a finalized batch leaf.
|
|
2820
|
+
* In the current mapping this is `true` for settled and swept virtual outputs,
|
|
2821
|
+
* and `false` for preconfirmed virtual outputs.
|
|
2822
|
+
*
|
|
2823
|
+
* @remarks
|
|
2824
|
+
* `isLeaf` is currently derived from `!isPreconfirmed` in the indexer mapping.
|
|
2825
|
+
* It is used primarily by transaction history classification to distinguish
|
|
2826
|
+
* finalized batch outputs from preconfirmed offchain outputs.
|
|
2827
|
+
*/
|
|
2828
|
+
isLeaf?: boolean;
|
|
2829
|
+
/** Block height where the output was confirmed, when known. */
|
|
2830
|
+
block_height?: number;
|
|
2831
|
+
/** Block hash where the output was confirmed, when known. */
|
|
2832
|
+
block_hash?: string;
|
|
2833
|
+
/** Block time where the output was confirmed, when known. */
|
|
2834
|
+
block_time?: number;
|
|
2835
|
+
}
|
|
2836
|
+
/**
|
|
2837
|
+
* Virtual output status
|
|
2838
|
+
*/
|
|
2839
|
+
interface VirtualStatus {
|
|
2840
|
+
/**
|
|
2841
|
+
* Extended output status.
|
|
2842
|
+
*
|
|
2843
|
+
* - `preconfirmed`: not yet finalized in a batch
|
|
2844
|
+
* - `settled`: finalized in a batch
|
|
2845
|
+
* - `swept`: expired/swept and recoverable in a new batch
|
|
2846
|
+
* - `spent`: destroyed by a later transaction
|
|
2847
|
+
*
|
|
2848
|
+
* @remarks
|
|
2849
|
+
* `state` is the high-level lifecycle summary used throughout wallet balance,
|
|
2850
|
+
* recovery, and transaction history logic.
|
|
2851
|
+
*/
|
|
2852
|
+
state: "preconfirmed" | "settled" | "swept" | "spent";
|
|
2853
|
+
/**
|
|
2854
|
+
* Which batch commitment transaction(s) this virtual output depends on.
|
|
2855
|
+
*
|
|
2856
|
+
* @remarks
|
|
2857
|
+
* The history builder uses these ids to group received batch transactions and
|
|
2858
|
+
* relate refreshed or forfeited virtual outputs back to the same batch.
|
|
2859
|
+
*/
|
|
2860
|
+
commitmentTxIds?: string[];
|
|
2861
|
+
/**
|
|
2862
|
+
* The earliest point at which this virtual output stops being safely preconfirmed.
|
|
2863
|
+
*
|
|
2864
|
+
* @remarks
|
|
2865
|
+
* The value is stored in milliseconds in the wallet model and is used by expiry
|
|
2866
|
+
* and recovery logic to decide when a virtual output can be swept or renewed.
|
|
2867
|
+
*/
|
|
2868
|
+
batchExpiry?: number;
|
|
2869
|
+
}
|
|
2870
|
+
/** Onchain output location data. */
|
|
2871
|
+
interface Outpoint {
|
|
2872
|
+
/** Transaction ID where the output was created */
|
|
2873
|
+
txid: string;
|
|
2874
|
+
/** Transaction output index for this output */
|
|
2875
|
+
vout: number;
|
|
2876
|
+
}
|
|
2877
|
+
/**
|
|
2878
|
+
* Onchain output data.
|
|
2879
|
+
*
|
|
2880
|
+
* @see Outpoint
|
|
2881
|
+
*/
|
|
2882
|
+
interface Coin extends Outpoint {
|
|
2883
|
+
/** Value of the output in satoshis */
|
|
2884
|
+
value: number;
|
|
2885
|
+
/** Onchain output status */
|
|
2886
|
+
status: Status;
|
|
2887
|
+
}
|
|
2888
|
+
/**
|
|
2889
|
+
* Virtual output data.
|
|
2890
|
+
*
|
|
2891
|
+
* @see Coin
|
|
2892
|
+
* @see VirtualStatus
|
|
2893
|
+
*/
|
|
2894
|
+
interface VirtualCoin extends Coin {
|
|
2895
|
+
/** Creation time of the virtual output. */
|
|
2896
|
+
createdAt: Date;
|
|
2897
|
+
/** The scriptPubKey (hex) locking this virtual output, as returned by the indexer. */
|
|
2898
|
+
script: string;
|
|
2899
|
+
/** Whether this virtual output has been broadcasted onchain via an unroll (unilateral exit). */
|
|
2900
|
+
isUnrolled: boolean;
|
|
2901
|
+
/**
|
|
2902
|
+
* Whether this virtual output is already spent (boolean helper for `spentBy`).
|
|
2903
|
+
* This is not set to true if the virtual output is unrolled or swept, only when it's spent offchain.
|
|
2904
|
+
*/
|
|
2905
|
+
isSpent?: boolean;
|
|
2906
|
+
/** ID of the onchain commitment transaction that settled this output, if applicable. */
|
|
2907
|
+
settledBy?: string;
|
|
2908
|
+
/** ID of the offchain checkpoint transaction that spent this output, if applicable. */
|
|
2909
|
+
spentBy?: string;
|
|
2910
|
+
/** ID of the offchain Arkade transaction that spent the above checkpoint output, if applicable. */
|
|
2911
|
+
arkTxId?: string;
|
|
2912
|
+
/** Virtual output status */
|
|
2913
|
+
virtualStatus: VirtualStatus;
|
|
2914
|
+
/** Assets carried by this virtual output, if any. */
|
|
2915
|
+
assets?: Asset[];
|
|
2916
|
+
}
|
|
2917
|
+
/** Wallet transaction direction. */
|
|
2918
|
+
declare enum TxType {
|
|
2919
|
+
TxSent = "SENT",
|
|
2920
|
+
TxReceived = "RECEIVED"
|
|
2921
|
+
}
|
|
2922
|
+
/**
|
|
2923
|
+
* Composite key used to correlate a wallet transaction across layers.
|
|
2924
|
+
*
|
|
2925
|
+
* @see ArkTransaction
|
|
2926
|
+
*/
|
|
2927
|
+
interface TxKey {
|
|
2928
|
+
/** Boarding transaction id, when applicable. */
|
|
2929
|
+
boardingTxid: string;
|
|
2930
|
+
/** Batch commitment transaction id, when applicable. */
|
|
2931
|
+
commitmentTxid: string;
|
|
2932
|
+
/** Arkade transaction id, when applicable. */
|
|
2933
|
+
arkTxid: string;
|
|
2934
|
+
}
|
|
2935
|
+
/**
|
|
2936
|
+
* Wallet transaction history entry.
|
|
2937
|
+
*
|
|
2938
|
+
* @see TxKey
|
|
2939
|
+
* @see TxType
|
|
2940
|
+
*/
|
|
2941
|
+
interface ArkTransaction {
|
|
2942
|
+
/** Composite key referencing the related transaction ids. */
|
|
2943
|
+
key: TxKey;
|
|
2944
|
+
/** Transaction direction. */
|
|
2945
|
+
type: TxType;
|
|
2946
|
+
/** Net transaction amount in satoshis. */
|
|
2947
|
+
amount: number;
|
|
2948
|
+
/** Whether the transaction is finalized. */
|
|
2949
|
+
settled: boolean;
|
|
2950
|
+
/** Creation timestamp in milliseconds since epoch. */
|
|
2951
|
+
createdAt: number;
|
|
2952
|
+
/** Assets sent or received by this transaction, if any. */
|
|
2953
|
+
assets?: Asset[];
|
|
2954
|
+
}
|
|
2955
|
+
/**
|
|
2956
|
+
* Tapleaves required to spend or settle a wallet output.
|
|
2957
|
+
*
|
|
2958
|
+
* @see ExtendedCoin
|
|
2959
|
+
* @see ExtendedVirtualCoin
|
|
2960
|
+
*/
|
|
2961
|
+
type TapLeaves = {
|
|
2962
|
+
/** Tapleaf script used for the forfeit path. */
|
|
2963
|
+
forfeitTapLeafScript: TapLeafScript;
|
|
2964
|
+
/** Tapleaf script used for the intent path. */
|
|
2965
|
+
intentTapLeafScript: TapLeafScript;
|
|
2966
|
+
};
|
|
2967
|
+
/**
|
|
2968
|
+
* Onchain output data enriched with tapscript and witness data.
|
|
2969
|
+
*
|
|
2970
|
+
* @see Coin
|
|
2971
|
+
* @see TapLeaves
|
|
2972
|
+
*/
|
|
2973
|
+
type ExtendedCoin = TapLeaves & EncodedVtxoScript & Coin & {
|
|
2974
|
+
extraWitness?: Bytes[];
|
|
2975
|
+
};
|
|
2976
|
+
/**
|
|
2977
|
+
* Virtual output data enriched with tapscript and witness data.
|
|
2978
|
+
*
|
|
2979
|
+
* @see VirtualCoin
|
|
2980
|
+
* @see TapLeaves
|
|
2981
|
+
*/
|
|
2982
|
+
type ExtendedVirtualCoin = TapLeaves & EncodedVtxoScript & VirtualCoin & {
|
|
2983
|
+
extraWitness?: Bytes[];
|
|
2984
|
+
};
|
|
2985
|
+
/**
|
|
2986
|
+
* Return whether a virtual output is still spendable.
|
|
2987
|
+
*
|
|
2988
|
+
* @param vtxo - virtual output to inspect
|
|
2989
|
+
* @returns `true` when the virtual output is not marked as spent
|
|
2990
|
+
*
|
|
2991
|
+
* @see isRecoverable
|
|
2992
|
+
* @see isExpired
|
|
2993
|
+
*/
|
|
2994
|
+
declare function isSpendable(vtxo: VirtualCoin): boolean;
|
|
2995
|
+
/**
|
|
2996
|
+
* Return whether a virtual output is recoverable.
|
|
2997
|
+
*
|
|
2998
|
+
* @param vtxo - virtual output to inspect
|
|
2999
|
+
* @returns `true` when the virtual output is swept but still spendable
|
|
3000
|
+
*
|
|
3001
|
+
* @remarks
|
|
3002
|
+
* Recoverable virtual outputs are typically re-settled into fresh virtual outputs by the virtual output manager.
|
|
3003
|
+
*
|
|
3004
|
+
* @see isSpendable
|
|
3005
|
+
* @see isExpired
|
|
3006
|
+
*/
|
|
3007
|
+
declare function isRecoverable(vtxo: VirtualCoin): boolean;
|
|
3008
|
+
/**
|
|
3009
|
+
* Return whether a virtual output should be treated as expired.
|
|
3010
|
+
*
|
|
3011
|
+
* @param vtxo - virtual output to inspect
|
|
3012
|
+
* @returns `true` when the virtual output is swept or its batch expiry has passed
|
|
3013
|
+
* @remarks
|
|
3014
|
+
* On regtest-like environments the upstream expiry value may be expressed as a block
|
|
3015
|
+
* height instead of a timestamp. This helper intentionally ignores obviously non-time
|
|
3016
|
+
* values to avoid false positives.
|
|
3017
|
+
*
|
|
3018
|
+
* @see VirtualStatus.batchExpiry
|
|
3019
|
+
*/
|
|
3020
|
+
declare function isExpired(vtxo: VirtualCoin): boolean;
|
|
3021
|
+
/**
|
|
3022
|
+
* Return whether a virtual output is below the dust threshold.
|
|
3023
|
+
*
|
|
3024
|
+
* @param vtxo - virtual output to inspect
|
|
3025
|
+
* @param dust - dust threshold in satoshis
|
|
3026
|
+
* @returns `true` when the virtual output value is below `dust`
|
|
3027
|
+
*
|
|
3028
|
+
* @see isRecoverable
|
|
3029
|
+
*/
|
|
3030
|
+
declare function isSubdust(vtxo: VirtualCoin, dust: bigint): boolean;
|
|
3031
|
+
/**
|
|
3032
|
+
* Filtering options for `IWallet.getVtxos`.
|
|
3033
|
+
*
|
|
3034
|
+
* @see IWallet.getVtxos
|
|
3035
|
+
*/
|
|
3036
|
+
type GetVtxosFilter = {
|
|
3037
|
+
/** Include swept but still unspent virtual outputs. */
|
|
3038
|
+
withRecoverable?: boolean;
|
|
3039
|
+
/** Include virtual outputs that have been unrolled onchain. */
|
|
3040
|
+
withUnrolled?: boolean;
|
|
3041
|
+
};
|
|
3042
|
+
/**
|
|
3043
|
+
* Readonly asset manager interface for asset operations that do not require wallet identity.
|
|
3044
|
+
*
|
|
3045
|
+
* @see IAssetManager
|
|
3046
|
+
*/
|
|
3047
|
+
interface IReadonlyAssetManager {
|
|
3048
|
+
/**
|
|
3049
|
+
* Fetch metadata and supply data for an asset.
|
|
3050
|
+
*
|
|
3051
|
+
* @param assetId - Asset identifier
|
|
3052
|
+
* @returns Asset details
|
|
3053
|
+
* @see AssetDetails
|
|
3054
|
+
*/
|
|
3055
|
+
getAssetDetails(assetId: string): Promise<AssetDetails>;
|
|
3056
|
+
}
|
|
3057
|
+
/**
|
|
3058
|
+
* Asset manager interface for asset operations that require wallet identity.
|
|
3059
|
+
*
|
|
3060
|
+
* @see IReadonlyAssetManager
|
|
3061
|
+
*/
|
|
3062
|
+
interface IAssetManager extends IReadonlyAssetManager {
|
|
3063
|
+
/**
|
|
3064
|
+
* Issue a new asset.
|
|
3065
|
+
*
|
|
3066
|
+
* @param params - Asset issuance parameters
|
|
3067
|
+
* @returns Asset issuance result
|
|
3068
|
+
* @see IssuanceParams
|
|
3069
|
+
* @see IssuanceResult
|
|
3070
|
+
*/
|
|
3071
|
+
issue(params: IssuanceParams): Promise<IssuanceResult>;
|
|
3072
|
+
/**
|
|
3073
|
+
* Reissue an existing asset.
|
|
3074
|
+
*
|
|
3075
|
+
* @param params - Asset reissuance parameters
|
|
3076
|
+
* @returns Arkade transaction id
|
|
3077
|
+
* @see ReissuanceParams
|
|
3078
|
+
*/
|
|
3079
|
+
reissue(params: ReissuanceParams): Promise<string>;
|
|
3080
|
+
/**
|
|
3081
|
+
* Burn an existing asset.
|
|
3082
|
+
*
|
|
3083
|
+
* @param params - Asset burn parameters
|
|
3084
|
+
* @returns Arkade transaction id
|
|
3085
|
+
* @see BurnParams
|
|
3086
|
+
*/
|
|
3087
|
+
burn(params: BurnParams): Promise<string>;
|
|
3088
|
+
}
|
|
3089
|
+
/**
|
|
3090
|
+
* Core wallet interface for Bitcoin transactions with Arkade protocol support.
|
|
3091
|
+
*
|
|
3092
|
+
* This interface defines the contract that all wallet implementations must follow.
|
|
3093
|
+
* It provides methods for address management, balance checking, virtual output
|
|
3094
|
+
* operations, and transaction management including sending, settling, and unrolling.
|
|
3095
|
+
*
|
|
3096
|
+
* @see IReadonlyWallet
|
|
3097
|
+
*/
|
|
3098
|
+
interface IWallet extends IReadonlyWallet {
|
|
3099
|
+
/** Signing identity associated with the wallet. */
|
|
3100
|
+
identity: Identity;
|
|
3101
|
+
/**
|
|
3102
|
+
* Send bitcoin to a single Arkade address.
|
|
3103
|
+
*
|
|
3104
|
+
* @param params - Destination, amount, fee rate override, etc
|
|
3105
|
+
* @returns Arkade transaction id
|
|
3106
|
+
* @deprecated Use `send`
|
|
3107
|
+
* @see send
|
|
3108
|
+
* @see Recipient
|
|
3109
|
+
*/
|
|
3110
|
+
sendBitcoin(params: SendBitcoinParams): Promise<string>;
|
|
3111
|
+
/**
|
|
3112
|
+
* Settle boarding inputs and/or preconfirmed virtual outputs into settled virtual outputs.
|
|
3113
|
+
*
|
|
3114
|
+
* @param params - Optional explicit settlement inputs and outputs
|
|
3115
|
+
* @param eventCallback - Optional callback that receives settlement events
|
|
3116
|
+
* @returns Arkade transaction id
|
|
3117
|
+
* @see SettleParams
|
|
3118
|
+
*/
|
|
3119
|
+
settle(params?: SettleParams, eventCallback?: (event: SettlementEvent) => void): Promise<string>;
|
|
3120
|
+
/**
|
|
3121
|
+
* Send bitcoin and/or assets to one or more Arkade recipients.
|
|
3122
|
+
*
|
|
3123
|
+
* @param recipients - One or more recipients
|
|
3124
|
+
* @returns Arkade transaction id
|
|
3125
|
+
* @example
|
|
3126
|
+
* ```typescript
|
|
3127
|
+
* await wallet.send({ address: 'ark1q...', amount: 1000 })
|
|
3128
|
+
* ```
|
|
3129
|
+
*/
|
|
3130
|
+
send(...recipients: [Recipient, ...Recipient[]]): Promise<string>;
|
|
3131
|
+
/** Asset manager bound to this wallet instance. */
|
|
3132
|
+
assetManager: IAssetManager;
|
|
3133
|
+
/** @returns Delegation manager, when configured. */
|
|
3134
|
+
getDelegatorManager(): Promise<IDelegatorManager | undefined>;
|
|
3135
|
+
}
|
|
3136
|
+
/**
|
|
3137
|
+
* Readonly wallet interface for Bitcoin transactions with Arkade protocol support.
|
|
3138
|
+
*
|
|
3139
|
+
* This interface defines the contract that all wallet implementations must follow.
|
|
3140
|
+
* It provides methods for address management, balance checking, virtual output
|
|
3141
|
+
* operations, and transaction management including sending, settling, and unrolling.
|
|
3142
|
+
*
|
|
3143
|
+
* @see IWallet
|
|
3144
|
+
*/
|
|
3145
|
+
interface IReadonlyWallet {
|
|
3146
|
+
/** Readonly identity associated with the wallet. */
|
|
3147
|
+
identity: ReadonlyIdentity;
|
|
3148
|
+
/** @returns Arkade address used for offchain funds. */
|
|
3149
|
+
getAddress(): Promise<string>;
|
|
3150
|
+
/** @returns Onchain boarding address used to move funds into Arkade. */
|
|
3151
|
+
getBoardingAddress(): Promise<string>;
|
|
3152
|
+
/** @returns The wallet's combined onchain and offchain balance. */
|
|
3153
|
+
getBalance(): Promise<WalletBalance>;
|
|
3154
|
+
/**
|
|
3155
|
+
* Get virtual outputs tracked by the wallet.
|
|
3156
|
+
*
|
|
3157
|
+
* @param filter - Optional filtering flags
|
|
3158
|
+
* @returns virtual outputs with tapscript and witness data
|
|
3159
|
+
* @see GetVtxosFilter
|
|
3160
|
+
*/
|
|
3161
|
+
getVtxos(filter?: GetVtxosFilter): Promise<ExtendedVirtualCoin[]>;
|
|
3162
|
+
/** @returns Onchain boarding inputs tracked by the wallet. */
|
|
3163
|
+
getBoardingUtxos(): Promise<ExtendedCoin[]>;
|
|
3164
|
+
/** @returns Wallet transaction history derived from boarding and Arkade activity. */
|
|
3165
|
+
getTransactionHistory(): Promise<ArkTransaction[]>;
|
|
3166
|
+
/**
|
|
3167
|
+
* Get the contract manager associated with this wallet.
|
|
3168
|
+
* This is useful for querying contract state and watching for contract events.
|
|
3169
|
+
*
|
|
3170
|
+
* @returns Contract manager instance
|
|
3171
|
+
*/
|
|
3172
|
+
getContractManager(): Promise<IContractManager>;
|
|
3173
|
+
/** Readonly asset manager bound to this wallet instance. */
|
|
3174
|
+
assetManager: IReadonlyAssetManager;
|
|
3175
|
+
}
|
|
3176
|
+
|
|
3177
|
+
type PaginationOptions = {
|
|
3178
|
+
pageIndex?: number;
|
|
3179
|
+
pageSize?: number;
|
|
3180
|
+
};
|
|
3181
|
+
declare enum IndexerTxType {
|
|
3182
|
+
INDEXER_TX_TYPE_UNSPECIFIED = 0,
|
|
3183
|
+
INDEXER_TX_TYPE_RECEIVED = 1,
|
|
3184
|
+
INDEXER_TX_TYPE_SENT = 2
|
|
3185
|
+
}
|
|
3186
|
+
declare enum ChainTxType {
|
|
3187
|
+
UNSPECIFIED = "INDEXER_CHAINED_TX_TYPE_UNSPECIFIED",
|
|
3188
|
+
COMMITMENT = "INDEXER_CHAINED_TX_TYPE_COMMITMENT",
|
|
3189
|
+
ARK = "INDEXER_CHAINED_TX_TYPE_ARK",
|
|
3190
|
+
TREE = "INDEXER_CHAINED_TX_TYPE_TREE",
|
|
3191
|
+
CHECKPOINT = "INDEXER_CHAINED_TX_TYPE_CHECKPOINT"
|
|
3192
|
+
}
|
|
3193
|
+
interface PageResponse {
|
|
3194
|
+
/** Current page index **/
|
|
3195
|
+
current: number;
|
|
3196
|
+
/** Next page index **/
|
|
3197
|
+
next: number;
|
|
3198
|
+
/** Total pages given the page-size used in the query **/
|
|
3199
|
+
total: number;
|
|
3200
|
+
}
|
|
3201
|
+
interface BatchInfo {
|
|
3202
|
+
totalOutputAmount: string;
|
|
3203
|
+
totalOutputVtxos: number;
|
|
3204
|
+
expiresAt: string;
|
|
3205
|
+
swept: boolean;
|
|
3206
|
+
}
|
|
3207
|
+
interface ChainTx {
|
|
3208
|
+
txid: string;
|
|
3209
|
+
expiresAt: string;
|
|
3210
|
+
type: ChainTxType;
|
|
3211
|
+
/** IDs of the transactions in the chain used as input of the current transaction. */
|
|
3212
|
+
spends: string[];
|
|
3213
|
+
}
|
|
3214
|
+
interface CommitmentTx {
|
|
3215
|
+
startedAt: string;
|
|
3216
|
+
endedAt: string;
|
|
3217
|
+
batches: {
|
|
3218
|
+
[key: string]: BatchInfo;
|
|
3219
|
+
};
|
|
3220
|
+
totalInputAmount: string;
|
|
3221
|
+
totalInputVtxos: number;
|
|
3222
|
+
totalOutputAmount: string;
|
|
3223
|
+
totalOutputVtxos: number;
|
|
3224
|
+
}
|
|
3225
|
+
interface Tx {
|
|
3226
|
+
txid: string;
|
|
3227
|
+
children: Record<number, string>;
|
|
3228
|
+
}
|
|
3229
|
+
interface TxHistoryRecord {
|
|
3230
|
+
commitmentTxid?: string;
|
|
3231
|
+
virtualTxid?: string;
|
|
3232
|
+
type: IndexerTxType;
|
|
3233
|
+
amount: string;
|
|
3234
|
+
createdAt: string;
|
|
3235
|
+
isSettled: boolean;
|
|
3236
|
+
settledBy: string;
|
|
3237
|
+
}
|
|
3238
|
+
interface VtxoAsset {
|
|
3239
|
+
assetId: string;
|
|
3240
|
+
amount: string;
|
|
3241
|
+
}
|
|
3242
|
+
interface Vtxo {
|
|
3243
|
+
outpoint: Outpoint;
|
|
3244
|
+
createdAt: string;
|
|
3245
|
+
expiresAt: string | null;
|
|
3246
|
+
amount: string;
|
|
3247
|
+
script: string;
|
|
3248
|
+
isPreconfirmed: boolean;
|
|
3249
|
+
isSwept: boolean;
|
|
3250
|
+
isUnrolled: boolean;
|
|
3251
|
+
isSpent: boolean;
|
|
3252
|
+
spentBy: string | null;
|
|
3253
|
+
commitmentTxids: string[];
|
|
3254
|
+
settledBy?: string;
|
|
3255
|
+
arkTxid?: string;
|
|
3256
|
+
assets?: VtxoAsset[];
|
|
3257
|
+
}
|
|
3258
|
+
interface VtxoChain {
|
|
3259
|
+
chain: ChainTx[];
|
|
3260
|
+
page?: PageResponse;
|
|
3261
|
+
}
|
|
3262
|
+
interface SubscriptionResponse {
|
|
3263
|
+
txid?: string;
|
|
3264
|
+
scripts: string[];
|
|
3265
|
+
newVtxos: VirtualCoin[];
|
|
3266
|
+
spentVtxos: VirtualCoin[];
|
|
3267
|
+
sweptVtxos: VirtualCoin[];
|
|
3268
|
+
tx?: string;
|
|
3269
|
+
checkpointTxs?: Record<string, {
|
|
3270
|
+
txid: string;
|
|
3271
|
+
tx: string;
|
|
3272
|
+
}>;
|
|
3273
|
+
}
|
|
3274
|
+
interface SubscriptionHeartbeat {
|
|
3275
|
+
type: "heartbeat";
|
|
3276
|
+
}
|
|
3277
|
+
interface SubscriptionEvent extends SubscriptionResponse {
|
|
3278
|
+
type: "event";
|
|
3279
|
+
}
|
|
3280
|
+
/**
|
|
3281
|
+
* Filters accepted by `IndexerProvider.getVtxos`.
|
|
3282
|
+
*
|
|
3283
|
+
* @remarks
|
|
3284
|
+
* Exactly one of `scripts` or `outpoints` must be supplied.
|
|
3285
|
+
*
|
|
3286
|
+
* @see IndexerProvider.getVtxos
|
|
3287
|
+
*/
|
|
3288
|
+
type GetVtxosOptions = PaginationOptions & {
|
|
3289
|
+
/** Only return spendable virtual outputs. */
|
|
3290
|
+
spendableOnly?: boolean;
|
|
3291
|
+
/** Only return spent virtual outputs. */
|
|
3292
|
+
spentOnly?: boolean;
|
|
3293
|
+
/** Only return recoverable virtual outputs. */
|
|
3294
|
+
recoverableOnly?: boolean;
|
|
3295
|
+
/** Only return pending/preconfirmed virtual outputs. */
|
|
3296
|
+
pendingOnly?: boolean;
|
|
3297
|
+
/** Only return virtual outputs created after this timestamp. */
|
|
3298
|
+
after?: number;
|
|
3299
|
+
/** Only return virtual outputs created before this timestamp. */
|
|
3300
|
+
before?: number;
|
|
3301
|
+
} & ({
|
|
3302
|
+
/** Scripts to search for matching virtual outputs. */
|
|
3303
|
+
scripts: string[];
|
|
3304
|
+
outpoints?: never;
|
|
3305
|
+
} | {
|
|
3306
|
+
/** Explicit outpoints to fetch. */
|
|
3307
|
+
outpoints: Outpoint[];
|
|
3308
|
+
scripts?: never;
|
|
3309
|
+
});
|
|
3310
|
+
interface IndexerProvider {
|
|
3311
|
+
/**
|
|
3312
|
+
* Fetch the virtual output tree for a batch outpoint.
|
|
3313
|
+
*
|
|
3314
|
+
* @param batchOutpoint - Batch outpoint whose tree should be fetched
|
|
3315
|
+
* @param opts - Optional pagination settings
|
|
3316
|
+
* @returns virtual output tree nodes and optional pagination state
|
|
3317
|
+
*/
|
|
3318
|
+
getVtxoTree(batchOutpoint: Outpoint, opts?: PaginationOptions): Promise<{
|
|
3319
|
+
vtxoTree: Tx[];
|
|
3320
|
+
page?: PageResponse;
|
|
3321
|
+
}>;
|
|
3322
|
+
/**
|
|
3323
|
+
* Fetch the leaf outpoints for a batch virtual output tree.
|
|
3324
|
+
*
|
|
3325
|
+
* @param batchOutpoint - Batch outpoint whose leaf outpoints should be fetched
|
|
3326
|
+
* @param opts - Optional pagination settings
|
|
3327
|
+
* @returns Leaf outpoints and optional pagination state
|
|
3328
|
+
*/
|
|
3329
|
+
getVtxoTreeLeaves(batchOutpoint: Outpoint, opts?: PaginationOptions): Promise<{
|
|
3330
|
+
leaves: Outpoint[];
|
|
3331
|
+
page?: PageResponse;
|
|
3332
|
+
}>;
|
|
3333
|
+
/**
|
|
3334
|
+
* Fetch sweep transactions that spent a batch.
|
|
3335
|
+
*
|
|
3336
|
+
* @param batchOutpoint - Batch outpoint to inspect
|
|
3337
|
+
* @returns Sweep transaction ids
|
|
3338
|
+
*/
|
|
3339
|
+
getBatchSweepTransactions(batchOutpoint: Outpoint): Promise<{
|
|
3340
|
+
sweptBy: string[];
|
|
3341
|
+
}>;
|
|
3342
|
+
/**
|
|
3343
|
+
* Fetch a commitment transaction by txid.
|
|
3344
|
+
*
|
|
3345
|
+
* @param txid - Commitment transaction id
|
|
3346
|
+
* @returns Commitment transaction details
|
|
3347
|
+
*/
|
|
3348
|
+
getCommitmentTx(txid: string): Promise<CommitmentTx>;
|
|
3349
|
+
/**
|
|
3350
|
+
* Fetch connector transactions for a commitment transaction.
|
|
3351
|
+
*
|
|
3352
|
+
* @param txid - Commitment transaction id
|
|
3353
|
+
* @param opts - Optional pagination settings
|
|
3354
|
+
* @returns Connector transactions and optional pagination state
|
|
3355
|
+
*/
|
|
3356
|
+
getCommitmentTxConnectors(txid: string, opts?: PaginationOptions): Promise<{
|
|
3357
|
+
connectors: Tx[];
|
|
3358
|
+
page?: PageResponse;
|
|
3359
|
+
}>;
|
|
3360
|
+
/**
|
|
3361
|
+
* Fetch forfeit transaction ids for a commitment transaction.
|
|
3362
|
+
*
|
|
3363
|
+
* @param txid - Commitment transaction id
|
|
3364
|
+
* @param opts - Optional pagination settings
|
|
3365
|
+
* @returns Forfeit transaction ids and optional pagination state
|
|
3366
|
+
*/
|
|
3367
|
+
getCommitmentTxForfeitTxs(txid: string, opts?: PaginationOptions): Promise<{
|
|
3368
|
+
txids: string[];
|
|
3369
|
+
page?: PageResponse;
|
|
3370
|
+
}>;
|
|
3371
|
+
/**
|
|
3372
|
+
* Open a streamed subscription for a previously created subscription id.
|
|
3373
|
+
*
|
|
3374
|
+
* @param subscriptionId - Subscription identifier returned by `subscribeForScripts`
|
|
3375
|
+
* @param abortSignal - Signal used to terminate the stream
|
|
3376
|
+
* @returns Async iterator of subscription responses
|
|
3377
|
+
*/
|
|
3378
|
+
getSubscription(subscriptionId: string, abortSignal: AbortSignal): AsyncIterableIterator<SubscriptionResponse>;
|
|
3379
|
+
/**
|
|
3380
|
+
* Fetch raw virtual transactions by txid.
|
|
3381
|
+
*
|
|
3382
|
+
* @param txids - Virtual transaction ids to fetch
|
|
3383
|
+
* @param opts - Optional pagination settings
|
|
3384
|
+
* @returns Raw virtual transactions and optional pagination state
|
|
3385
|
+
*/
|
|
3386
|
+
getVirtualTxs(txids: string[], opts?: PaginationOptions): Promise<{
|
|
3387
|
+
txs: string[];
|
|
3388
|
+
page?: PageResponse;
|
|
3389
|
+
}>;
|
|
3390
|
+
/**
|
|
3391
|
+
* Fetch the ancestry chain for a virtual output.
|
|
3392
|
+
*
|
|
3393
|
+
* @param vtxoOutpoint - Virtual output outpoint to inspect
|
|
3394
|
+
* @param opts - Optional pagination settings
|
|
3395
|
+
* @returns Chain data and optional pagination state
|
|
3396
|
+
*/
|
|
3397
|
+
getVtxoChain(vtxoOutpoint: Outpoint, opts?: PaginationOptions): Promise<VtxoChain>;
|
|
3398
|
+
/**
|
|
3399
|
+
* Fetch virtual outputs by script set or outpoints.
|
|
3400
|
+
*
|
|
3401
|
+
* @param opts - Virtual output filters and pagination settings
|
|
3402
|
+
* @returns Virtual outputs and optional pagination state
|
|
3403
|
+
*/
|
|
3404
|
+
getVtxos(opts?: GetVtxosOptions): Promise<{
|
|
3405
|
+
vtxos: VirtualCoin[];
|
|
3406
|
+
page?: PageResponse;
|
|
3407
|
+
}>;
|
|
3408
|
+
/**
|
|
3409
|
+
* Fetch metadata for a specific asset id.
|
|
3410
|
+
*
|
|
3411
|
+
* @param assetId - Asset identifier
|
|
3412
|
+
* @returns Asset details
|
|
3413
|
+
*/
|
|
3414
|
+
getAssetDetails(assetId: string): Promise<AssetDetails>;
|
|
3415
|
+
/**
|
|
3416
|
+
* Create or extend a subscription for a set of scripts.
|
|
3417
|
+
*
|
|
3418
|
+
* @param scripts - Scripts to monitor
|
|
3419
|
+
* @param subscriptionId - Existing subscription id to extend
|
|
3420
|
+
* @returns Subscription id
|
|
3421
|
+
*/
|
|
3422
|
+
subscribeForScripts(scripts: string[], subscriptionId?: string): Promise<string>;
|
|
3423
|
+
/**
|
|
3424
|
+
* Remove some or all scripts from an existing subscription.
|
|
3425
|
+
*
|
|
3426
|
+
* @param subscriptionId - Subscription identifier to update
|
|
3427
|
+
* @param scripts - Scripts to remove, or omit to remove all
|
|
3428
|
+
*/
|
|
3429
|
+
unsubscribeForScripts(subscriptionId: string, scripts?: string[]): Promise<void>;
|
|
3430
|
+
}
|
|
3431
|
+
/**
|
|
3432
|
+
* REST-based indexer provider implementation.
|
|
3433
|
+
* @see https://buf.build/arkade-os/arkd/docs/main:ark.v1#ark.v1.IndexerService
|
|
3434
|
+
* @example
|
|
3435
|
+
* ```typescript
|
|
3436
|
+
* const provider = new RestIndexerProvider('https://arkade.computer');
|
|
3437
|
+
* const commitmentTx = await provider.getCommitmentTx("6686af8f3be3517880821f62e6c3d749b9d6713736a1d8e229a55daa659446b2");
|
|
3438
|
+
* ```
|
|
3439
|
+
*/
|
|
3440
|
+
declare class RestIndexerProvider implements IndexerProvider {
|
|
3441
|
+
serverUrl: string;
|
|
3442
|
+
constructor(serverUrl: string);
|
|
3443
|
+
getVtxoTree(batchOutpoint: Outpoint, opts?: PaginationOptions): Promise<{
|
|
3444
|
+
vtxoTree: Tx[];
|
|
3445
|
+
page?: PageResponse;
|
|
3446
|
+
}>;
|
|
3447
|
+
getVtxoTreeLeaves(batchOutpoint: Outpoint, opts?: PaginationOptions): Promise<{
|
|
3448
|
+
leaves: Outpoint[];
|
|
3449
|
+
page?: PageResponse;
|
|
3450
|
+
}>;
|
|
3451
|
+
getBatchSweepTransactions(batchOutpoint: Outpoint): Promise<{
|
|
3452
|
+
sweptBy: string[];
|
|
3453
|
+
}>;
|
|
3454
|
+
getCommitmentTx(txid: string): Promise<CommitmentTx>;
|
|
3455
|
+
getCommitmentTxConnectors(txid: string, opts?: PaginationOptions): Promise<{
|
|
3456
|
+
connectors: Tx[];
|
|
3457
|
+
page?: PageResponse;
|
|
3458
|
+
}>;
|
|
3459
|
+
getCommitmentTxForfeitTxs(txid: string, opts?: PaginationOptions): Promise<{
|
|
3460
|
+
txids: string[];
|
|
3461
|
+
page?: PageResponse;
|
|
3462
|
+
}>;
|
|
3463
|
+
getSubscription(subscriptionId: string, abortSignal: AbortSignal): AsyncIterableIterator<SubscriptionResponse>;
|
|
3464
|
+
getVirtualTxs(txids: string[], opts?: PaginationOptions): Promise<{
|
|
3465
|
+
txs: string[];
|
|
3466
|
+
page?: PageResponse;
|
|
3467
|
+
}>;
|
|
3468
|
+
getVtxoChain(vtxoOutpoint: Outpoint, opts?: PaginationOptions): Promise<VtxoChain>;
|
|
3469
|
+
getVtxos(opts?: GetVtxosOptions): Promise<{
|
|
3470
|
+
vtxos: VirtualCoin[];
|
|
3471
|
+
page?: PageResponse;
|
|
3472
|
+
}>;
|
|
3473
|
+
getAssetDetails(assetId: string): Promise<AssetDetails>;
|
|
3474
|
+
subscribeForScripts(scripts: string[], subscriptionId?: string): Promise<string>;
|
|
3475
|
+
unsubscribeForScripts(subscriptionId: string, scripts?: string[]): Promise<void>;
|
|
3476
|
+
}
|
|
3477
|
+
|
|
3478
|
+
/**
|
|
3479
|
+
* FeeAmount is a wrapper around a number that represents a fee amount in satoshis floating point.
|
|
3480
|
+
* @param value - The fee amount in floating point.
|
|
3481
|
+
* @example
|
|
3482
|
+
* const fee = new FeeAmount(1.23456789);
|
|
3483
|
+
* console.log(fee.value); // 1.23456789
|
|
3484
|
+
* console.log(fee.satoshis); // 2
|
|
3485
|
+
*/
|
|
3486
|
+
declare class FeeAmount {
|
|
3487
|
+
readonly value: number;
|
|
3488
|
+
static ZERO: FeeAmount;
|
|
3489
|
+
constructor(value: number);
|
|
3490
|
+
/** Returns the fee amount rounded up to whole satoshis. */
|
|
3491
|
+
get satoshis(): number;
|
|
3492
|
+
/** Add two fee amounts together. */
|
|
3493
|
+
add(other: FeeAmount): FeeAmount;
|
|
3494
|
+
}
|
|
3495
|
+
interface IntentFeeConfig {
|
|
3496
|
+
offchainInput?: string;
|
|
3497
|
+
onchainInput?: string;
|
|
3498
|
+
offchainOutput?: string;
|
|
3499
|
+
onchainOutput?: string;
|
|
3500
|
+
}
|
|
3501
|
+
type VtxoType = "recoverable" | "vtxo" | "note";
|
|
3502
|
+
interface OffchainInput {
|
|
3503
|
+
amount: bigint;
|
|
3504
|
+
expiry?: Date;
|
|
3505
|
+
birth?: Date;
|
|
3506
|
+
type: VtxoType;
|
|
3507
|
+
weight: number;
|
|
3508
|
+
}
|
|
3509
|
+
interface OnchainInput {
|
|
3510
|
+
amount: bigint;
|
|
3511
|
+
}
|
|
3512
|
+
interface FeeOutput {
|
|
3513
|
+
amount: bigint;
|
|
3514
|
+
script: string;
|
|
3515
|
+
}
|
|
3516
|
+
|
|
3517
|
+
/** Output requested during settlement or transaction submission. */
|
|
3518
|
+
type Output = {
|
|
3519
|
+
/** Destination address, either onchain or Arkade (offchain). */
|
|
3520
|
+
address: string;
|
|
3521
|
+
/** Amount to send in satoshis. */
|
|
3522
|
+
amount: bigint;
|
|
3523
|
+
};
|
|
3524
|
+
declare enum SettlementEventType {
|
|
3525
|
+
BatchStarted = "batch_started",
|
|
3526
|
+
BatchFinalization = "batch_finalization",
|
|
3527
|
+
BatchFinalized = "batch_finalized",
|
|
3528
|
+
BatchFailed = "batch_failed",
|
|
3529
|
+
TreeSigningStarted = "tree_signing_started",
|
|
3530
|
+
TreeNonces = "tree_nonces",
|
|
3531
|
+
TreeTx = "tree_tx",
|
|
3532
|
+
TreeSignature = "tree_signature",
|
|
3533
|
+
StreamStarted = "stream_started"
|
|
3534
|
+
}
|
|
3535
|
+
type BatchFinalizationEvent = {
|
|
3536
|
+
type: SettlementEventType.BatchFinalization;
|
|
3537
|
+
id: string;
|
|
3538
|
+
commitmentTx: string;
|
|
3539
|
+
};
|
|
3540
|
+
type BatchFinalizedEvent = {
|
|
3541
|
+
type: SettlementEventType.BatchFinalized;
|
|
3542
|
+
id: string;
|
|
3543
|
+
commitmentTxid: string;
|
|
3544
|
+
};
|
|
3545
|
+
type BatchFailedEvent = {
|
|
3546
|
+
type: SettlementEventType.BatchFailed;
|
|
3547
|
+
id: string;
|
|
3548
|
+
reason: string;
|
|
3549
|
+
};
|
|
3550
|
+
type TreeSigningStartedEvent = {
|
|
3551
|
+
type: SettlementEventType.TreeSigningStarted;
|
|
3552
|
+
id: string;
|
|
3553
|
+
cosignersPublicKeys: string[];
|
|
3554
|
+
unsignedCommitmentTx: string;
|
|
3555
|
+
};
|
|
3556
|
+
type TreeNoncesEvent = {
|
|
3557
|
+
type: SettlementEventType.TreeNonces;
|
|
3558
|
+
id: string;
|
|
3559
|
+
topic: string[];
|
|
3560
|
+
txid: string;
|
|
3561
|
+
/** Musig2 public nonces keyed by cosigner public key. */
|
|
3562
|
+
nonces: TreeNonces;
|
|
3563
|
+
};
|
|
3564
|
+
type BatchStartedEvent = {
|
|
3565
|
+
type: SettlementEventType.BatchStarted;
|
|
3566
|
+
id: string;
|
|
3567
|
+
intentIdHashes: string[];
|
|
3568
|
+
batchExpiry: bigint;
|
|
3569
|
+
};
|
|
3570
|
+
type TreeTxEvent = {
|
|
3571
|
+
type: SettlementEventType.TreeTx;
|
|
3572
|
+
id: string;
|
|
3573
|
+
topic: string[];
|
|
3574
|
+
batchIndex: number;
|
|
3575
|
+
chunk: TxTreeNode;
|
|
3576
|
+
};
|
|
3577
|
+
type TreeSignatureEvent = {
|
|
3578
|
+
type: SettlementEventType.TreeSignature;
|
|
3579
|
+
id: string;
|
|
3580
|
+
topic: string[];
|
|
3581
|
+
batchIndex: number;
|
|
3582
|
+
txid: string;
|
|
3583
|
+
signature: string;
|
|
3584
|
+
};
|
|
3585
|
+
type StreamStartedEvent = {
|
|
3586
|
+
type: SettlementEventType.StreamStarted;
|
|
3587
|
+
id: string;
|
|
3588
|
+
};
|
|
3589
|
+
type SettlementEvent = BatchFinalizationEvent | BatchFinalizedEvent | BatchFailedEvent | TreeSigningStartedEvent | TreeNoncesEvent | BatchStartedEvent | TreeTxEvent | TreeSignatureEvent | StreamStartedEvent;
|
|
3590
|
+
interface ScheduledSession {
|
|
3591
|
+
duration: bigint;
|
|
3592
|
+
fees: FeeInfo;
|
|
3593
|
+
nextEndTime: bigint;
|
|
3594
|
+
nextStartTime: bigint;
|
|
3595
|
+
period: bigint;
|
|
3596
|
+
}
|
|
3597
|
+
interface FeeInfo {
|
|
3598
|
+
intentFee: IntentFeeConfig;
|
|
3599
|
+
txFeeRate: string;
|
|
3600
|
+
}
|
|
3601
|
+
interface PendingTx {
|
|
3602
|
+
arkTxid: string;
|
|
3603
|
+
finalArkTx: string;
|
|
3604
|
+
signedCheckpointTxs: string[];
|
|
3605
|
+
}
|
|
3606
|
+
interface DeprecatedSigner {
|
|
3607
|
+
cutoffDate: bigint;
|
|
3608
|
+
pubkey: string;
|
|
3609
|
+
}
|
|
3610
|
+
type ServiceStatus = Record<string, string>;
|
|
3611
|
+
interface ArkInfo {
|
|
3612
|
+
boardingExitDelay: bigint;
|
|
3613
|
+
checkpointTapscript: string;
|
|
3614
|
+
deprecatedSigners: DeprecatedSigner[];
|
|
3615
|
+
digest: string;
|
|
3616
|
+
dust: bigint;
|
|
3617
|
+
fees: FeeInfo;
|
|
3618
|
+
forfeitAddress: string;
|
|
3619
|
+
forfeitPubkey: string;
|
|
3620
|
+
network: string;
|
|
3621
|
+
scheduledSession?: ScheduledSession;
|
|
3622
|
+
serviceStatus: ServiceStatus;
|
|
3623
|
+
sessionDuration: bigint;
|
|
3624
|
+
signerPubkey: string;
|
|
3625
|
+
unilateralExitDelay: bigint;
|
|
3626
|
+
/**
|
|
3627
|
+
* Maximum boarding input amount.
|
|
3628
|
+
*
|
|
3629
|
+
* @remarks
|
|
3630
|
+
* `-1` means unlimited, while `0` disables boarding.
|
|
3631
|
+
*/
|
|
3632
|
+
utxoMaxAmount: bigint;
|
|
3633
|
+
utxoMinAmount: bigint;
|
|
3634
|
+
version: string;
|
|
3635
|
+
/**
|
|
3636
|
+
* Maximum virtual output amount.
|
|
3637
|
+
*
|
|
3638
|
+
* @remarks
|
|
3639
|
+
* `-1` means unlimited.
|
|
3640
|
+
*/
|
|
3641
|
+
vtxoMaxAmount: bigint;
|
|
3642
|
+
vtxoMinAmount: bigint;
|
|
3643
|
+
}
|
|
3644
|
+
/** Signed intent payload sent to the Arkade server. */
|
|
3645
|
+
interface SignedIntent<T extends Intent.Message> {
|
|
3646
|
+
/** Base64-encoded signed proof transaction. */
|
|
3647
|
+
proof: string;
|
|
3648
|
+
/** Intent message payload associated with the proof. */
|
|
3649
|
+
message: T;
|
|
3650
|
+
}
|
|
3651
|
+
/** Transaction notification emitted by the Arkade server stream. */
|
|
3652
|
+
interface TxNotification {
|
|
3653
|
+
/** Transaction id. */
|
|
3654
|
+
txid: string;
|
|
3655
|
+
/** Raw transaction payload. */
|
|
3656
|
+
tx: string;
|
|
3657
|
+
/** Virtual outputs spent by the transaction. */
|
|
3658
|
+
spentVtxos: Vtxo[];
|
|
3659
|
+
/** Virtual outputs made spendable by the transaction. */
|
|
3660
|
+
spendableVtxos: Vtxo[];
|
|
3661
|
+
/** Optional checkpoint transactions associated with the notification. */
|
|
3662
|
+
checkpointTxs?: Record<string, {
|
|
3663
|
+
txid: string;
|
|
3664
|
+
tx: string;
|
|
3665
|
+
}>;
|
|
3666
|
+
}
|
|
3667
|
+
interface ArkProvider {
|
|
3668
|
+
/** Fetch Arkade server configuration and fee settings. */
|
|
3669
|
+
getInfo(): Promise<ArkInfo>;
|
|
3670
|
+
/** Submit a signed Arkade transaction and its checkpoint transactions. */
|
|
3671
|
+
submitTx(signedArkTx: string, checkpointTxs: string[]): Promise<{
|
|
3672
|
+
arkTxid: string;
|
|
3673
|
+
finalArkTx: string;
|
|
3674
|
+
signedCheckpointTxs: string[];
|
|
3675
|
+
}>;
|
|
3676
|
+
/** Finalize a previously submitted Arkade transaction. */
|
|
3677
|
+
finalizeTx(arkTxid: string, finalCheckpointTxs: string[]): Promise<void>;
|
|
3678
|
+
/** Register a signed intent with the Arkade server. */
|
|
3679
|
+
registerIntent(intent: SignedIntent<Intent.RegisterMessage>): Promise<string>;
|
|
3680
|
+
/** Delete a previously registered intent. */
|
|
3681
|
+
deleteIntent(intent: SignedIntent<Intent.DeleteMessage>): Promise<void>;
|
|
3682
|
+
/** Confirm an already registered intent id. */
|
|
3683
|
+
confirmRegistration(intentId: string): Promise<void>;
|
|
3684
|
+
/** Submit musig2 tree nonces for a batch signing session. */
|
|
3685
|
+
submitTreeNonces(batchId: string, pubkey: string, nonces: TreeNonces): Promise<void>;
|
|
3686
|
+
/** Submit musig2 partial signatures for a batch signing session. */
|
|
3687
|
+
submitTreeSignatures(batchId: string, pubkey: string, signatures: TreePartialSigs): Promise<void>;
|
|
3688
|
+
/** Submit signed forfeit transactions for cooperative settlement. */
|
|
3689
|
+
submitSignedForfeitTxs(signedForfeitTxs: string[], signedCommitmentTx?: string): Promise<void>;
|
|
3690
|
+
/** Open the settlement event stream for the given topics. */
|
|
3691
|
+
getEventStream(signal: AbortSignal, topics: string[]): AsyncIterableIterator<SettlementEvent>;
|
|
3692
|
+
/** Stream transaction notifications emitted by the Arkade server. */
|
|
3693
|
+
getTransactionsStream(signal: AbortSignal): AsyncIterableIterator<{
|
|
3694
|
+
commitmentTx?: TxNotification;
|
|
3695
|
+
arkTx?: TxNotification;
|
|
3696
|
+
}>;
|
|
3697
|
+
/** Fetch pending transactions for a signed get-pending-tx intent. */
|
|
3698
|
+
getPendingTxs(intent: SignedIntent<Intent.GetPendingTxMessage>): Promise<PendingTx[]>;
|
|
3699
|
+
}
|
|
3700
|
+
/**
|
|
3701
|
+
* REST-based Arkade provider implementation.
|
|
3702
|
+
*
|
|
3703
|
+
* @see https://buf.build/arkade-os/arkd/docs/main:ark.v1#ark.v1.ArkService
|
|
3704
|
+
* @example
|
|
3705
|
+
* ```typescript
|
|
3706
|
+
* const provider = new RestArkProvider('https://arkade.computer');
|
|
3707
|
+
* const info = await provider.getInfo();
|
|
3708
|
+
* ```
|
|
3709
|
+
*/
|
|
3710
|
+
declare class RestArkProvider implements ArkProvider {
|
|
3711
|
+
serverUrl: string;
|
|
3712
|
+
constructor(serverUrl: string);
|
|
3713
|
+
getInfo(): Promise<ArkInfo>;
|
|
3714
|
+
submitTx(signedArkTx: string, checkpointTxs: string[]): Promise<{
|
|
3715
|
+
arkTxid: string;
|
|
3716
|
+
finalArkTx: string;
|
|
3717
|
+
signedCheckpointTxs: string[];
|
|
3718
|
+
}>;
|
|
3719
|
+
finalizeTx(arkTxid: string, finalCheckpointTxs: string[]): Promise<void>;
|
|
3720
|
+
registerIntent(intent: SignedIntent<Intent.RegisterMessage>): Promise<string>;
|
|
3721
|
+
deleteIntent(intent: SignedIntent<Intent.DeleteMessage>): Promise<void>;
|
|
3722
|
+
confirmRegistration(intentId: string): Promise<void>;
|
|
3723
|
+
submitTreeNonces(batchId: string, pubkey: string, nonces: TreeNonces): Promise<void>;
|
|
3724
|
+
submitTreeSignatures(batchId: string, pubkey: string, signatures: TreePartialSigs): Promise<void>;
|
|
3725
|
+
submitSignedForfeitTxs(signedForfeitTxs: string[], signedCommitmentTx?: string): Promise<void>;
|
|
3726
|
+
getEventStream(signal: AbortSignal, topics: string[]): AsyncIterableIterator<SettlementEvent>;
|
|
3727
|
+
getTransactionsStream(signal: AbortSignal): AsyncIterableIterator<{
|
|
3728
|
+
commitmentTx?: TxNotification;
|
|
3729
|
+
arkTx?: TxNotification;
|
|
3730
|
+
}>;
|
|
3731
|
+
getPendingTxs(intent: SignedIntent<Intent.GetPendingTxMessage>): Promise<PendingTx[]>;
|
|
3732
|
+
protected parseSettlementEvent(data: ProtoTypes.GetEventStreamResponse): SettlementEvent | null;
|
|
3733
|
+
protected parseTransactionNotification(data: ProtoTypes.GetTransactionsStreamResponse): {
|
|
3734
|
+
commitmentTx?: TxNotification;
|
|
3735
|
+
arkTx?: TxNotification;
|
|
3736
|
+
} | null;
|
|
3737
|
+
}
|
|
3738
|
+
declare namespace ProtoTypes {
|
|
3739
|
+
interface BatchStartedEvent {
|
|
3740
|
+
id: string;
|
|
3741
|
+
intentIdHashes: string[];
|
|
3742
|
+
batchExpiry: number;
|
|
3743
|
+
}
|
|
3744
|
+
interface BatchFailed {
|
|
3745
|
+
id: string;
|
|
3746
|
+
reason: string;
|
|
3747
|
+
}
|
|
3748
|
+
export interface BatchFinalizationEvent {
|
|
3749
|
+
id: string;
|
|
3750
|
+
commitmentTx: string;
|
|
3751
|
+
}
|
|
3752
|
+
interface BatchFinalizedEvent {
|
|
3753
|
+
id: string;
|
|
3754
|
+
commitmentTxid: string;
|
|
3755
|
+
}
|
|
3756
|
+
interface TreeSigningStartedEvent {
|
|
3757
|
+
id: string;
|
|
3758
|
+
cosignersPubkeys: string[];
|
|
3759
|
+
unsignedCommitmentTx: string;
|
|
3760
|
+
}
|
|
3761
|
+
interface TreeNoncesAggregatedEvent {
|
|
3762
|
+
id: string;
|
|
3763
|
+
treeNonces: Record<string, string>;
|
|
3764
|
+
}
|
|
3765
|
+
interface TreeNoncesEvent {
|
|
3766
|
+
id: string;
|
|
3767
|
+
topic: string[];
|
|
3768
|
+
txid: string;
|
|
3769
|
+
nonces: Record<string, string>;
|
|
3770
|
+
}
|
|
3771
|
+
interface TreeTxEvent {
|
|
3772
|
+
id: string;
|
|
3773
|
+
topic: string[];
|
|
3774
|
+
batchIndex: number;
|
|
3775
|
+
txid: string;
|
|
3776
|
+
tx: string;
|
|
3777
|
+
children: Record<string, string>;
|
|
3778
|
+
}
|
|
3779
|
+
interface TreeSignatureEvent {
|
|
3780
|
+
id: string;
|
|
3781
|
+
topic: string[];
|
|
3782
|
+
batchIndex: number;
|
|
3783
|
+
txid: string;
|
|
3784
|
+
signature: string;
|
|
3785
|
+
}
|
|
3786
|
+
interface StreamStartedEvent {
|
|
3787
|
+
id: string;
|
|
3788
|
+
}
|
|
3789
|
+
interface Heartbeat {
|
|
3790
|
+
}
|
|
3791
|
+
export interface VtxoData {
|
|
3792
|
+
outpoint: {
|
|
3793
|
+
txid: string;
|
|
3794
|
+
vout: number;
|
|
3795
|
+
};
|
|
3796
|
+
amount: string;
|
|
3797
|
+
script: string;
|
|
3798
|
+
createdAt: string;
|
|
3799
|
+
expiresAt: string | null;
|
|
3800
|
+
commitmentTxids: string[];
|
|
3801
|
+
isPreconfirmed: boolean;
|
|
3802
|
+
isSwept: boolean;
|
|
3803
|
+
isUnrolled: boolean;
|
|
3804
|
+
isSpent: boolean;
|
|
3805
|
+
spentBy: string;
|
|
3806
|
+
settledBy?: string;
|
|
3807
|
+
arkTxid?: string;
|
|
3808
|
+
}
|
|
3809
|
+
export interface GetEventStreamResponse {
|
|
3810
|
+
batchStarted?: BatchStartedEvent;
|
|
3811
|
+
batchFailed?: BatchFailed;
|
|
3812
|
+
batchFinalization?: BatchFinalizationEvent;
|
|
3813
|
+
batchFinalized?: BatchFinalizedEvent;
|
|
3814
|
+
treeSigningStarted?: TreeSigningStartedEvent;
|
|
3815
|
+
treeNoncesAggregated?: TreeNoncesAggregatedEvent;
|
|
3816
|
+
treeNonces?: TreeNoncesEvent;
|
|
3817
|
+
treeTx?: TreeTxEvent;
|
|
3818
|
+
treeSignature?: TreeSignatureEvent;
|
|
3819
|
+
streamStarted?: StreamStartedEvent;
|
|
3820
|
+
heartbeat?: Heartbeat;
|
|
3821
|
+
}
|
|
3822
|
+
export interface GetTransactionsStreamResponse {
|
|
3823
|
+
commitmentTx?: {
|
|
3824
|
+
txid: string;
|
|
3825
|
+
tx: string;
|
|
3826
|
+
spentVtxos: VtxoData[];
|
|
3827
|
+
spendableVtxos: VtxoData[];
|
|
3828
|
+
checkpointTxs?: Record<string, {
|
|
3829
|
+
txid: string;
|
|
3830
|
+
tx: string;
|
|
3831
|
+
}>;
|
|
3832
|
+
};
|
|
3833
|
+
arkTx?: {
|
|
3834
|
+
txid: string;
|
|
3835
|
+
tx: string;
|
|
3836
|
+
spentVtxos: VtxoData[];
|
|
3837
|
+
spendableVtxos: VtxoData[];
|
|
3838
|
+
checkpointTxs?: Record<string, {
|
|
3839
|
+
txid: string;
|
|
3840
|
+
tx: string;
|
|
3841
|
+
}>;
|
|
3842
|
+
};
|
|
3843
|
+
heartbeat?: Heartbeat;
|
|
3844
|
+
}
|
|
3845
|
+
export interface EventData {
|
|
3846
|
+
batchStarted?: BatchStartedEvent;
|
|
3847
|
+
batchFailed?: BatchFailed;
|
|
3848
|
+
batchFinalization?: BatchFinalizationEvent;
|
|
3849
|
+
batchFinalized?: BatchFinalizedEvent;
|
|
3850
|
+
treeSigningStarted?: TreeSigningStartedEvent;
|
|
3851
|
+
treeNoncesAggregated?: TreeNoncesAggregatedEvent;
|
|
3852
|
+
treeTx?: TreeTxEvent;
|
|
3853
|
+
treeSignature?: TreeSignatureEvent;
|
|
3854
|
+
}
|
|
3855
|
+
export interface TransactionData {
|
|
3856
|
+
commitmentTx?: {
|
|
3857
|
+
txid: string;
|
|
3858
|
+
tx: string;
|
|
3859
|
+
spentVtxos: VtxoData[];
|
|
3860
|
+
spendableVtxos: VtxoData[];
|
|
3861
|
+
checkpointTxs?: Record<string, {
|
|
3862
|
+
txid: string;
|
|
3863
|
+
tx: string;
|
|
3864
|
+
}>;
|
|
3865
|
+
};
|
|
3866
|
+
arkTx?: {
|
|
3867
|
+
txid: string;
|
|
3868
|
+
tx: string;
|
|
3869
|
+
spentVtxos: VtxoData[];
|
|
3870
|
+
spendableVtxos: VtxoData[];
|
|
3871
|
+
checkpointTxs?: Record<string, {
|
|
3872
|
+
txid: string;
|
|
3873
|
+
tx: string;
|
|
3874
|
+
}>;
|
|
3875
|
+
};
|
|
3876
|
+
}
|
|
3877
|
+
export { };
|
|
3878
|
+
}
|
|
3879
|
+
|
|
3880
|
+
export { CSVMultisigTapscript as $, type ArkTransaction as A, type BatchStartedEvent as B, type ContractRepository as C, type BatchFailedEvent as D, type ExtendedVirtualCoin as E, type TreeTxEvent as F, type GetVtxosFilter as G, type TreeSignatureEvent as H, type IWallet as I, type DescriptorProvider as J, type Coin as K, type IReadonlyWallet as L, type ReadonlyIdentity as M, type Network as N, type OnchainProvider as O, type DelegatorProvider as P, type ReadonlyWalletConfig as Q, type Recipient as R, type SendBitcoinParams as S, type TxNotification as T, type IReadonlyAssetManager as U, VtxoScript as V, type WalletRepository as W, type NetworkName as X, type ArkInfo as Y, ArkAddress as Z, ContractManager as _, type Identity as a, MultisigTapscript as a$, type SettlementConfig as a0, VtxoManager as a1, type SignerSession as a2, type SignedIntent as a3, Intent as a4, type DescriptorSigningRequest as a5, Transaction as a6, type IntentFeeConfig as a7, type OffchainInput as a8, FeeAmount as a9, type AssetMetadata as aA, type BaseWalletConfig as aB, type BatchInfo as aC, type BatchSignableIdentity as aD, CLTVMultisigTapscript as aE, ChainTxType as aF, type CommitmentTx as aG, ConditionCSVMultisigTapscript as aH, ConditionMultisigTapscript as aI, type ContractBalance as aJ, type ContractEventCallback as aK, type ContractHandler as aL, type ContractManagerConfig as aM, type ContractState as aN, type ContractVtxo as aO, ContractWatcher as aP, type DelegateOptions as aQ, DelegatorManagerImpl as aR, type Discoverable as aS, type DiscoveredContract as aT, type DiscoveryDeps as aU, ESPLORA_URL as aV, EsploraProvider as aW, type ExtendedContractVtxo as aX, type HandlerError as aY, IndexerTxType as aZ, type KnownMetadata as a_, type OnchainInput as aa, type FeeOutput as ab, type ContractWatcherConfig as ac, type FeeInfo as ad, type CreateContractParams as ae, type GetContractsFilter as af, type GetSpendablePathsOptions as ag, type GetAllSpendingPathsOptions as ah, type IssuanceParams as ai, type ReissuanceParams as aj, type BurnParams as ak, type ContractWithVtxos as al, type PathSelection as am, type ContractEvent as an, type AssetDetails as ao, type IssuanceResult as ap, type DelegateInfo as aq, type StorageConfig as ar, type IVtxoManager as as, type ExplorerTransaction as at, type EncodedVtxoScript as au, type Status as av, type Outpoint as aw, type ChainTx as ax, type ArkTapscript as ay, type Asset as az, type WalletConfig as b, type Nonces as b0, type Output as b1, type PageResponse as b2, type PaginationOptions as b3, PartialSig as b4, type PathContext as b5, type ProviderClass as b6, RestDelegatorProvider as b7, type ScanContractsOptions as b8, type ScanResult as b9, isSpendable as bA, isSubdust as bB, isVtxoExpiringSoon as bC, networks as bD, type ScheduledSession as ba, SettlementEventType as bb, type SignRequest as bc, type SubscriptionEvent as bd, type SubscriptionHeartbeat as be, type TapLeaves as bf, TapTreeCoder as bg, TapscriptType as bh, type TreeNonces as bi, type TreePartialSigs as bj, type Tx as bk, type TxHistoryRecord as bl, type TxKey as bm, type TxTreeNode as bn, TxType as bo, type VirtualStatus as bp, type Vtxo as bq, type VtxoChain as br, type VtxoType as bs, type WalletMode as bt, decodeTapscript as bu, getSequence as bv, isBatchSignable as bw, isDiscoverable as bx, isExpired as by, isRecoverable as bz, type WalletBalance as c, type ExtendedCoin as d, type IContractManager as e, type IDelegatorManager as f, type SettleParams as g, type SettlementEvent as h, type IAssetManager as i, RestArkProvider as j, RestIndexerProvider as k, type SubscriptionResponse as l, type ArkProvider as m, type IndexerProvider as n, type RelativeTimelock as o, type TapLeafScript as p, type VirtualCoin as q, type Contract as r, type VtxoRepositoryKey as s, type WalletState as t, type ContractFilter as u, type TreeSigningStartedEvent as v, TxTree as w, type TreeNoncesEvent as x, type BatchFinalizationEvent as y, type BatchFinalizedEvent as z };
|