@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
package/dist/esm/tree/txTree.js
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import { Transaction } from "@scure/btc-signer/transaction.js";
|
|
2
|
-
import { base64 } from "@scure/base";
|
|
3
|
-
import { hex } from "@scure/base";
|
|
4
|
-
/**
|
|
5
|
-
* TxTree is a graph of bitcoin transactions.
|
|
6
|
-
* It is used to represent batch tree created during settlement session
|
|
7
|
-
*/
|
|
8
|
-
export class TxTree {
|
|
9
|
-
constructor(root, children = new Map()) {
|
|
10
|
-
this.root = root;
|
|
11
|
-
this.children = children;
|
|
12
|
-
}
|
|
13
|
-
static create(chunks) {
|
|
14
|
-
if (chunks.length === 0) {
|
|
15
|
-
throw new Error("empty chunks");
|
|
16
|
-
}
|
|
17
|
-
// Create a map to store all chunks by their txid for easy lookup
|
|
18
|
-
const chunksByTxid = new Map();
|
|
19
|
-
for (const chunk of chunks) {
|
|
20
|
-
const decodedChunk = decodeNode(chunk);
|
|
21
|
-
const txid = decodedChunk.tx.id;
|
|
22
|
-
chunksByTxid.set(txid, decodedChunk);
|
|
23
|
-
}
|
|
24
|
-
// Find the root chunks (the ones that aren't referenced as a child)
|
|
25
|
-
const rootTxids = [];
|
|
26
|
-
for (const [txid] of chunksByTxid) {
|
|
27
|
-
let isChild = false;
|
|
28
|
-
for (const [otherTxid, otherChunk] of chunksByTxid) {
|
|
29
|
-
if (otherTxid === txid) {
|
|
30
|
-
// skip self
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
// check if the current chunk is a child of the other chunk
|
|
34
|
-
isChild = hasChild(otherChunk, txid);
|
|
35
|
-
if (isChild) {
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
// if the chunk is not a child of any other chunk, it is a root
|
|
40
|
-
if (!isChild) {
|
|
41
|
-
rootTxids.push(txid);
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (rootTxids.length === 0) {
|
|
46
|
-
throw new Error("no root chunk found");
|
|
47
|
-
}
|
|
48
|
-
if (rootTxids.length > 1) {
|
|
49
|
-
throw new Error(`multiple root chunks found: ${rootTxids.join(", ")}`);
|
|
50
|
-
}
|
|
51
|
-
const graph = buildGraph(rootTxids[0], chunksByTxid);
|
|
52
|
-
if (!graph) {
|
|
53
|
-
throw new Error(`chunk not found for root txid: ${rootTxids[0]}`);
|
|
54
|
-
}
|
|
55
|
-
// verify that the number of chunks is equal to the number node in the graph
|
|
56
|
-
if (graph.nbOfNodes() !== chunks.length) {
|
|
57
|
-
throw new Error(`number of chunks (${chunks.length}) is not equal to the number of nodes in the graph (${graph.nbOfNodes()})`);
|
|
58
|
-
}
|
|
59
|
-
return graph;
|
|
60
|
-
}
|
|
61
|
-
nbOfNodes() {
|
|
62
|
-
let count = 1; // count this node
|
|
63
|
-
for (const child of this.children.values()) {
|
|
64
|
-
count += child.nbOfNodes();
|
|
65
|
-
}
|
|
66
|
-
return count;
|
|
67
|
-
}
|
|
68
|
-
validate() {
|
|
69
|
-
if (!this.root) {
|
|
70
|
-
throw new Error("unexpected nil root");
|
|
71
|
-
}
|
|
72
|
-
const nbOfOutputs = this.root.outputsLength;
|
|
73
|
-
const nbOfInputs = this.root.inputsLength;
|
|
74
|
-
if (nbOfInputs !== 1) {
|
|
75
|
-
throw new Error(`unexpected number of inputs: ${nbOfInputs}, expected 1`);
|
|
76
|
-
}
|
|
77
|
-
// the children map can't be bigger than the number of outputs (excluding the P2A)
|
|
78
|
-
// a graph can be "partial" and specify only some of the outputs as children,
|
|
79
|
-
// that's why we allow len(g.Children) to be less than nbOfOutputs-1
|
|
80
|
-
if (this.children.size > nbOfOutputs - 1) {
|
|
81
|
-
throw new Error(`unexpected number of children: ${this.children.size}, expected maximum ${nbOfOutputs - 1}`);
|
|
82
|
-
}
|
|
83
|
-
// validate each child
|
|
84
|
-
for (const [outputIndex, child] of this.children) {
|
|
85
|
-
if (outputIndex >= nbOfOutputs) {
|
|
86
|
-
throw new Error(`output index ${outputIndex} is out of bounds (nb of outputs: ${nbOfOutputs})`);
|
|
87
|
-
}
|
|
88
|
-
child.validate();
|
|
89
|
-
const childInput = child.root.getInput(0);
|
|
90
|
-
const parentTxid = this.root.id;
|
|
91
|
-
// verify the input of the child is the output of the parent
|
|
92
|
-
if (!childInput.txid ||
|
|
93
|
-
hex.encode(childInput.txid) !== parentTxid ||
|
|
94
|
-
childInput.index !== outputIndex) {
|
|
95
|
-
throw new Error(`input of child ${outputIndex} is not the output of the parent`);
|
|
96
|
-
}
|
|
97
|
-
// verify the sum of the child's outputs is equal to the output of the parent
|
|
98
|
-
let childOutputsSum = 0n;
|
|
99
|
-
for (let i = 0; i < child.root.outputsLength; i++) {
|
|
100
|
-
const output = child.root.getOutput(i);
|
|
101
|
-
if (output?.amount) {
|
|
102
|
-
childOutputsSum += output.amount;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
const parentOutput = this.root.getOutput(outputIndex);
|
|
106
|
-
if (!parentOutput?.amount) {
|
|
107
|
-
throw new Error(`parent output ${outputIndex} has no amount`);
|
|
108
|
-
}
|
|
109
|
-
if (childOutputsSum !== parentOutput.amount) {
|
|
110
|
-
throw new Error(`sum of child's outputs is not equal to the output of the parent: ${childOutputsSum} != ${parentOutput.amount}`);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
leaves() {
|
|
115
|
-
if (this.children.size === 0) {
|
|
116
|
-
return [this.root];
|
|
117
|
-
}
|
|
118
|
-
const leaves = [];
|
|
119
|
-
for (const child of this.children.values()) {
|
|
120
|
-
leaves.push(...child.leaves());
|
|
121
|
-
}
|
|
122
|
-
return leaves;
|
|
123
|
-
}
|
|
124
|
-
get txid() {
|
|
125
|
-
return this.root.id;
|
|
126
|
-
}
|
|
127
|
-
find(txid) {
|
|
128
|
-
if (txid === this.txid) {
|
|
129
|
-
return this;
|
|
130
|
-
}
|
|
131
|
-
for (const child of this.children.values()) {
|
|
132
|
-
const found = child.find(txid);
|
|
133
|
-
if (found) {
|
|
134
|
-
return found;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return null;
|
|
138
|
-
}
|
|
139
|
-
update(txid, fn) {
|
|
140
|
-
if (txid === this.txid) {
|
|
141
|
-
fn(this.root);
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
for (const child of this.children.values()) {
|
|
145
|
-
try {
|
|
146
|
-
child.update(txid, fn);
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
catch (error) {
|
|
150
|
-
// Continue searching in other children if not found
|
|
151
|
-
continue;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
throw new Error(`tx not found: ${txid}`);
|
|
155
|
-
}
|
|
156
|
-
*iterator() {
|
|
157
|
-
for (const child of this.children.values()) {
|
|
158
|
-
yield* child.iterator();
|
|
159
|
-
}
|
|
160
|
-
yield this;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
// Helper function to check if a chunk has a specific child
|
|
164
|
-
function hasChild(chunk, childTxid) {
|
|
165
|
-
return Object.values(chunk.children).includes(childTxid);
|
|
166
|
-
}
|
|
167
|
-
// buildGraph recursively builds the TxGraph starting from the given txid
|
|
168
|
-
function buildGraph(rootTxid, chunksByTxid) {
|
|
169
|
-
const chunk = chunksByTxid.get(rootTxid);
|
|
170
|
-
if (!chunk) {
|
|
171
|
-
return null;
|
|
172
|
-
}
|
|
173
|
-
const rootTx = chunk.tx;
|
|
174
|
-
const children = new Map();
|
|
175
|
-
// Recursively build children graphs
|
|
176
|
-
for (const [outputIndexStr, childTxid] of Object.entries(chunk.children)) {
|
|
177
|
-
const outputIndex = parseInt(outputIndexStr);
|
|
178
|
-
const childGraph = buildGraph(childTxid, chunksByTxid);
|
|
179
|
-
if (childGraph) {
|
|
180
|
-
children.set(outputIndex, childGraph);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return new TxTree(rootTx, children);
|
|
184
|
-
}
|
|
185
|
-
function decodeNode(chunk) {
|
|
186
|
-
const tx = Transaction.fromPSBT(base64.decode(chunk.tx));
|
|
187
|
-
return { tx, children: chunk.children };
|
|
188
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { hex } from "@scure/base";
|
|
2
|
-
import { Transaction } from "@scure/btc-signer/transaction.js";
|
|
3
|
-
import { base64 } from "@scure/base";
|
|
4
|
-
import { aggregateKeys } from "../musig2/index.js";
|
|
5
|
-
import { CosignerPublicKey, getArkPsbtFields } from "../utils/unknownFields.js";
|
|
6
|
-
export const ErrInvalidSettlementTx = (tx) => new Error(`invalid settlement transaction: ${tx}`);
|
|
7
|
-
export const ErrInvalidSettlementTxOutputs = new Error("invalid settlement transaction outputs");
|
|
8
|
-
export const ErrEmptyTree = new Error("empty tree");
|
|
9
|
-
export const ErrNumberOfInputs = new Error("invalid number of inputs");
|
|
10
|
-
export const ErrWrongSettlementTxid = new Error("wrong settlement txid");
|
|
11
|
-
export const ErrInvalidAmount = new Error("invalid amount");
|
|
12
|
-
export const ErrNoLeaves = new Error("no leaves");
|
|
13
|
-
export const ErrInvalidTaprootScript = new Error("invalid taproot script");
|
|
14
|
-
export const ErrInvalidRoundTxOutputs = new Error("invalid round transaction outputs");
|
|
15
|
-
export const ErrWrongCommitmentTxid = new Error("wrong commitment txid");
|
|
16
|
-
export const ErrMissingCosignersPublicKeys = new Error("missing cosigners public keys");
|
|
17
|
-
const BATCH_OUTPUT_VTXO_INDEX = 0;
|
|
18
|
-
const BATCH_OUTPUT_CONNECTORS_INDEX = 1;
|
|
19
|
-
export function validateConnectorsTxGraph(settlementTxB64, connectorsGraph) {
|
|
20
|
-
connectorsGraph.validate();
|
|
21
|
-
if (connectorsGraph.root.inputsLength !== 1)
|
|
22
|
-
throw ErrNumberOfInputs;
|
|
23
|
-
const rootInput = connectorsGraph.root.getInput(0);
|
|
24
|
-
const settlementTx = Transaction.fromPSBT(base64.decode(settlementTxB64));
|
|
25
|
-
if (settlementTx.outputsLength <= BATCH_OUTPUT_CONNECTORS_INDEX)
|
|
26
|
-
throw ErrInvalidSettlementTxOutputs;
|
|
27
|
-
const expectedRootTxid = settlementTx.id;
|
|
28
|
-
if (!rootInput.txid)
|
|
29
|
-
throw ErrWrongSettlementTxid;
|
|
30
|
-
if (hex.encode(rootInput.txid) !== expectedRootTxid)
|
|
31
|
-
throw ErrWrongSettlementTxid;
|
|
32
|
-
if (rootInput.index !== BATCH_OUTPUT_CONNECTORS_INDEX)
|
|
33
|
-
throw ErrWrongSettlementTxid;
|
|
34
|
-
}
|
|
35
|
-
// ValidateVtxoTxGraph checks if the given virtual output tx graph is valid.
|
|
36
|
-
// The function validates:
|
|
37
|
-
// - the number of nodes
|
|
38
|
-
// - the number of leaves
|
|
39
|
-
// - children coherence with parent.
|
|
40
|
-
// - every control block and taproot output scripts.
|
|
41
|
-
// - input and output amounts.
|
|
42
|
-
export function validateVtxoTxGraph(graph, roundTransaction, sweepTapTreeRoot) {
|
|
43
|
-
if (roundTransaction.outputsLength < BATCH_OUTPUT_VTXO_INDEX + 1) {
|
|
44
|
-
throw ErrInvalidRoundTxOutputs;
|
|
45
|
-
}
|
|
46
|
-
const batchOutputAmount = roundTransaction.getOutput(BATCH_OUTPUT_VTXO_INDEX)?.amount;
|
|
47
|
-
if (!batchOutputAmount) {
|
|
48
|
-
throw ErrInvalidRoundTxOutputs;
|
|
49
|
-
}
|
|
50
|
-
if (!graph.root) {
|
|
51
|
-
throw ErrEmptyTree;
|
|
52
|
-
}
|
|
53
|
-
const rootInput = graph.root.getInput(0);
|
|
54
|
-
const commitmentTxid = roundTransaction.id;
|
|
55
|
-
if (!rootInput.txid ||
|
|
56
|
-
hex.encode(rootInput.txid) !== commitmentTxid ||
|
|
57
|
-
rootInput.index !== BATCH_OUTPUT_VTXO_INDEX) {
|
|
58
|
-
throw ErrWrongCommitmentTxid;
|
|
59
|
-
}
|
|
60
|
-
let sumRootValue = 0n;
|
|
61
|
-
for (let i = 0; i < graph.root.outputsLength; i++) {
|
|
62
|
-
const output = graph.root.getOutput(i);
|
|
63
|
-
if (output?.amount) {
|
|
64
|
-
sumRootValue += output.amount;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
if (sumRootValue !== batchOutputAmount) {
|
|
68
|
-
throw ErrInvalidAmount;
|
|
69
|
-
}
|
|
70
|
-
const leaves = graph.leaves();
|
|
71
|
-
if (leaves.length === 0) {
|
|
72
|
-
throw ErrNoLeaves;
|
|
73
|
-
}
|
|
74
|
-
// validate the graph structure
|
|
75
|
-
graph.validate();
|
|
76
|
-
// iterates over all the nodes of the graph to verify that cosigners public keys are corresponding to the parent output
|
|
77
|
-
for (const g of graph.iterator()) {
|
|
78
|
-
for (const [childIndex, child] of g.children) {
|
|
79
|
-
const parentOutput = g.root.getOutput(childIndex);
|
|
80
|
-
if (!parentOutput?.script) {
|
|
81
|
-
throw new Error(`parent output ${childIndex} not found`);
|
|
82
|
-
}
|
|
83
|
-
const previousScriptKey = parentOutput.script.slice(2);
|
|
84
|
-
if (previousScriptKey.length !== 32) {
|
|
85
|
-
throw new Error(`parent output ${childIndex} has invalid script`);
|
|
86
|
-
}
|
|
87
|
-
const cosigners = getArkPsbtFields(child.root, 0, CosignerPublicKey);
|
|
88
|
-
if (cosigners.length === 0) {
|
|
89
|
-
throw ErrMissingCosignersPublicKeys;
|
|
90
|
-
}
|
|
91
|
-
const cosignerKeys = cosigners.map((c) => c.key);
|
|
92
|
-
const { finalKey } = aggregateKeys(cosignerKeys, true, {
|
|
93
|
-
taprootTweak: sweepTapTreeRoot,
|
|
94
|
-
});
|
|
95
|
-
if (!finalKey ||
|
|
96
|
-
hex.encode(finalKey.slice(1)) !== hex.encode(previousScriptKey)) {
|
|
97
|
-
throw ErrInvalidTaprootScript;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
package/dist/esm/utils/anchor.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { hex } from "@scure/base";
|
|
2
|
-
export const ANCHOR_VALUE = 0n;
|
|
3
|
-
export const ANCHOR_PKSCRIPT = new Uint8Array([0x51, 0x02, 0x4e, 0x73]);
|
|
4
|
-
/**
|
|
5
|
-
* A zero-value anchor output.
|
|
6
|
-
*/
|
|
7
|
-
export const P2A = {
|
|
8
|
-
script: ANCHOR_PKSCRIPT,
|
|
9
|
-
amount: ANCHOR_VALUE,
|
|
10
|
-
};
|
|
11
|
-
const hexP2Ascript = hex.encode(P2A.script);
|
|
12
|
-
/**
|
|
13
|
-
* search for anchor in the given transaction.
|
|
14
|
-
* @throws {Error} if the anchor is not found or has the wrong amount
|
|
15
|
-
*/
|
|
16
|
-
export function findP2AOutput(tx) {
|
|
17
|
-
for (let i = 0; i < tx.outputsLength; i++) {
|
|
18
|
-
const output = tx.getOutput(i);
|
|
19
|
-
if (output.script && hex.encode(output.script) === hexP2Ascript) {
|
|
20
|
-
if (output.amount !== P2A.amount) {
|
|
21
|
-
throw new Error(`P2A output has wrong amount, expected ${P2A.amount} got ${output.amount}`);
|
|
22
|
-
}
|
|
23
|
-
return {
|
|
24
|
-
txid: tx.id,
|
|
25
|
-
index: i,
|
|
26
|
-
witnessUtxo: P2A,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
throw new Error("P2A output not found");
|
|
31
|
-
}
|
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
import { schnorr } from "@noble/curves/secp256k1.js";
|
|
2
|
-
import { hex } from "@scure/base";
|
|
3
|
-
import { DEFAULT_SEQUENCE, Script, SigHash } from "@scure/btc-signer";
|
|
4
|
-
import { tapLeafHash } from "@scure/btc-signer/payment.js";
|
|
5
|
-
import { CLTVMultisigTapscript, decodeTapscript, } from "../script/tapscript.js";
|
|
6
|
-
import { scriptFromTapLeafScript, VtxoScript, } from "../script/base.js";
|
|
7
|
-
import { P2A } from "./anchor.js";
|
|
8
|
-
import { setArkPsbtField, VtxoTaprootTree } from "./unknownFields.js";
|
|
9
|
-
import { Transaction } from "./transaction.js";
|
|
10
|
-
import { ArkAddress } from "../script/address.js";
|
|
11
|
-
import { Extension } from "../extension/index.js";
|
|
12
|
-
/**
|
|
13
|
-
* Builds an offchain transaction with checkpoint transactions.
|
|
14
|
-
*
|
|
15
|
-
* Creates one checkpoint transaction per input and a virtual transaction that
|
|
16
|
-
* combines all the checkpoints, sending to the specified outputs. This is the
|
|
17
|
-
* core function for creating Arkade transactions.
|
|
18
|
-
*
|
|
19
|
-
* @param inputs - Array of virtual transaction inputs
|
|
20
|
-
* @param outputs - Array of transaction outputs
|
|
21
|
-
* @param serverUnrollScript - Server unroll script for checkpoint transactions
|
|
22
|
-
* @returns Object containing the virtual transaction and checkpoint transactions
|
|
23
|
-
*/
|
|
24
|
-
export function buildOffchainTx(inputs, outputs, serverUnrollScript) {
|
|
25
|
-
// TODO: use arkd /info
|
|
26
|
-
const MAX_OP_RETURN = 2;
|
|
27
|
-
let countOpReturn = 0;
|
|
28
|
-
let hasExtensionOutput = false;
|
|
29
|
-
for (const [index, output] of outputs.entries()) {
|
|
30
|
-
if (!output.script)
|
|
31
|
-
throw new Error(`missing output script ${index}`);
|
|
32
|
-
const isExtension = Extension.isExtension(output.script);
|
|
33
|
-
const isOpReturn = isExtension || Script.decode(output.script)[0] === "RETURN";
|
|
34
|
-
if (isOpReturn) {
|
|
35
|
-
countOpReturn++;
|
|
36
|
-
}
|
|
37
|
-
if (!isExtension)
|
|
38
|
-
continue;
|
|
39
|
-
if (hasExtensionOutput)
|
|
40
|
-
throw new Error("multiple extension outputs");
|
|
41
|
-
hasExtensionOutput = true;
|
|
42
|
-
}
|
|
43
|
-
if (countOpReturn > MAX_OP_RETURN) {
|
|
44
|
-
throw new Error(`too many OP_RETURN outputs: ${countOpReturn} > ${MAX_OP_RETURN}`);
|
|
45
|
-
}
|
|
46
|
-
const checkpoints = inputs.map((input) => buildCheckpointTx(input, serverUnrollScript));
|
|
47
|
-
const arkTx = buildVirtualTx(checkpoints.map((c) => c.input), outputs);
|
|
48
|
-
return {
|
|
49
|
-
arkTx,
|
|
50
|
-
checkpoints: checkpoints.map((c) => c.tx),
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function buildVirtualTx(inputs, outputs) {
|
|
54
|
-
let lockTime = 0n;
|
|
55
|
-
for (const input of inputs) {
|
|
56
|
-
const tapscript = decodeTapscript(scriptFromTapLeafScript(input.tapLeafScript));
|
|
57
|
-
if (CLTVMultisigTapscript.is(tapscript)) {
|
|
58
|
-
if (lockTime !== 0n) {
|
|
59
|
-
// if a locktime is already set, check if the new locktime is in the same unit
|
|
60
|
-
if (isSeconds(lockTime) !==
|
|
61
|
-
isSeconds(tapscript.params.absoluteTimelock)) {
|
|
62
|
-
throw new Error("cannot mix seconds and blocks locktime");
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (tapscript.params.absoluteTimelock > lockTime) {
|
|
66
|
-
lockTime = tapscript.params.absoluteTimelock;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
const tx = new Transaction({
|
|
71
|
-
version: 3,
|
|
72
|
-
lockTime: Number(lockTime),
|
|
73
|
-
});
|
|
74
|
-
for (const [i, input] of inputs.entries()) {
|
|
75
|
-
tx.addInput({
|
|
76
|
-
txid: input.txid,
|
|
77
|
-
index: input.vout,
|
|
78
|
-
sequence: lockTime ? DEFAULT_SEQUENCE - 1 : undefined,
|
|
79
|
-
witnessUtxo: {
|
|
80
|
-
script: VtxoScript.decode(input.tapTree).pkScript,
|
|
81
|
-
amount: BigInt(input.value),
|
|
82
|
-
},
|
|
83
|
-
tapLeafScript: [input.tapLeafScript],
|
|
84
|
-
});
|
|
85
|
-
setArkPsbtField(tx, i, VtxoTaprootTree, input.tapTree);
|
|
86
|
-
}
|
|
87
|
-
for (const output of outputs) {
|
|
88
|
-
tx.addOutput(output);
|
|
89
|
-
}
|
|
90
|
-
// add the anchor output
|
|
91
|
-
tx.addOutput(P2A);
|
|
92
|
-
return tx;
|
|
93
|
-
}
|
|
94
|
-
function buildCheckpointTx(vtxo, serverUnrollScript) {
|
|
95
|
-
// create the checkpoint virtual output script from collaborative closure
|
|
96
|
-
const collaborativeClosure = decodeTapscript(scriptFromTapLeafScript(vtxo.tapLeafScript));
|
|
97
|
-
// create the checkpoint virtual output script combining collaborative closure and server unroll script
|
|
98
|
-
const checkpointVtxoScript = new VtxoScript([
|
|
99
|
-
serverUnrollScript.script,
|
|
100
|
-
collaborativeClosure.script,
|
|
101
|
-
]);
|
|
102
|
-
// build the checkpoint virtual tx
|
|
103
|
-
const checkpointTx = buildVirtualTx([vtxo], [
|
|
104
|
-
{
|
|
105
|
-
amount: BigInt(vtxo.value),
|
|
106
|
-
script: checkpointVtxoScript.pkScript,
|
|
107
|
-
},
|
|
108
|
-
]);
|
|
109
|
-
// get the collaborative leaf proof
|
|
110
|
-
const collaborativeLeafProof = checkpointVtxoScript.findLeaf(hex.encode(collaborativeClosure.script));
|
|
111
|
-
// create the checkpoint input that will be used as input of the virtual tx
|
|
112
|
-
const checkpointInput = {
|
|
113
|
-
txid: checkpointTx.id,
|
|
114
|
-
vout: 0,
|
|
115
|
-
value: vtxo.value,
|
|
116
|
-
tapLeafScript: collaborativeLeafProof,
|
|
117
|
-
tapTree: checkpointVtxoScript.encode(),
|
|
118
|
-
};
|
|
119
|
-
return {
|
|
120
|
-
tx: checkpointTx,
|
|
121
|
-
input: checkpointInput,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
const nLocktimeMinSeconds = 500000000n;
|
|
125
|
-
function isSeconds(locktime) {
|
|
126
|
-
return locktime >= nLocktimeMinSeconds;
|
|
127
|
-
}
|
|
128
|
-
export function hasBoardingTxExpired(coin, boardingTimelock, chainTipHeight) {
|
|
129
|
-
if (!coin.status.block_time)
|
|
130
|
-
return false;
|
|
131
|
-
if (boardingTimelock.value === 0n)
|
|
132
|
-
return true;
|
|
133
|
-
if (boardingTimelock.type === "blocks") {
|
|
134
|
-
if (chainTipHeight === undefined || !coin.status.block_height)
|
|
135
|
-
return false;
|
|
136
|
-
return (BigInt(chainTipHeight - coin.status.block_height) >=
|
|
137
|
-
boardingTimelock.value);
|
|
138
|
-
}
|
|
139
|
-
// validate expiry in terms of seconds
|
|
140
|
-
const now = BigInt(Math.floor(Date.now() / 1000));
|
|
141
|
-
const blockTime = BigInt(Math.floor(coin.status.block_time));
|
|
142
|
-
return blockTime + boardingTimelock.value <= now;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Formats a sighash type as a hex string (e.g., 0x01)
|
|
146
|
-
*/
|
|
147
|
-
function formatSighash(type) {
|
|
148
|
-
return `0x${type.toString(16).padStart(2, "0")}`;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Verify tapscript signatures on a transaction input
|
|
152
|
-
* @param tx Transaction to verify
|
|
153
|
-
* @param inputIndex Index of the input to verify
|
|
154
|
-
* @param requiredSigners List of required signer pubkeys (hex encoded)
|
|
155
|
-
* @param excludePubkeys List of pubkeys to exclude from verification (hex encoded, e.g., server key not yet signed)
|
|
156
|
-
* @param allowedSighashTypes List of allowed sighash types (defaults to [SigHash.DEFAULT])
|
|
157
|
-
* @throws Error if verification fails
|
|
158
|
-
*/
|
|
159
|
-
export function verifyTapscriptSignatures(tx, inputIndex, requiredSigners, excludePubkeys = [], allowedSighashTypes = [SigHash.DEFAULT]) {
|
|
160
|
-
const input = tx.getInput(inputIndex);
|
|
161
|
-
// Collect prevout scripts and amounts for ALL inputs (required for preimageWitnessV1)
|
|
162
|
-
const prevoutScripts = [];
|
|
163
|
-
const prevoutAmounts = [];
|
|
164
|
-
for (let i = 0; i < tx.inputsLength; i++) {
|
|
165
|
-
const inp = tx.getInput(i);
|
|
166
|
-
if (!inp.witnessUtxo) {
|
|
167
|
-
throw new Error(`Input ${i} is missing witnessUtxo`);
|
|
168
|
-
}
|
|
169
|
-
prevoutScripts.push(inp.witnessUtxo.script);
|
|
170
|
-
prevoutAmounts.push(inp.witnessUtxo.amount);
|
|
171
|
-
}
|
|
172
|
-
// Verify tapScriptSig signatures
|
|
173
|
-
if (!input.tapScriptSig || input.tapScriptSig.length === 0) {
|
|
174
|
-
throw new Error(`Input ${inputIndex} is missing tapScriptSig`);
|
|
175
|
-
}
|
|
176
|
-
// Verify each signature in tapScriptSig
|
|
177
|
-
for (const [tapScriptSigData, signature] of input.tapScriptSig) {
|
|
178
|
-
const pubKey = tapScriptSigData.pubKey;
|
|
179
|
-
const pubKeyHex = hex.encode(pubKey);
|
|
180
|
-
// Skip verification for excluded pubkeys
|
|
181
|
-
if (excludePubkeys.includes(pubKeyHex)) {
|
|
182
|
-
continue;
|
|
183
|
-
}
|
|
184
|
-
// Extract sighash type from signature
|
|
185
|
-
// Schnorr signatures are 64 bytes, with optional 1-byte sighash appended
|
|
186
|
-
const sighashType = signature.length === 65 ? signature[64] : SigHash.DEFAULT;
|
|
187
|
-
const sig = signature.subarray(0, 64);
|
|
188
|
-
// Verify sighash type is allowed
|
|
189
|
-
if (!allowedSighashTypes.includes(sighashType)) {
|
|
190
|
-
const sighashName = formatSighash(sighashType);
|
|
191
|
-
throw new Error(`Unallowed sighash type ${sighashName} for input ${inputIndex}, pubkey ${pubKeyHex}.`);
|
|
192
|
-
}
|
|
193
|
-
// Find the tapLeafScript that matches this signature's leafHash
|
|
194
|
-
if (!input.tapLeafScript || input.tapLeafScript.length === 0) {
|
|
195
|
-
throw new Error();
|
|
196
|
-
}
|
|
197
|
-
// Search for the leaf that matches the leafHash in tapScriptSigData
|
|
198
|
-
const leafHash = tapScriptSigData.leafHash;
|
|
199
|
-
const leafHashHex = hex.encode(leafHash);
|
|
200
|
-
let matchingScript;
|
|
201
|
-
let matchingVersion;
|
|
202
|
-
for (const [_, scriptWithVersion] of input.tapLeafScript) {
|
|
203
|
-
const script = scriptWithVersion.subarray(0, -1);
|
|
204
|
-
const version = scriptWithVersion[scriptWithVersion.length - 1];
|
|
205
|
-
// Compute the leaf hash for this script and compare as hex strings
|
|
206
|
-
const computedLeafHash = tapLeafHash(script, version);
|
|
207
|
-
const computedHex = hex.encode(computedLeafHash);
|
|
208
|
-
if (computedHex === leafHashHex) {
|
|
209
|
-
matchingScript = script;
|
|
210
|
-
matchingVersion = version;
|
|
211
|
-
break;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
if (!matchingScript || matchingVersion === undefined) {
|
|
215
|
-
throw new Error(`Input ${inputIndex}: No tapLeafScript found matching leafHash ${hex.encode(leafHash)}`);
|
|
216
|
-
}
|
|
217
|
-
// Reconstruct the message that was signed
|
|
218
|
-
// Note: preimageWitnessV1 requires ALL input prevout scripts and amounts
|
|
219
|
-
const message = tx.preimageWitnessV1(inputIndex, prevoutScripts, sighashType, prevoutAmounts, undefined, matchingScript, matchingVersion);
|
|
220
|
-
// Verify the schnorr signature
|
|
221
|
-
const isValid = schnorr.verify(sig, message, pubKey);
|
|
222
|
-
if (!isValid) {
|
|
223
|
-
throw new Error(`Invalid signature for input ${inputIndex}, pubkey ${pubKeyHex}`);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
// Verify we have signatures from all required signers (excluding those we're skipping)
|
|
227
|
-
const signedPubkeys = input.tapScriptSig.map(([data]) => hex.encode(data.pubKey));
|
|
228
|
-
const requiredNotExcluded = requiredSigners.filter((pk) => !excludePubkeys.includes(pk));
|
|
229
|
-
const missingSigners = requiredNotExcluded.filter((pk) => !signedPubkeys.includes(pk));
|
|
230
|
-
if (missingSigners.length > 0) {
|
|
231
|
-
throw new Error(`Missing signatures from: ${missingSigners.map((pk) => pk.slice(0, 16)).join(", ")}...`);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Merges the signed transaction with the original transaction
|
|
236
|
-
* @param signedTx signed transaction
|
|
237
|
-
* @param originalTx original transaction
|
|
238
|
-
*/
|
|
239
|
-
export function combineTapscriptSigs(signedTx, originalTx) {
|
|
240
|
-
for (let i = 0; i < signedTx.inputsLength; i++) {
|
|
241
|
-
const input = originalTx.getInput(i);
|
|
242
|
-
const signedInput = signedTx.getInput(i);
|
|
243
|
-
if (!input.tapScriptSig)
|
|
244
|
-
throw new Error("No tapScriptSig");
|
|
245
|
-
originalTx.updateInput(i, {
|
|
246
|
-
tapScriptSig: input.tapScriptSig?.concat(signedInput.tapScriptSig),
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
return originalTx;
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Validates if a given string is a valid Arkade address by attempting to decode it.
|
|
253
|
-
* @param address The Arkade address to validate.
|
|
254
|
-
* @returns True if the address is valid, false otherwise.
|
|
255
|
-
*/
|
|
256
|
-
export function isValidArkAddress(address) {
|
|
257
|
-
try {
|
|
258
|
-
ArkAddress.decode(address);
|
|
259
|
-
return true;
|
|
260
|
-
}
|
|
261
|
-
catch (e) {
|
|
262
|
-
return false;
|
|
263
|
-
}
|
|
264
|
-
}
|