@arkade-os/sdk 0.4.27 → 0.4.29
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 +45 -116
- 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-ChhTwpLf.d.cts +3892 -0
- package/dist/ark-ChhTwpLf.d.ts +3892 -0
- package/dist/asyncStorageTaskQueue-DW1-BpI7.d.cts +49 -0
- package/dist/{types/worker/expo/asyncStorageTaskQueue.d.ts → asyncStorageTaskQueue-DZ0nUuEJ.d.ts} +6 -3
- package/dist/chunk-5BLDMQED.cjs +18 -0
- package/dist/chunk-5BLDMQED.cjs.map +1 -0
- package/dist/chunk-6FLL2Q36.cjs +2701 -0
- package/dist/chunk-6FLL2Q36.cjs.map +1 -0
- package/dist/chunk-6NWNOLL3.js +2671 -0
- package/dist/chunk-6NWNOLL3.js.map +1 -0
- package/dist/chunk-ABWRLTX5.js +210 -0
- package/dist/chunk-ABWRLTX5.js.map +1 -0
- package/dist/chunk-BVP2U66Q.js +13943 -0
- package/dist/chunk-BVP2U66Q.js.map +1 -0
- package/dist/chunk-GDCTOSMV.cjs +14058 -0
- package/dist/chunk-GDCTOSMV.cjs.map +1 -0
- package/dist/chunk-GIGILVVP.cjs +213 -0
- package/dist/chunk-GIGILVVP.cjs.map +1 -0
- package/dist/chunk-IEO3XDKI.cjs +838 -0
- package/dist/chunk-IEO3XDKI.cjs.map +1 -0
- package/dist/chunk-NSBPE2FW.js +15 -0
- package/dist/chunk-NSBPE2FW.js.map +1 -0
- package/dist/chunk-PJUFOJ2L.cjs +100 -0
- package/dist/chunk-PJUFOJ2L.cjs.map +1 -0
- package/dist/chunk-TH6T23XG.js +95 -0
- package/dist/chunk-TH6T23XG.js.map +1 -0
- package/dist/chunk-TU3LVAPX.js +769 -0
- package/dist/chunk-TU3LVAPX.js.map +1 -0
- package/dist/chunk-WMIPYZSB.cjs +803 -0
- package/dist/chunk-WMIPYZSB.cjs.map +1 -0
- package/dist/chunk-YA4G7RFB.js +829 -0
- package/dist/chunk-YA4G7RFB.js.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-4JBUkUhR.d.cts +84 -0
- package/dist/delegate-DN7RELL1.d.ts +84 -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-Cn82bBUu.d.ts +199 -0
- package/dist/index-DfT5xzgY.d.cts +199 -0
- package/dist/index.cjs +504 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3469 -0
- package/dist/index.d.ts +3469 -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-B-aPfHhK.d.cts +114 -0
- package/dist/taskRunner-B-vG08pX.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 +175 -0
- package/dist/wallet/expo/index.cjs.map +1 -0
- package/dist/wallet/expo/index.d.cts +124 -0
- package/dist/wallet/expo/index.d.ts +124 -0
- package/dist/wallet/expo/index.js +173 -0
- package/dist/wallet/expo/index.js.map +1 -0
- package/dist/wallet-CCtqT2Wb.d.ts +778 -0
- package/dist/wallet-DjgFb_4T.d.cts +778 -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/expo/wallet.d.ts +0 -99
- 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,829 @@
|
|
|
1
|
+
import { VtxoScript, MultisigTapscript, CSVMultisigTapscript, ConditionMultisigTapscript, CLTVMultisigTapscript, ConditionCSVMultisigTapscript, timelockToSequence, sequenceToTimelock } from './chunk-TU3LVAPX.js';
|
|
2
|
+
import { hex } from '@scure/base';
|
|
3
|
+
import { networks, expand } from '@bitcoinerlab/descriptors-scure';
|
|
4
|
+
import { Script } from '@scure/btc-signer';
|
|
5
|
+
|
|
6
|
+
// src/contracts/handlers/registry.ts
|
|
7
|
+
var ContractHandlerRegistry = class {
|
|
8
|
+
handlers = /* @__PURE__ */ new Map();
|
|
9
|
+
/**
|
|
10
|
+
* Register a contract handler.
|
|
11
|
+
*
|
|
12
|
+
* @param handler - The handler to register
|
|
13
|
+
* @throws If a handler for this type is already registered
|
|
14
|
+
*/
|
|
15
|
+
register(handler) {
|
|
16
|
+
if (this.handlers.has(handler.type)) {
|
|
17
|
+
throw new Error(`Contract handler for type '${handler.type}' is already registered`);
|
|
18
|
+
}
|
|
19
|
+
this.handlers.set(handler.type, handler);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get a handler by type.
|
|
23
|
+
*
|
|
24
|
+
* @param type - The contract type
|
|
25
|
+
* @returns The handler, or undefined if not found
|
|
26
|
+
*/
|
|
27
|
+
get(type) {
|
|
28
|
+
return this.handlers.get(type);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Get a handler by type, throwing if not found.
|
|
32
|
+
*
|
|
33
|
+
* @param type - The contract type
|
|
34
|
+
* @returns The handler
|
|
35
|
+
* @throws If no handler is registered for this type
|
|
36
|
+
*/
|
|
37
|
+
getOrThrow(type) {
|
|
38
|
+
const handler = this.get(type);
|
|
39
|
+
if (!handler) {
|
|
40
|
+
throw new Error(`No contract handler registered for type '${type}'`);
|
|
41
|
+
}
|
|
42
|
+
return handler;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Check if a handler is registered.
|
|
46
|
+
*
|
|
47
|
+
* @param type - The contract type
|
|
48
|
+
*/
|
|
49
|
+
has(type) {
|
|
50
|
+
return this.handlers.has(type);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get all registered types.
|
|
54
|
+
*/
|
|
55
|
+
getRegisteredTypes() {
|
|
56
|
+
return Array.from(this.handlers.keys());
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Unregister a handler (mainly for testing).
|
|
60
|
+
*/
|
|
61
|
+
unregister(type) {
|
|
62
|
+
return this.handlers.delete(type);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Clear all handlers (mainly for testing).
|
|
66
|
+
*/
|
|
67
|
+
clear() {
|
|
68
|
+
this.handlers.clear();
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var contractHandlers = new ContractHandlerRegistry();
|
|
72
|
+
var DefaultVtxo;
|
|
73
|
+
((DefaultVtxo2) => {
|
|
74
|
+
class Script2 extends VtxoScript {
|
|
75
|
+
/** Create the default virtual output script with one forfeit path and one exit path. */
|
|
76
|
+
constructor(options) {
|
|
77
|
+
const { pubKey, serverPubKey, csvTimelock = Script2.DEFAULT_TIMELOCK } = options;
|
|
78
|
+
const forfeitScript = MultisigTapscript.encode({
|
|
79
|
+
pubkeys: [pubKey, serverPubKey]
|
|
80
|
+
}).script;
|
|
81
|
+
const exitScript = CSVMultisigTapscript.encode({
|
|
82
|
+
timelock: csvTimelock,
|
|
83
|
+
pubkeys: [pubKey]
|
|
84
|
+
}).script;
|
|
85
|
+
super([forfeitScript, exitScript]);
|
|
86
|
+
this.options = options;
|
|
87
|
+
this.forfeitScript = hex.encode(forfeitScript);
|
|
88
|
+
this.exitScript = hex.encode(exitScript);
|
|
89
|
+
}
|
|
90
|
+
static DEFAULT_TIMELOCK = {
|
|
91
|
+
value: 144n,
|
|
92
|
+
type: "blocks"
|
|
93
|
+
};
|
|
94
|
+
// 1 day in blocks
|
|
95
|
+
forfeitScript;
|
|
96
|
+
exitScript;
|
|
97
|
+
/** Return the forfeit tapleaf script. */
|
|
98
|
+
forfeit() {
|
|
99
|
+
return this.findLeaf(this.forfeitScript);
|
|
100
|
+
}
|
|
101
|
+
/** Return the unilateral exit tapleaf script. */
|
|
102
|
+
exit() {
|
|
103
|
+
return this.findLeaf(this.exitScript);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
DefaultVtxo2.Script = Script2;
|
|
107
|
+
})(DefaultVtxo || (DefaultVtxo = {}));
|
|
108
|
+
function isMainnetDescriptor(descriptor) {
|
|
109
|
+
return !descriptor.includes("tpub");
|
|
110
|
+
}
|
|
111
|
+
function descriptorIsOurs(candidate, ourDescriptor, ourXOnlyPubkey) {
|
|
112
|
+
if (!isDescriptor(candidate)) return false;
|
|
113
|
+
try {
|
|
114
|
+
const candidateInfo = expand({
|
|
115
|
+
descriptor: candidate,
|
|
116
|
+
network: isMainnetDescriptor(candidate) ? networks.bitcoin : networks.testnet
|
|
117
|
+
}).expansionMap?.["@0"];
|
|
118
|
+
if (!candidateInfo) return false;
|
|
119
|
+
if (candidateInfo.bip32) {
|
|
120
|
+
const ourBip32 = expand({
|
|
121
|
+
descriptor: ourDescriptor,
|
|
122
|
+
network: isMainnetDescriptor(ourDescriptor) ? networks.bitcoin : networks.testnet
|
|
123
|
+
}).expansionMap?.["@0"]?.bip32;
|
|
124
|
+
if (!ourBip32) return false;
|
|
125
|
+
return ourBip32.toBase58() === candidateInfo.bip32.toBase58();
|
|
126
|
+
}
|
|
127
|
+
if (candidateInfo.pubkey) {
|
|
128
|
+
const candidatePub = candidateInfo.pubkey.length === 33 ? candidateInfo.pubkey.subarray(1) : candidateInfo.pubkey;
|
|
129
|
+
if (candidatePub.length !== ourXOnlyPubkey.length) return false;
|
|
130
|
+
return hex.encode(candidatePub) === hex.encode(ourXOnlyPubkey);
|
|
131
|
+
}
|
|
132
|
+
return false;
|
|
133
|
+
} catch {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function isDescriptor(value) {
|
|
138
|
+
if (typeof value !== "string") return false;
|
|
139
|
+
if (!value.startsWith("tr(") || !value.endsWith(")")) return false;
|
|
140
|
+
return value.length > "tr()".length;
|
|
141
|
+
}
|
|
142
|
+
function normalizeToDescriptor(value) {
|
|
143
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
144
|
+
throw new Error("normalizeToDescriptor: expected a non-empty string value");
|
|
145
|
+
}
|
|
146
|
+
if (isDescriptor(value)) {
|
|
147
|
+
return value;
|
|
148
|
+
}
|
|
149
|
+
return `tr(${value})`;
|
|
150
|
+
}
|
|
151
|
+
function extractPubKey(descriptor) {
|
|
152
|
+
if (!isDescriptor(descriptor)) {
|
|
153
|
+
return descriptor;
|
|
154
|
+
}
|
|
155
|
+
const network = isMainnetDescriptor(descriptor) ? networks.bitcoin : networks.testnet;
|
|
156
|
+
const expansion = expand({ descriptor, network });
|
|
157
|
+
if (!expansion.expansionMap) {
|
|
158
|
+
throw new Error("Cannot extract pubkey from descriptor: expansion failed.");
|
|
159
|
+
}
|
|
160
|
+
const key = expansion.expansionMap["@0"];
|
|
161
|
+
if (key?.bip32) {
|
|
162
|
+
throw new Error(
|
|
163
|
+
"Cannot extract pubkey from HD descriptor without derivation. Use DescriptorProvider to derive the key from the xpub."
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
if (!key?.pubkey) {
|
|
167
|
+
throw new Error("Cannot extract pubkey from descriptor: no key found.");
|
|
168
|
+
}
|
|
169
|
+
return hex.encode(key.pubkey);
|
|
170
|
+
}
|
|
171
|
+
function deriveDescriptorLeafPubKey(descriptor) {
|
|
172
|
+
const network = isMainnetDescriptor(descriptor) ? networks.bitcoin : networks.testnet;
|
|
173
|
+
let expansion;
|
|
174
|
+
try {
|
|
175
|
+
expansion = expand({ descriptor, network });
|
|
176
|
+
} catch (e) {
|
|
177
|
+
throw new Error(
|
|
178
|
+
`Cannot derive leaf pubkey from descriptor (length=${descriptor.length}): ensure it is materialized (no wildcard) and parsable.`,
|
|
179
|
+
{ cause: e }
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
const key = expansion.expansionMap?.["@0"];
|
|
183
|
+
if (!key?.pubkey) {
|
|
184
|
+
throw new Error(
|
|
185
|
+
`Cannot derive leaf pubkey from descriptor (length=${descriptor.length}): parsed but no '@0' pubkey in the expansion map.`
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
return key.pubkey;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// src/contracts/handlers/helpers.ts
|
|
192
|
+
function extractRawPubKey(value) {
|
|
193
|
+
if (!isDescriptor(value)) {
|
|
194
|
+
return value.toLowerCase();
|
|
195
|
+
}
|
|
196
|
+
try {
|
|
197
|
+
return extractPubKey(value).toLowerCase();
|
|
198
|
+
} catch {
|
|
199
|
+
return void 0;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function resolveRole(contract, context) {
|
|
203
|
+
if (context.role === "sender" || context.role === "receiver") {
|
|
204
|
+
return context.role;
|
|
205
|
+
}
|
|
206
|
+
const senderKey = contract.params.sender ? extractRawPubKey(contract.params.sender) : void 0;
|
|
207
|
+
const receiverKey = contract.params.receiver ? extractRawPubKey(contract.params.receiver) : void 0;
|
|
208
|
+
const matchRole = (rawWalletKey) => {
|
|
209
|
+
if (!rawWalletKey) return void 0;
|
|
210
|
+
if (senderKey && rawWalletKey === senderKey) {
|
|
211
|
+
return "sender";
|
|
212
|
+
}
|
|
213
|
+
if (receiverKey && rawWalletKey === receiverKey) {
|
|
214
|
+
return "receiver";
|
|
215
|
+
}
|
|
216
|
+
return void 0;
|
|
217
|
+
};
|
|
218
|
+
if (context.walletDescriptor) {
|
|
219
|
+
const walletDescriptorKey = extractRawPubKey(context.walletDescriptor);
|
|
220
|
+
const matchedRole = matchRole(walletDescriptorKey);
|
|
221
|
+
if (matchedRole) {
|
|
222
|
+
return matchedRole;
|
|
223
|
+
}
|
|
224
|
+
if (!walletDescriptorKey && context.walletPubKey) {
|
|
225
|
+
return matchRole(extractRawPubKey(context.walletPubKey));
|
|
226
|
+
}
|
|
227
|
+
return void 0;
|
|
228
|
+
}
|
|
229
|
+
if (context.walletPubKey) {
|
|
230
|
+
return matchRole(extractRawPubKey(context.walletPubKey));
|
|
231
|
+
}
|
|
232
|
+
return void 0;
|
|
233
|
+
}
|
|
234
|
+
var CLTV_HEIGHT_THRESHOLD = 500000000n;
|
|
235
|
+
function isCltvSatisfied(context, locktime) {
|
|
236
|
+
if (locktime < CLTV_HEIGHT_THRESHOLD) {
|
|
237
|
+
if (context.blockHeight === void 0) return false;
|
|
238
|
+
return BigInt(context.blockHeight) >= locktime;
|
|
239
|
+
}
|
|
240
|
+
const currentTimeSec = BigInt(Math.floor(context.currentTime / 1e3));
|
|
241
|
+
return currentTimeSec >= locktime;
|
|
242
|
+
}
|
|
243
|
+
function isCsvSpendable(context, sequence) {
|
|
244
|
+
if (sequence === void 0) return true;
|
|
245
|
+
if (!context.vtxo) return false;
|
|
246
|
+
const timelock = sequenceToTimelock(sequence);
|
|
247
|
+
if (timelock.type === "blocks") {
|
|
248
|
+
if (context.blockHeight === void 0 || context.vtxo.status.block_height === void 0) {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
return context.blockHeight - context.vtxo.status.block_height >= Number(timelock.value);
|
|
252
|
+
}
|
|
253
|
+
if (timelock.type === "seconds") {
|
|
254
|
+
const blockTime = context.vtxo.status.block_time;
|
|
255
|
+
if (blockTime === void 0) return false;
|
|
256
|
+
return context.currentTime / 1e3 - blockTime >= Number(timelock.value);
|
|
257
|
+
}
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// src/contracts/metadata.ts
|
|
262
|
+
var WALLET_RECEIVE_SOURCE = "wallet-receive";
|
|
263
|
+
|
|
264
|
+
// src/contracts/handlers/default.ts
|
|
265
|
+
function extractPubKeyBytes(value) {
|
|
266
|
+
return hex.decode(extractPubKey(normalizeToDescriptor(value)));
|
|
267
|
+
}
|
|
268
|
+
var DefaultContractHandler = {
|
|
269
|
+
type: "default",
|
|
270
|
+
createScript(params) {
|
|
271
|
+
const typed = this.deserializeParams(params);
|
|
272
|
+
return new DefaultVtxo.Script(typed);
|
|
273
|
+
},
|
|
274
|
+
serializeParams(params) {
|
|
275
|
+
return {
|
|
276
|
+
pubKey: hex.encode(params.pubKey),
|
|
277
|
+
serverPubKey: hex.encode(params.serverPubKey),
|
|
278
|
+
csvTimelock: timelockToSequence(params.csvTimelock).toString()
|
|
279
|
+
};
|
|
280
|
+
},
|
|
281
|
+
deserializeParams(params) {
|
|
282
|
+
const csvTimelock = params.csvTimelock ? sequenceToTimelock(Number(params.csvTimelock)) : DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
283
|
+
return {
|
|
284
|
+
pubKey: extractPubKeyBytes(params.pubKey),
|
|
285
|
+
serverPubKey: extractPubKeyBytes(params.serverPubKey),
|
|
286
|
+
csvTimelock
|
|
287
|
+
};
|
|
288
|
+
},
|
|
289
|
+
selectPath(script, contract, context) {
|
|
290
|
+
if (context.collaborative) {
|
|
291
|
+
return { leaf: script.forfeit() };
|
|
292
|
+
}
|
|
293
|
+
const sequence = contract.params.csvTimelock ? Number(contract.params.csvTimelock) : void 0;
|
|
294
|
+
if (!isCsvSpendable(context, sequence)) {
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
return {
|
|
298
|
+
leaf: script.exit(),
|
|
299
|
+
sequence
|
|
300
|
+
};
|
|
301
|
+
},
|
|
302
|
+
getAllSpendingPaths(script, contract, context) {
|
|
303
|
+
const paths = [];
|
|
304
|
+
if (context.collaborative) {
|
|
305
|
+
paths.push({ leaf: script.forfeit() });
|
|
306
|
+
}
|
|
307
|
+
const exitPath = { leaf: script.exit() };
|
|
308
|
+
if (contract.params.csvTimelock) {
|
|
309
|
+
exitPath.sequence = Number(contract.params.csvTimelock);
|
|
310
|
+
}
|
|
311
|
+
paths.push(exitPath);
|
|
312
|
+
return paths;
|
|
313
|
+
},
|
|
314
|
+
getSpendablePaths(script, contract, context) {
|
|
315
|
+
const paths = [];
|
|
316
|
+
if (context.collaborative) {
|
|
317
|
+
paths.push({ leaf: script.forfeit() });
|
|
318
|
+
}
|
|
319
|
+
const exitSequence = contract.params.csvTimelock ? Number(contract.params.csvTimelock) : void 0;
|
|
320
|
+
if (isCsvSpendable(context, exitSequence)) {
|
|
321
|
+
const exitPath = { leaf: script.exit() };
|
|
322
|
+
if (exitSequence !== void 0) {
|
|
323
|
+
exitPath.sequence = exitSequence;
|
|
324
|
+
}
|
|
325
|
+
paths.push(exitPath);
|
|
326
|
+
}
|
|
327
|
+
return paths;
|
|
328
|
+
},
|
|
329
|
+
async discoverAt(index, descriptor, deps) {
|
|
330
|
+
const pubKey = deriveDescriptorLeafPubKey(descriptor);
|
|
331
|
+
const out = [];
|
|
332
|
+
for (const csvTimelock of deps.csvTimelocks) {
|
|
333
|
+
const script = new DefaultVtxo.Script({
|
|
334
|
+
pubKey,
|
|
335
|
+
serverPubKey: deps.serverPubKey,
|
|
336
|
+
csvTimelock
|
|
337
|
+
});
|
|
338
|
+
const scriptHex = hex.encode(script.pkScript);
|
|
339
|
+
const { vtxos } = await deps.indexerProvider.getVtxos({
|
|
340
|
+
scripts: [scriptHex]
|
|
341
|
+
});
|
|
342
|
+
if (vtxos.length === 0) continue;
|
|
343
|
+
out.push({
|
|
344
|
+
type: "default",
|
|
345
|
+
params: {
|
|
346
|
+
pubKey: hex.encode(pubKey),
|
|
347
|
+
serverPubKey: hex.encode(deps.serverPubKey),
|
|
348
|
+
csvTimelock: timelockToSequence(csvTimelock).toString()
|
|
349
|
+
},
|
|
350
|
+
script: scriptHex,
|
|
351
|
+
address: script.address(deps.network.hrp, deps.serverPubKey).encode(),
|
|
352
|
+
...index > 0 ? {
|
|
353
|
+
metadata: {
|
|
354
|
+
source: WALLET_RECEIVE_SOURCE,
|
|
355
|
+
signingDescriptor: descriptor
|
|
356
|
+
}
|
|
357
|
+
} : {}
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
return out;
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
var DelegateVtxo;
|
|
364
|
+
((DelegateVtxo2) => {
|
|
365
|
+
class Script2 extends VtxoScript {
|
|
366
|
+
/** Create a delegated virtual output script with forfeit, exit, and delegate paths. */
|
|
367
|
+
constructor(options) {
|
|
368
|
+
const defaultVtxo = new DefaultVtxo.Script(options);
|
|
369
|
+
const { delegatePubKey, pubKey, serverPubKey } = options;
|
|
370
|
+
const delegateScript = MultisigTapscript.encode({
|
|
371
|
+
pubkeys: [pubKey, delegatePubKey, serverPubKey]
|
|
372
|
+
}).script;
|
|
373
|
+
super([...defaultVtxo.scripts, delegateScript]);
|
|
374
|
+
this.options = options;
|
|
375
|
+
this.defaultVtxo = defaultVtxo;
|
|
376
|
+
this.delegateScript = hex.encode(delegateScript);
|
|
377
|
+
}
|
|
378
|
+
defaultVtxo;
|
|
379
|
+
delegateScript;
|
|
380
|
+
/** Return the forfeit tapleaf script. */
|
|
381
|
+
forfeit() {
|
|
382
|
+
return this.findLeaf(this.defaultVtxo.forfeitScript);
|
|
383
|
+
}
|
|
384
|
+
/** Return the unilateral exit tapleaf script. */
|
|
385
|
+
exit() {
|
|
386
|
+
return this.findLeaf(this.defaultVtxo.exitScript);
|
|
387
|
+
}
|
|
388
|
+
/** Return the delegate tapleaf script. */
|
|
389
|
+
delegate() {
|
|
390
|
+
return this.findLeaf(this.delegateScript);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
DelegateVtxo2.Script = Script2;
|
|
394
|
+
})(DelegateVtxo || (DelegateVtxo = {}));
|
|
395
|
+
|
|
396
|
+
// src/contracts/handlers/delegate.ts
|
|
397
|
+
var DelegateContractHandler = {
|
|
398
|
+
type: "delegate",
|
|
399
|
+
createScript(params) {
|
|
400
|
+
const typed = this.deserializeParams(params);
|
|
401
|
+
return new DelegateVtxo.Script(typed);
|
|
402
|
+
},
|
|
403
|
+
serializeParams(params) {
|
|
404
|
+
return {
|
|
405
|
+
pubKey: hex.encode(params.pubKey),
|
|
406
|
+
serverPubKey: hex.encode(params.serverPubKey),
|
|
407
|
+
delegatePubKey: hex.encode(params.delegatePubKey),
|
|
408
|
+
csvTimelock: timelockToSequence(params.csvTimelock).toString()
|
|
409
|
+
};
|
|
410
|
+
},
|
|
411
|
+
deserializeParams(params) {
|
|
412
|
+
const csvTimelock = params.csvTimelock ? sequenceToTimelock(Number(params.csvTimelock)) : DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
413
|
+
return {
|
|
414
|
+
pubKey: hex.decode(params.pubKey),
|
|
415
|
+
serverPubKey: hex.decode(params.serverPubKey),
|
|
416
|
+
delegatePubKey: hex.decode(params.delegatePubKey),
|
|
417
|
+
csvTimelock
|
|
418
|
+
};
|
|
419
|
+
},
|
|
420
|
+
selectPath(script, contract, context) {
|
|
421
|
+
if (context.collaborative) {
|
|
422
|
+
return { leaf: script.forfeit() };
|
|
423
|
+
}
|
|
424
|
+
const sequence = contract.params.csvTimelock ? Number(contract.params.csvTimelock) : void 0;
|
|
425
|
+
if (!isCsvSpendable(context, sequence)) {
|
|
426
|
+
return null;
|
|
427
|
+
}
|
|
428
|
+
return {
|
|
429
|
+
leaf: script.exit(),
|
|
430
|
+
sequence
|
|
431
|
+
};
|
|
432
|
+
},
|
|
433
|
+
getAllSpendingPaths(script, contract, context) {
|
|
434
|
+
const paths = [];
|
|
435
|
+
if (context.collaborative) {
|
|
436
|
+
paths.push({ leaf: script.forfeit() });
|
|
437
|
+
}
|
|
438
|
+
const exitPath = { leaf: script.exit() };
|
|
439
|
+
if (contract.params.csvTimelock) {
|
|
440
|
+
exitPath.sequence = Number(contract.params.csvTimelock);
|
|
441
|
+
}
|
|
442
|
+
paths.push(exitPath);
|
|
443
|
+
if (context.collaborative) {
|
|
444
|
+
paths.push({ leaf: script.delegate() });
|
|
445
|
+
}
|
|
446
|
+
return paths;
|
|
447
|
+
},
|
|
448
|
+
getSpendablePaths(script, contract, context) {
|
|
449
|
+
const paths = [];
|
|
450
|
+
if (context.collaborative) {
|
|
451
|
+
paths.push({ leaf: script.forfeit() });
|
|
452
|
+
}
|
|
453
|
+
const exitSequence = contract.params.csvTimelock ? Number(contract.params.csvTimelock) : void 0;
|
|
454
|
+
if (isCsvSpendable(context, exitSequence)) {
|
|
455
|
+
const exitPath = { leaf: script.exit() };
|
|
456
|
+
if (exitSequence !== void 0) {
|
|
457
|
+
exitPath.sequence = exitSequence;
|
|
458
|
+
}
|
|
459
|
+
paths.push(exitPath);
|
|
460
|
+
}
|
|
461
|
+
return paths;
|
|
462
|
+
},
|
|
463
|
+
async discoverAt(index, descriptor, deps) {
|
|
464
|
+
if (!deps.delegatePubKey) return [];
|
|
465
|
+
const pubKey = deriveDescriptorLeafPubKey(descriptor);
|
|
466
|
+
const out = [];
|
|
467
|
+
for (const csvTimelock of deps.csvTimelocks) {
|
|
468
|
+
const script = new DelegateVtxo.Script({
|
|
469
|
+
pubKey,
|
|
470
|
+
serverPubKey: deps.serverPubKey,
|
|
471
|
+
delegatePubKey: deps.delegatePubKey,
|
|
472
|
+
csvTimelock
|
|
473
|
+
});
|
|
474
|
+
const scriptHex = hex.encode(script.pkScript);
|
|
475
|
+
const { vtxos } = await deps.indexerProvider.getVtxos({
|
|
476
|
+
scripts: [scriptHex]
|
|
477
|
+
});
|
|
478
|
+
if (vtxos.length === 0) continue;
|
|
479
|
+
out.push({
|
|
480
|
+
type: "delegate",
|
|
481
|
+
params: {
|
|
482
|
+
pubKey: hex.encode(pubKey),
|
|
483
|
+
serverPubKey: hex.encode(deps.serverPubKey),
|
|
484
|
+
delegatePubKey: hex.encode(deps.delegatePubKey),
|
|
485
|
+
csvTimelock: timelockToSequence(csvTimelock).toString()
|
|
486
|
+
},
|
|
487
|
+
script: scriptHex,
|
|
488
|
+
address: script.address(deps.network.hrp, deps.serverPubKey).encode(),
|
|
489
|
+
...index > 0 ? {
|
|
490
|
+
metadata: {
|
|
491
|
+
source: WALLET_RECEIVE_SOURCE,
|
|
492
|
+
signingDescriptor: descriptor
|
|
493
|
+
}
|
|
494
|
+
} : {}
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
return out;
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
var VHTLC;
|
|
501
|
+
((VHTLC2) => {
|
|
502
|
+
class Script2 extends VtxoScript {
|
|
503
|
+
/** Create a VHTLC script from the supplied participant keys, hash, and timelocks. */
|
|
504
|
+
constructor(options) {
|
|
505
|
+
validateOptions(options);
|
|
506
|
+
const {
|
|
507
|
+
sender,
|
|
508
|
+
receiver,
|
|
509
|
+
server,
|
|
510
|
+
preimageHash,
|
|
511
|
+
refundLocktime,
|
|
512
|
+
unilateralClaimDelay,
|
|
513
|
+
unilateralRefundDelay,
|
|
514
|
+
unilateralRefundWithoutReceiverDelay
|
|
515
|
+
} = options;
|
|
516
|
+
const conditionScript = preimageConditionScript(preimageHash);
|
|
517
|
+
const claimScript = ConditionMultisigTapscript.encode({
|
|
518
|
+
conditionScript,
|
|
519
|
+
pubkeys: [receiver, server]
|
|
520
|
+
}).script;
|
|
521
|
+
const refundScript = MultisigTapscript.encode({
|
|
522
|
+
pubkeys: [sender, receiver, server]
|
|
523
|
+
}).script;
|
|
524
|
+
const refundWithoutReceiverScript = CLTVMultisigTapscript.encode({
|
|
525
|
+
absoluteTimelock: refundLocktime,
|
|
526
|
+
pubkeys: [sender, server]
|
|
527
|
+
}).script;
|
|
528
|
+
const unilateralClaimScript = ConditionCSVMultisigTapscript.encode({
|
|
529
|
+
conditionScript,
|
|
530
|
+
timelock: unilateralClaimDelay,
|
|
531
|
+
pubkeys: [receiver]
|
|
532
|
+
}).script;
|
|
533
|
+
const unilateralRefundScript = CSVMultisigTapscript.encode({
|
|
534
|
+
timelock: unilateralRefundDelay,
|
|
535
|
+
pubkeys: [sender, receiver]
|
|
536
|
+
}).script;
|
|
537
|
+
const unilateralRefundWithoutReceiverScript = CSVMultisigTapscript.encode({
|
|
538
|
+
timelock: unilateralRefundWithoutReceiverDelay,
|
|
539
|
+
pubkeys: [sender]
|
|
540
|
+
}).script;
|
|
541
|
+
super([
|
|
542
|
+
claimScript,
|
|
543
|
+
refundScript,
|
|
544
|
+
refundWithoutReceiverScript,
|
|
545
|
+
unilateralClaimScript,
|
|
546
|
+
unilateralRefundScript,
|
|
547
|
+
unilateralRefundWithoutReceiverScript
|
|
548
|
+
]);
|
|
549
|
+
this.options = options;
|
|
550
|
+
this.claimScript = hex.encode(claimScript);
|
|
551
|
+
this.refundScript = hex.encode(refundScript);
|
|
552
|
+
this.refundWithoutReceiverScript = hex.encode(refundWithoutReceiverScript);
|
|
553
|
+
this.unilateralClaimScript = hex.encode(unilateralClaimScript);
|
|
554
|
+
this.unilateralRefundScript = hex.encode(unilateralRefundScript);
|
|
555
|
+
this.unilateralRefundWithoutReceiverScript = hex.encode(
|
|
556
|
+
unilateralRefundWithoutReceiverScript
|
|
557
|
+
);
|
|
558
|
+
}
|
|
559
|
+
claimScript;
|
|
560
|
+
refundScript;
|
|
561
|
+
refundWithoutReceiverScript;
|
|
562
|
+
unilateralClaimScript;
|
|
563
|
+
unilateralRefundScript;
|
|
564
|
+
unilateralRefundWithoutReceiverScript;
|
|
565
|
+
/** Return the collaborative claim tapleaf script. */
|
|
566
|
+
claim() {
|
|
567
|
+
return this.findLeaf(this.claimScript);
|
|
568
|
+
}
|
|
569
|
+
/** Return the collaborative refund tapleaf script. */
|
|
570
|
+
refund() {
|
|
571
|
+
return this.findLeaf(this.refundScript);
|
|
572
|
+
}
|
|
573
|
+
/** Return the refund-without-receiver tapleaf script. */
|
|
574
|
+
refundWithoutReceiver() {
|
|
575
|
+
return this.findLeaf(this.refundWithoutReceiverScript);
|
|
576
|
+
}
|
|
577
|
+
/** Return the unilateral claim tapleaf script. */
|
|
578
|
+
unilateralClaim() {
|
|
579
|
+
return this.findLeaf(this.unilateralClaimScript);
|
|
580
|
+
}
|
|
581
|
+
/** Return the unilateral refund tapleaf script. */
|
|
582
|
+
unilateralRefund() {
|
|
583
|
+
return this.findLeaf(this.unilateralRefundScript);
|
|
584
|
+
}
|
|
585
|
+
/** Return the unilateral refund-without-receiver tapleaf script. */
|
|
586
|
+
unilateralRefundWithoutReceiver() {
|
|
587
|
+
return this.findLeaf(this.unilateralRefundWithoutReceiverScript);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
VHTLC2.Script = Script2;
|
|
591
|
+
function validateOptions(options) {
|
|
592
|
+
const {
|
|
593
|
+
sender,
|
|
594
|
+
receiver,
|
|
595
|
+
server,
|
|
596
|
+
preimageHash,
|
|
597
|
+
refundLocktime,
|
|
598
|
+
unilateralClaimDelay,
|
|
599
|
+
unilateralRefundDelay,
|
|
600
|
+
unilateralRefundWithoutReceiverDelay
|
|
601
|
+
} = options;
|
|
602
|
+
if (!preimageHash || preimageHash.length !== 20) {
|
|
603
|
+
throw new Error("preimage hash must be 20 bytes");
|
|
604
|
+
}
|
|
605
|
+
if (!receiver || receiver.length !== 32) {
|
|
606
|
+
throw new Error("Invalid public key length (receiver)");
|
|
607
|
+
}
|
|
608
|
+
if (!sender || sender.length !== 32) {
|
|
609
|
+
throw new Error("Invalid public key length (sender)");
|
|
610
|
+
}
|
|
611
|
+
if (!server || server.length !== 32) {
|
|
612
|
+
throw new Error("Invalid public key length (server)");
|
|
613
|
+
}
|
|
614
|
+
if (typeof refundLocktime !== "bigint" || refundLocktime <= 0n) {
|
|
615
|
+
throw new Error("refund locktime must be greater than 0");
|
|
616
|
+
}
|
|
617
|
+
if (!unilateralClaimDelay || typeof unilateralClaimDelay.value !== "bigint" || unilateralClaimDelay.value <= 0n) {
|
|
618
|
+
throw new Error("unilateral claim delay must greater than 0");
|
|
619
|
+
}
|
|
620
|
+
if (unilateralClaimDelay.type === "seconds" && unilateralClaimDelay.value % 512n !== 0n) {
|
|
621
|
+
throw new Error("seconds timelock must be multiple of 512");
|
|
622
|
+
}
|
|
623
|
+
if (unilateralClaimDelay.type === "seconds" && unilateralClaimDelay.value < 512n) {
|
|
624
|
+
throw new Error("seconds timelock must be greater or equal to 512");
|
|
625
|
+
}
|
|
626
|
+
if (!unilateralRefundDelay || typeof unilateralRefundDelay.value !== "bigint" || unilateralRefundDelay.value <= 0n) {
|
|
627
|
+
throw new Error("unilateral refund delay must greater than 0");
|
|
628
|
+
}
|
|
629
|
+
if (unilateralRefundDelay.type === "seconds" && unilateralRefundDelay.value % 512n !== 0n) {
|
|
630
|
+
throw new Error("seconds timelock must be multiple of 512");
|
|
631
|
+
}
|
|
632
|
+
if (unilateralRefundDelay.type === "seconds" && unilateralRefundDelay.value < 512n) {
|
|
633
|
+
throw new Error("seconds timelock must be greater or equal to 512");
|
|
634
|
+
}
|
|
635
|
+
if (!unilateralRefundWithoutReceiverDelay || typeof unilateralRefundWithoutReceiverDelay.value !== "bigint" || unilateralRefundWithoutReceiverDelay.value <= 0n) {
|
|
636
|
+
throw new Error("unilateral refund without receiver delay must greater than 0");
|
|
637
|
+
}
|
|
638
|
+
if (unilateralRefundWithoutReceiverDelay.type === "seconds" && unilateralRefundWithoutReceiverDelay.value % 512n !== 0n) {
|
|
639
|
+
throw new Error("seconds timelock must be multiple of 512");
|
|
640
|
+
}
|
|
641
|
+
if (unilateralRefundWithoutReceiverDelay.type === "seconds" && unilateralRefundWithoutReceiverDelay.value < 512n) {
|
|
642
|
+
throw new Error("seconds timelock must be greater or equal to 512");
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
})(VHTLC || (VHTLC = {}));
|
|
646
|
+
function preimageConditionScript(preimageHash) {
|
|
647
|
+
return Script.encode(["HASH160", preimageHash, "EQUAL"]);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// src/contracts/handlers/vhtlc.ts
|
|
651
|
+
var VHTLCContractHandler = {
|
|
652
|
+
type: "vhtlc",
|
|
653
|
+
createScript(params) {
|
|
654
|
+
const typed = this.deserializeParams(params);
|
|
655
|
+
return new VHTLC.Script(typed);
|
|
656
|
+
},
|
|
657
|
+
serializeParams(params) {
|
|
658
|
+
return {
|
|
659
|
+
sender: hex.encode(params.sender),
|
|
660
|
+
receiver: hex.encode(params.receiver),
|
|
661
|
+
server: hex.encode(params.server),
|
|
662
|
+
hash: hex.encode(params.preimageHash),
|
|
663
|
+
refundLocktime: params.refundLocktime.toString(),
|
|
664
|
+
claimDelay: timelockToSequence(params.unilateralClaimDelay).toString(),
|
|
665
|
+
refundDelay: timelockToSequence(params.unilateralRefundDelay).toString(),
|
|
666
|
+
refundNoReceiverDelay: timelockToSequence(
|
|
667
|
+
params.unilateralRefundWithoutReceiverDelay
|
|
668
|
+
).toString()
|
|
669
|
+
};
|
|
670
|
+
},
|
|
671
|
+
deserializeParams(params) {
|
|
672
|
+
return {
|
|
673
|
+
sender: hex.decode(params.sender),
|
|
674
|
+
receiver: hex.decode(params.receiver),
|
|
675
|
+
server: hex.decode(params.server),
|
|
676
|
+
preimageHash: hex.decode(params.hash),
|
|
677
|
+
refundLocktime: BigInt(params.refundLocktime),
|
|
678
|
+
unilateralClaimDelay: sequenceToTimelock(Number(params.claimDelay)),
|
|
679
|
+
unilateralRefundDelay: sequenceToTimelock(Number(params.refundDelay)),
|
|
680
|
+
unilateralRefundWithoutReceiverDelay: sequenceToTimelock(
|
|
681
|
+
Number(params.refundNoReceiverDelay)
|
|
682
|
+
)
|
|
683
|
+
};
|
|
684
|
+
},
|
|
685
|
+
/**
|
|
686
|
+
* Select spending path based on context.
|
|
687
|
+
*
|
|
688
|
+
* Role is determined from `context.role` or by matching
|
|
689
|
+
* `context.walletDescriptor` (preferred) / `context.walletPubKey`
|
|
690
|
+
* against sender/receiver in contract params.
|
|
691
|
+
*/
|
|
692
|
+
selectPath(script, contract, context) {
|
|
693
|
+
const role = resolveRole(contract, context);
|
|
694
|
+
const preimage = contract.params?.preimage;
|
|
695
|
+
const refundLocktime = BigInt(contract.params.refundLocktime);
|
|
696
|
+
if (!role) {
|
|
697
|
+
return null;
|
|
698
|
+
}
|
|
699
|
+
if (context.collaborative) {
|
|
700
|
+
if (role === "receiver" && preimage) {
|
|
701
|
+
return {
|
|
702
|
+
leaf: script.claim(),
|
|
703
|
+
extraWitness: [hex.decode(preimage)]
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
if (role === "sender" && isCltvSatisfied(context, refundLocktime)) {
|
|
707
|
+
return {
|
|
708
|
+
leaf: script.refundWithoutReceiver()
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
return null;
|
|
712
|
+
}
|
|
713
|
+
if (role === "receiver" && preimage) {
|
|
714
|
+
const sequence = Number(contract.params.claimDelay);
|
|
715
|
+
if (!isCsvSpendable(context, sequence)) return null;
|
|
716
|
+
return {
|
|
717
|
+
leaf: script.unilateralClaim(),
|
|
718
|
+
extraWitness: [hex.decode(preimage)],
|
|
719
|
+
sequence
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
if (role === "sender") {
|
|
723
|
+
const sequence = Number(contract.params.refundNoReceiverDelay);
|
|
724
|
+
if (!isCsvSpendable(context, sequence)) return null;
|
|
725
|
+
return {
|
|
726
|
+
leaf: script.unilateralRefundWithoutReceiver(),
|
|
727
|
+
sequence
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
return null;
|
|
731
|
+
},
|
|
732
|
+
/**
|
|
733
|
+
* Get all possible spending paths (no timelock checks).
|
|
734
|
+
*
|
|
735
|
+
* Role is determined from `context.role` or by matching
|
|
736
|
+
* `context.walletDescriptor` (preferred) / `context.walletPubKey`
|
|
737
|
+
* against sender/receiver in contract params.
|
|
738
|
+
*/
|
|
739
|
+
getAllSpendingPaths(script, contract, context) {
|
|
740
|
+
const role = resolveRole(contract, context);
|
|
741
|
+
const paths = [];
|
|
742
|
+
if (!role) {
|
|
743
|
+
return paths;
|
|
744
|
+
}
|
|
745
|
+
const preimage = contract.params?.preimage;
|
|
746
|
+
if (context.collaborative) {
|
|
747
|
+
if (role === "receiver" && preimage) {
|
|
748
|
+
paths.push({
|
|
749
|
+
leaf: script.claim(),
|
|
750
|
+
extraWitness: [hex.decode(preimage)]
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
if (role === "sender") {
|
|
754
|
+
paths.push({
|
|
755
|
+
leaf: script.refundWithoutReceiver()
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
} else {
|
|
759
|
+
if (role === "receiver" && preimage) {
|
|
760
|
+
const sequence = Number(contract.params.claimDelay);
|
|
761
|
+
paths.push({
|
|
762
|
+
leaf: script.unilateralClaim(),
|
|
763
|
+
extraWitness: [hex.decode(preimage)],
|
|
764
|
+
sequence
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
if (role === "sender") {
|
|
768
|
+
const sequence = Number(contract.params.refundNoReceiverDelay);
|
|
769
|
+
paths.push({
|
|
770
|
+
leaf: script.unilateralRefundWithoutReceiver(),
|
|
771
|
+
sequence
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
return paths;
|
|
776
|
+
},
|
|
777
|
+
getSpendablePaths(script, contract, context) {
|
|
778
|
+
const role = resolveRole(contract, context);
|
|
779
|
+
const paths = [];
|
|
780
|
+
if (!role) {
|
|
781
|
+
return paths;
|
|
782
|
+
}
|
|
783
|
+
const preimage = contract.params?.preimage;
|
|
784
|
+
const refundLocktime = BigInt(contract.params.refundLocktime);
|
|
785
|
+
if (context.collaborative) {
|
|
786
|
+
if (role === "receiver" && preimage) {
|
|
787
|
+
paths.push({
|
|
788
|
+
leaf: script.claim(),
|
|
789
|
+
extraWitness: [hex.decode(preimage)]
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
if (role === "sender" && isCltvSatisfied(context, refundLocktime)) {
|
|
793
|
+
paths.push({
|
|
794
|
+
leaf: script.refundWithoutReceiver()
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
return paths;
|
|
798
|
+
}
|
|
799
|
+
if (role === "receiver" && preimage) {
|
|
800
|
+
const sequence = Number(contract.params.claimDelay);
|
|
801
|
+
if (isCsvSpendable(context, sequence)) {
|
|
802
|
+
paths.push({
|
|
803
|
+
leaf: script.unilateralClaim(),
|
|
804
|
+
extraWitness: [hex.decode(preimage)],
|
|
805
|
+
sequence
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
if (role === "sender") {
|
|
810
|
+
const sequence = Number(contract.params.refundNoReceiverDelay);
|
|
811
|
+
if (isCsvSpendable(context, sequence)) {
|
|
812
|
+
paths.push({
|
|
813
|
+
leaf: script.unilateralRefundWithoutReceiver(),
|
|
814
|
+
sequence
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
return paths;
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
|
|
822
|
+
// src/contracts/handlers/index.ts
|
|
823
|
+
contractHandlers.register(DefaultContractHandler);
|
|
824
|
+
contractHandlers.register(DelegateContractHandler);
|
|
825
|
+
contractHandlers.register(VHTLCContractHandler);
|
|
826
|
+
|
|
827
|
+
export { DefaultContractHandler, DefaultVtxo, DelegateContractHandler, DelegateVtxo, VHTLC, VHTLCContractHandler, WALLET_RECEIVE_SOURCE, contractHandlers, deriveDescriptorLeafPubKey, descriptorIsOurs, isMainnetDescriptor };
|
|
828
|
+
//# sourceMappingURL=chunk-YA4G7RFB.js.map
|
|
829
|
+
//# sourceMappingURL=chunk-YA4G7RFB.js.map
|