@bsv/wallet-toolbox 1.7.1 → 1.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (317) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/docs/client.md +489 -1334
  3. package/docs/services.md +5 -5
  4. package/docs/storage.md +64 -61
  5. package/docs/wallet.md +489 -1334
  6. package/mobile/out/src/Wallet.d.ts +21 -4
  7. package/mobile/out/src/Wallet.d.ts.map +1 -1
  8. package/mobile/out/src/Wallet.js +93 -57
  9. package/mobile/out/src/Wallet.js.map +1 -1
  10. package/mobile/out/src/WalletLogger.d.ts +33 -0
  11. package/mobile/out/src/WalletLogger.d.ts.map +1 -0
  12. package/mobile/out/src/WalletLogger.js +157 -0
  13. package/mobile/out/src/WalletLogger.js.map +1 -0
  14. package/mobile/out/src/WalletPermissionsManager.d.ts.map +1 -1
  15. package/mobile/out/src/WalletPermissionsManager.js +1 -2
  16. package/mobile/out/src/WalletPermissionsManager.js.map +1 -1
  17. package/mobile/out/src/sdk/WERR_errors.d.ts.map +1 -1
  18. package/mobile/out/src/sdk/WERR_errors.js.map +1 -1
  19. package/mobile/out/src/sdk/WalletError.d.ts.map +1 -1
  20. package/mobile/out/src/sdk/WalletError.js +0 -2
  21. package/mobile/out/src/sdk/WalletError.js.map +1 -1
  22. package/mobile/out/src/sdk/WalletServices.interfaces.d.ts +3 -3
  23. package/mobile/out/src/sdk/WalletServices.interfaces.d.ts.map +1 -1
  24. package/mobile/out/src/sdk/WalletStorage.interfaces.d.ts +9 -10
  25. package/mobile/out/src/sdk/WalletStorage.interfaces.d.ts.map +1 -1
  26. package/mobile/out/src/sdk/index.d.ts +1 -1
  27. package/mobile/out/src/sdk/index.d.ts.map +1 -1
  28. package/mobile/out/src/sdk/index.js +3 -1
  29. package/mobile/out/src/sdk/index.js.map +1 -1
  30. package/mobile/out/src/services/Services.d.ts +5 -5
  31. package/mobile/out/src/services/Services.d.ts.map +1 -1
  32. package/mobile/out/src/services/Services.js +18 -4
  33. package/mobile/out/src/services/Services.js.map +1 -1
  34. package/mobile/out/src/services/providers/WhatsOnChain.d.ts.map +1 -1
  35. package/mobile/out/src/services/providers/WhatsOnChain.js +1 -2
  36. package/mobile/out/src/services/providers/WhatsOnChain.js.map +1 -1
  37. package/mobile/out/src/services/providers/getBeefForTxid.d.ts.map +1 -1
  38. package/mobile/out/src/services/providers/getBeefForTxid.js.map +1 -1
  39. package/mobile/out/src/signer/methods/acquireDirectCertificate.d.ts +2 -3
  40. package/mobile/out/src/signer/methods/acquireDirectCertificate.d.ts.map +1 -1
  41. package/mobile/out/src/signer/methods/acquireDirectCertificate.js.map +1 -1
  42. package/mobile/out/src/signer/methods/buildSignableTransaction.d.ts +3 -4
  43. package/mobile/out/src/signer/methods/buildSignableTransaction.d.ts.map +1 -1
  44. package/mobile/out/src/signer/methods/buildSignableTransaction.js +1 -2
  45. package/mobile/out/src/signer/methods/buildSignableTransaction.js.map +1 -1
  46. package/mobile/out/src/signer/methods/createAction.d.ts +3 -4
  47. package/mobile/out/src/signer/methods/createAction.d.ts.map +1 -1
  48. package/mobile/out/src/signer/methods/createAction.js +17 -6
  49. package/mobile/out/src/signer/methods/createAction.js.map +1 -1
  50. package/mobile/out/src/signer/methods/internalizeAction.d.ts.map +1 -1
  51. package/mobile/out/src/signer/methods/internalizeAction.js +1 -2
  52. package/mobile/out/src/signer/methods/internalizeAction.js.map +1 -1
  53. package/mobile/out/src/signer/methods/proveCertificate.d.ts +2 -3
  54. package/mobile/out/src/signer/methods/proveCertificate.d.ts.map +1 -1
  55. package/mobile/out/src/signer/methods/proveCertificate.js.map +1 -1
  56. package/mobile/out/src/signer/methods/signAction.d.ts.map +1 -1
  57. package/mobile/out/src/signer/methods/signAction.js +1 -2
  58. package/mobile/out/src/signer/methods/signAction.js.map +1 -1
  59. package/mobile/out/src/storage/StorageIdb.d.ts +3 -4
  60. package/mobile/out/src/storage/StorageIdb.d.ts.map +1 -1
  61. package/mobile/out/src/storage/StorageIdb.js.map +1 -1
  62. package/mobile/out/src/storage/StorageProvider.d.ts +6 -7
  63. package/mobile/out/src/storage/StorageProvider.d.ts.map +1 -1
  64. package/mobile/out/src/storage/StorageProvider.js +5 -6
  65. package/mobile/out/src/storage/StorageProvider.js.map +1 -1
  66. package/mobile/out/src/storage/WalletStorageManager.d.ts +5 -5
  67. package/mobile/out/src/storage/WalletStorageManager.d.ts.map +1 -1
  68. package/mobile/out/src/storage/WalletStorageManager.js +5 -4
  69. package/mobile/out/src/storage/WalletStorageManager.js.map +1 -1
  70. package/mobile/out/src/storage/methods/ListActionsSpecOp.d.ts +2 -2
  71. package/mobile/out/src/storage/methods/ListActionsSpecOp.d.ts.map +1 -1
  72. package/mobile/out/src/storage/methods/ListActionsSpecOp.js.map +1 -1
  73. package/mobile/out/src/storage/methods/ListOutputsSpecOp.d.ts +4 -5
  74. package/mobile/out/src/storage/methods/ListOutputsSpecOp.d.ts.map +1 -1
  75. package/mobile/out/src/storage/methods/ListOutputsSpecOp.js.map +1 -1
  76. package/mobile/out/src/storage/methods/attemptToPostReqsToNetwork.d.ts +2 -2
  77. package/mobile/out/src/storage/methods/attemptToPostReqsToNetwork.d.ts.map +1 -1
  78. package/mobile/out/src/storage/methods/attemptToPostReqsToNetwork.js +11 -7
  79. package/mobile/out/src/storage/methods/attemptToPostReqsToNetwork.js.map +1 -1
  80. package/mobile/out/src/storage/methods/createAction.d.ts +3 -4
  81. package/mobile/out/src/storage/methods/createAction.d.ts.map +1 -1
  82. package/mobile/out/src/storage/methods/createAction.js +18 -5
  83. package/mobile/out/src/storage/methods/createAction.js.map +1 -1
  84. package/mobile/out/src/storage/methods/generateChange.js +10 -10
  85. package/mobile/out/src/storage/methods/generateChange.js.map +1 -1
  86. package/mobile/out/src/storage/methods/internalizeAction.d.ts.map +1 -1
  87. package/mobile/out/src/storage/methods/internalizeAction.js +1 -2
  88. package/mobile/out/src/storage/methods/internalizeAction.js.map +1 -1
  89. package/mobile/out/src/storage/methods/listActionsIdb.d.ts +2 -3
  90. package/mobile/out/src/storage/methods/listActionsIdb.d.ts.map +1 -1
  91. package/mobile/out/src/storage/methods/listActionsIdb.js.map +1 -1
  92. package/mobile/out/src/storage/methods/listCertificates.d.ts +3 -3
  93. package/mobile/out/src/storage/methods/listCertificates.d.ts.map +1 -1
  94. package/mobile/out/src/storage/methods/listCertificates.js.map +1 -1
  95. package/mobile/out/src/storage/methods/listOutputsIdb.d.ts +2 -3
  96. package/mobile/out/src/storage/methods/listOutputsIdb.d.ts.map +1 -1
  97. package/mobile/out/src/storage/methods/listOutputsIdb.js.map +1 -1
  98. package/mobile/out/src/storage/methods/processAction.d.ts +2 -2
  99. package/mobile/out/src/storage/methods/processAction.d.ts.map +1 -1
  100. package/mobile/out/src/storage/methods/processAction.js +15 -10
  101. package/mobile/out/src/storage/methods/processAction.js.map +1 -1
  102. package/mobile/out/src/storage/remoting/StorageClient.d.ts +5 -6
  103. package/mobile/out/src/storage/remoting/StorageClient.d.ts.map +1 -1
  104. package/mobile/out/src/storage/remoting/StorageClient.js +22 -0
  105. package/mobile/out/src/storage/remoting/StorageClient.js.map +1 -1
  106. package/mobile/out/src/storage/remoting/StorageMobile.d.ts +5 -6
  107. package/mobile/out/src/storage/remoting/StorageMobile.d.ts.map +1 -1
  108. package/mobile/out/src/storage/remoting/StorageMobile.js.map +1 -1
  109. package/mobile/package-lock.json +6 -6
  110. package/mobile/package.json +2 -2
  111. package/out/src/Wallet.d.ts +21 -4
  112. package/out/src/Wallet.d.ts.map +1 -1
  113. package/out/src/Wallet.js +93 -57
  114. package/out/src/Wallet.js.map +1 -1
  115. package/out/src/WalletLogger.d.ts +33 -0
  116. package/out/src/WalletLogger.d.ts.map +1 -0
  117. package/out/src/WalletLogger.js +157 -0
  118. package/out/src/WalletLogger.js.map +1 -0
  119. package/out/src/WalletPermissionsManager.d.ts.map +1 -1
  120. package/out/src/WalletPermissionsManager.js +1 -2
  121. package/out/src/WalletPermissionsManager.js.map +1 -1
  122. package/out/src/__tests/WalletPermissionsManager.fixtures.d.ts +1 -0
  123. package/out/src/__tests/WalletPermissionsManager.fixtures.d.ts.map +1 -1
  124. package/out/src/__tests/WalletPermissionsManager.fixtures.js +15 -4
  125. package/out/src/__tests/WalletPermissionsManager.fixtures.js.map +1 -1
  126. package/out/src/__tests/WalletPermissionsManager.proxying.test.js +79 -74
  127. package/out/src/__tests/WalletPermissionsManager.proxying.test.js.map +1 -1
  128. package/out/src/sdk/WERR_errors.d.ts.map +1 -1
  129. package/out/src/sdk/WERR_errors.js.map +1 -1
  130. package/out/src/sdk/WalletError.d.ts.map +1 -1
  131. package/out/src/sdk/WalletError.js +0 -2
  132. package/out/src/sdk/WalletError.js.map +1 -1
  133. package/out/src/sdk/WalletServices.interfaces.d.ts +3 -3
  134. package/out/src/sdk/WalletServices.interfaces.d.ts.map +1 -1
  135. package/out/src/sdk/WalletStorage.interfaces.d.ts +9 -10
  136. package/out/src/sdk/WalletStorage.interfaces.d.ts.map +1 -1
  137. package/out/src/sdk/__test/validationHelpers.test.js +4 -4
  138. package/out/src/sdk/__test/validationHelpers.test.js.map +1 -1
  139. package/out/src/sdk/index.d.ts +1 -1
  140. package/out/src/sdk/index.d.ts.map +1 -1
  141. package/out/src/sdk/index.js +3 -1
  142. package/out/src/sdk/index.js.map +1 -1
  143. package/out/src/services/Services.d.ts +5 -5
  144. package/out/src/services/Services.d.ts.map +1 -1
  145. package/out/src/services/Services.js +18 -4
  146. package/out/src/services/Services.js.map +1 -1
  147. package/out/src/services/providers/WhatsOnChain.d.ts.map +1 -1
  148. package/out/src/services/providers/WhatsOnChain.js +1 -2
  149. package/out/src/services/providers/WhatsOnChain.js.map +1 -1
  150. package/out/src/services/providers/getBeefForTxid.d.ts.map +1 -1
  151. package/out/src/services/providers/getBeefForTxid.js.map +1 -1
  152. package/out/src/signer/methods/acquireDirectCertificate.d.ts +2 -3
  153. package/out/src/signer/methods/acquireDirectCertificate.d.ts.map +1 -1
  154. package/out/src/signer/methods/acquireDirectCertificate.js.map +1 -1
  155. package/out/src/signer/methods/buildSignableTransaction.d.ts +3 -4
  156. package/out/src/signer/methods/buildSignableTransaction.d.ts.map +1 -1
  157. package/out/src/signer/methods/buildSignableTransaction.js +1 -2
  158. package/out/src/signer/methods/buildSignableTransaction.js.map +1 -1
  159. package/out/src/signer/methods/createAction.d.ts +3 -4
  160. package/out/src/signer/methods/createAction.d.ts.map +1 -1
  161. package/out/src/signer/methods/createAction.js +17 -6
  162. package/out/src/signer/methods/createAction.js.map +1 -1
  163. package/out/src/signer/methods/internalizeAction.d.ts.map +1 -1
  164. package/out/src/signer/methods/internalizeAction.js +1 -2
  165. package/out/src/signer/methods/internalizeAction.js.map +1 -1
  166. package/out/src/signer/methods/proveCertificate.d.ts +2 -3
  167. package/out/src/signer/methods/proveCertificate.d.ts.map +1 -1
  168. package/out/src/signer/methods/proveCertificate.js.map +1 -1
  169. package/out/src/signer/methods/signAction.d.ts.map +1 -1
  170. package/out/src/signer/methods/signAction.js +1 -2
  171. package/out/src/signer/methods/signAction.js.map +1 -1
  172. package/out/src/storage/StorageIdb.d.ts +3 -4
  173. package/out/src/storage/StorageIdb.d.ts.map +1 -1
  174. package/out/src/storage/StorageIdb.js.map +1 -1
  175. package/out/src/storage/StorageKnex.d.ts +3 -4
  176. package/out/src/storage/StorageKnex.d.ts.map +1 -1
  177. package/out/src/storage/StorageKnex.js.map +1 -1
  178. package/out/src/storage/StorageProvider.d.ts +6 -7
  179. package/out/src/storage/StorageProvider.d.ts.map +1 -1
  180. package/out/src/storage/StorageProvider.js +5 -6
  181. package/out/src/storage/StorageProvider.js.map +1 -1
  182. package/out/src/storage/WalletStorageManager.d.ts +5 -5
  183. package/out/src/storage/WalletStorageManager.d.ts.map +1 -1
  184. package/out/src/storage/WalletStorageManager.js +5 -4
  185. package/out/src/storage/WalletStorageManager.js.map +1 -1
  186. package/out/src/storage/__test/getBeefForTransaction.test.js.map +1 -1
  187. package/out/src/storage/methods/ListActionsSpecOp.d.ts +2 -2
  188. package/out/src/storage/methods/ListActionsSpecOp.d.ts.map +1 -1
  189. package/out/src/storage/methods/ListActionsSpecOp.js.map +1 -1
  190. package/out/src/storage/methods/ListOutputsSpecOp.d.ts +4 -5
  191. package/out/src/storage/methods/ListOutputsSpecOp.d.ts.map +1 -1
  192. package/out/src/storage/methods/ListOutputsSpecOp.js.map +1 -1
  193. package/out/src/storage/methods/attemptToPostReqsToNetwork.d.ts +2 -2
  194. package/out/src/storage/methods/attemptToPostReqsToNetwork.d.ts.map +1 -1
  195. package/out/src/storage/methods/attemptToPostReqsToNetwork.js +11 -7
  196. package/out/src/storage/methods/attemptToPostReqsToNetwork.js.map +1 -1
  197. package/out/src/storage/methods/createAction.d.ts +3 -4
  198. package/out/src/storage/methods/createAction.d.ts.map +1 -1
  199. package/out/src/storage/methods/createAction.js +18 -5
  200. package/out/src/storage/methods/createAction.js.map +1 -1
  201. package/out/src/storage/methods/generateChange.js +10 -10
  202. package/out/src/storage/methods/generateChange.js.map +1 -1
  203. package/out/src/storage/methods/internalizeAction.d.ts.map +1 -1
  204. package/out/src/storage/methods/internalizeAction.js +1 -2
  205. package/out/src/storage/methods/internalizeAction.js.map +1 -1
  206. package/out/src/storage/methods/listActionsIdb.d.ts +2 -3
  207. package/out/src/storage/methods/listActionsIdb.d.ts.map +1 -1
  208. package/out/src/storage/methods/listActionsIdb.js.map +1 -1
  209. package/out/src/storage/methods/listActionsKnex.d.ts +2 -3
  210. package/out/src/storage/methods/listActionsKnex.d.ts.map +1 -1
  211. package/out/src/storage/methods/listActionsKnex.js.map +1 -1
  212. package/out/src/storage/methods/listCertificates.d.ts +3 -3
  213. package/out/src/storage/methods/listCertificates.d.ts.map +1 -1
  214. package/out/src/storage/methods/listCertificates.js.map +1 -1
  215. package/out/src/storage/methods/listOutputsIdb.d.ts +2 -3
  216. package/out/src/storage/methods/listOutputsIdb.d.ts.map +1 -1
  217. package/out/src/storage/methods/listOutputsIdb.js.map +1 -1
  218. package/out/src/storage/methods/listOutputsKnex.d.ts +2 -3
  219. package/out/src/storage/methods/listOutputsKnex.d.ts.map +1 -1
  220. package/out/src/storage/methods/listOutputsKnex.js.map +1 -1
  221. package/out/src/storage/methods/processAction.d.ts +2 -2
  222. package/out/src/storage/methods/processAction.d.ts.map +1 -1
  223. package/out/src/storage/methods/processAction.js +15 -10
  224. package/out/src/storage/methods/processAction.js.map +1 -1
  225. package/out/src/storage/remoting/StorageClient.d.ts +5 -6
  226. package/out/src/storage/remoting/StorageClient.d.ts.map +1 -1
  227. package/out/src/storage/remoting/StorageClient.js +22 -0
  228. package/out/src/storage/remoting/StorageClient.js.map +1 -1
  229. package/out/src/storage/remoting/StorageMobile.d.ts +5 -6
  230. package/out/src/storage/remoting/StorageMobile.d.ts.map +1 -1
  231. package/out/src/storage/remoting/StorageMobile.js.map +1 -1
  232. package/out/src/storage/remoting/StorageServer.d.ts +5 -0
  233. package/out/src/storage/remoting/StorageServer.d.ts.map +1 -1
  234. package/out/src/storage/remoting/StorageServer.js +38 -5
  235. package/out/src/storage/remoting/StorageServer.js.map +1 -1
  236. package/out/src/storage/remoting/__test/StorageClient.test.d.ts +2 -0
  237. package/out/src/storage/remoting/__test/StorageClient.test.d.ts.map +1 -0
  238. package/out/src/storage/remoting/__test/StorageClient.test.js +98 -0
  239. package/out/src/storage/remoting/__test/StorageClient.test.js.map +1 -0
  240. package/out/src/storage/sync/StorageMySQLDojoReader.d.ts.map +1 -1
  241. package/out/src/storage/sync/StorageMySQLDojoReader.js +1 -2
  242. package/out/src/storage/sync/StorageMySQLDojoReader.js.map +1 -1
  243. package/out/test/Wallet/certificate/listCertificates.test.js.map +1 -1
  244. package/out/test/Wallet/local/localWallet2.man.test.js.map +1 -1
  245. package/out/test/Wallet/signAction/mountaintop.man.test.js +2 -2
  246. package/out/test/Wallet/signAction/mountaintop.man.test.js.map +1 -1
  247. package/out/test/Wallet/support/operations.man.test.js +46 -1
  248. package/out/test/Wallet/support/operations.man.test.js.map +1 -1
  249. package/out/test/Wallet/support/reqErrorReview.2025.05.06.man.test.js.map +1 -1
  250. package/out/test/WalletClient/WERR.man.test.js +1 -1
  251. package/out/test/WalletClient/WERR.man.test.js.map +1 -1
  252. package/out/test/utils/localWalletMethods.d.ts.map +1 -1
  253. package/out/test/utils/localWalletMethods.js +2 -3
  254. package/out/test/utils/localWalletMethods.js.map +1 -1
  255. package/out/test/wallet/action/createAction.test.js +3 -0
  256. package/out/test/wallet/action/createAction.test.js.map +1 -1
  257. package/out/tsconfig.all.tsbuildinfo +1 -1
  258. package/package.json +2 -2
  259. package/src/Wallet.ts +114 -79
  260. package/src/WalletLogger.ts +167 -0
  261. package/src/WalletPermissionsManager.ts +3 -5
  262. package/src/__tests/WalletPermissionsManager.fixtures.ts +14 -1
  263. package/src/__tests/WalletPermissionsManager.proxying.test.ts +89 -85
  264. package/src/sdk/WERR_errors.ts +6 -3
  265. package/src/sdk/WalletError.ts +0 -4
  266. package/src/sdk/WalletServices.interfaces.ts +14 -3
  267. package/src/sdk/WalletStorage.interfaces.ts +11 -16
  268. package/src/sdk/__test/validationHelpers.test.ts +4 -5
  269. package/src/sdk/index.ts +1 -1
  270. package/src/services/Services.ts +23 -5
  271. package/src/services/providers/WhatsOnChain.ts +2 -3
  272. package/src/services/providers/getBeefForTxid.ts +3 -5
  273. package/src/signer/methods/acquireDirectCertificate.ts +2 -3
  274. package/src/signer/methods/buildSignableTransaction.ts +5 -6
  275. package/src/signer/methods/createAction.ts +24 -18
  276. package/src/signer/methods/internalizeAction.ts +4 -5
  277. package/src/signer/methods/proveCertificate.ts +3 -4
  278. package/src/signer/methods/signAction.ts +6 -4
  279. package/src/storage/StorageIdb.ts +3 -4
  280. package/src/storage/StorageKnex.ts +3 -4
  281. package/src/storage/StorageProvider.ts +16 -20
  282. package/src/storage/WalletStorageManager.ts +10 -11
  283. package/src/storage/__test/getBeefForTransaction.test.ts +3 -4
  284. package/src/storage/methods/ListActionsSpecOp.ts +4 -4
  285. package/src/storage/methods/ListOutputsSpecOp.ts +7 -8
  286. package/src/storage/methods/attemptToPostReqsToNetwork.ts +15 -8
  287. package/src/storage/methods/createAction.ts +39 -23
  288. package/src/storage/methods/generateChange.ts +10 -10
  289. package/src/storage/methods/internalizeAction.ts +4 -4
  290. package/src/storage/methods/listActionsIdb.ts +3 -3
  291. package/src/storage/methods/listActionsKnex.ts +3 -3
  292. package/src/storage/methods/listCertificates.ts +7 -6
  293. package/src/storage/methods/listOutputsIdb.ts +2 -3
  294. package/src/storage/methods/listOutputsKnex.ts +2 -3
  295. package/src/storage/methods/processAction.ts +30 -11
  296. package/src/storage/remoting/StorageClient.ts +31 -12
  297. package/src/storage/remoting/StorageMobile.ts +6 -12
  298. package/src/storage/remoting/StorageServer.ts +45 -6
  299. package/src/storage/remoting/__test/StorageClient.test.ts +113 -0
  300. package/src/storage/sync/StorageMySQLDojoReader.ts +2 -3
  301. package/test/Wallet/certificate/listCertificates.test.ts +2 -2
  302. package/test/Wallet/local/localWallet2.man.test.ts +5 -5
  303. package/test/Wallet/signAction/mountaintop.man.test.ts +3 -2
  304. package/test/Wallet/support/operations.man.test.ts +65 -6
  305. package/test/Wallet/support/reqErrorReview.2025.05.06.man.test.ts +2 -14
  306. package/test/WalletClient/WERR.man.test.ts +3 -3
  307. package/test/utils/localWalletMethods.ts +5 -5
  308. package/test/wallet/action/createAction.test.ts +3 -0
  309. package/mobile/out/src/sdk/validationHelpers.d.ts +0 -322
  310. package/mobile/out/src/sdk/validationHelpers.d.ts.map +0 -1
  311. package/mobile/out/src/sdk/validationHelpers.js +0 -691
  312. package/mobile/out/src/sdk/validationHelpers.js.map +0 -1
  313. package/out/src/sdk/validationHelpers.d.ts +0 -322
  314. package/out/src/sdk/validationHelpers.d.ts.map +0 -1
  315. package/out/src/sdk/validationHelpers.js +0 -691
  316. package/out/src/sdk/validationHelpers.js.map +0 -1
  317. package/src/sdk/validationHelpers.ts +0 -1034
@@ -1,691 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseWalletOutpoint = parseWalletOutpoint;
4
- exports.validateSatoshis = validateSatoshis;
5
- exports.validateOptionalInteger = validateOptionalInteger;
6
- exports.validateInteger = validateInteger;
7
- exports.validatePositiveIntegerOrZero = validatePositiveIntegerOrZero;
8
- exports.validateStringLength = validateStringLength;
9
- exports.validateBase64String = validateBase64String;
10
- exports.isHexString = isHexString;
11
- exports.validateCreateActionInput = validateCreateActionInput;
12
- exports.validateCreateActionOutput = validateCreateActionOutput;
13
- exports.validateCreateActionOptions = validateCreateActionOptions;
14
- exports.validateCreateActionArgs = validateCreateActionArgs;
15
- exports.validateSignActionOptions = validateSignActionOptions;
16
- exports.validateSignActionArgs = validateSignActionArgs;
17
- exports.validateAbortActionArgs = validateAbortActionArgs;
18
- exports.validateWalletPayment = validateWalletPayment;
19
- exports.validateBasketInsertion = validateBasketInsertion;
20
- exports.validateInternalizeOutput = validateInternalizeOutput;
21
- exports.validateOriginator = validateOriginator;
22
- exports.validateInternalizeActionArgs = validateInternalizeActionArgs;
23
- exports.validateOptionalOutpointString = validateOptionalOutpointString;
24
- exports.validateOutpointString = validateOutpointString;
25
- exports.validateRelinquishOutputArgs = validateRelinquishOutputArgs;
26
- exports.validateRelinquishCertificateArgs = validateRelinquishCertificateArgs;
27
- exports.validateListCertificatesArgs = validateListCertificatesArgs;
28
- exports.validateAcquireCertificateArgs = validateAcquireCertificateArgs;
29
- exports.validateAcquireIssuanceCertificateArgs = validateAcquireIssuanceCertificateArgs;
30
- exports.validateAcquireDirectCertificateArgs = validateAcquireDirectCertificateArgs;
31
- exports.validateProveCertificateArgs = validateProveCertificateArgs;
32
- exports.validateDiscoverByIdentityKeyArgs = validateDiscoverByIdentityKeyArgs;
33
- exports.validateDiscoverByAttributesArgs = validateDiscoverByAttributesArgs;
34
- exports.validateListOutputsArgs = validateListOutputsArgs;
35
- exports.validateListActionsArgs = validateListActionsArgs;
36
- const sdk_1 = require("@bsv/sdk");
37
- const types_1 = require("./types");
38
- const WERR_errors_1 = require("./WERR_errors");
39
- function parseWalletOutpoint(outpoint) {
40
- const [txid, vout] = outpoint.split('.');
41
- return { txid, vout: Number(vout) };
42
- }
43
- function defaultTrue(v) {
44
- return v !== null && v !== void 0 ? v : true;
45
- }
46
- function defaultFalse(v) {
47
- return v !== null && v !== void 0 ? v : false;
48
- }
49
- function defaultZero(v) {
50
- return v !== null && v !== void 0 ? v : 0;
51
- }
52
- function default0xffffffff(v) {
53
- return v !== null && v !== void 0 ? v : 0xffffffff;
54
- }
55
- function defaultOne(v) {
56
- return v !== null && v !== void 0 ? v : 1;
57
- }
58
- function defaultEmpty(v) {
59
- return v !== null && v !== void 0 ? v : [];
60
- }
61
- function validateOptionalStringLength(s, name, min, max) {
62
- if (s === undefined)
63
- return undefined;
64
- return validateStringLength(s, name, min, max);
65
- }
66
- function validateSatoshis(v, name, min) {
67
- if (v === undefined || !Number.isInteger(v) || v < 0 || v > 21e14)
68
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(name, 'a valid number of satoshis');
69
- if (min !== undefined && v < min)
70
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(name, `at least ${min} satoshis.`);
71
- return v;
72
- }
73
- function validateOptionalInteger(v, name, min, max) {
74
- if (v === undefined)
75
- return undefined;
76
- return validateInteger(v, name, undefined, min, max);
77
- }
78
- function validateInteger(v, name, defaultValue, min, max) {
79
- if (v === undefined) {
80
- if (defaultValue !== undefined)
81
- return defaultValue;
82
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(name, 'a valid integer');
83
- }
84
- if (!Number.isInteger(v))
85
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(name, 'an integer');
86
- v = Number(v);
87
- if (min !== undefined && v < min)
88
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(name, `at least ${min} length.`);
89
- if (max !== undefined && v > max)
90
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(name, `no more than ${max} length.`);
91
- return v;
92
- }
93
- function validatePositiveIntegerOrZero(v, name) {
94
- return validateInteger(v, name, 0, 0);
95
- }
96
- function validateStringLength(s, name, min, max) {
97
- const bytes = sdk_1.Utils.toArray(s, 'utf8').length;
98
- if (min !== undefined && bytes < min)
99
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(name, `at least ${min} length.`);
100
- if (max !== undefined && bytes > max)
101
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(name, `no more than ${max} length.`);
102
- return s;
103
- }
104
- function validateOptionalBasket(s) {
105
- if (s === undefined)
106
- return undefined;
107
- return validateBasket(s);
108
- }
109
- function validateBasket(s) {
110
- return validateIdentifier(s, 'basket', 1, 300);
111
- }
112
- function validateLabel(s) {
113
- return validateIdentifier(s, 'label', 1, 300);
114
- }
115
- function validateTag(s) {
116
- return validateIdentifier(s, 'tag', 1, 300);
117
- }
118
- function validateIdentifier(s, name, min, max) {
119
- s = s.trim().toLowerCase();
120
- const bytes = sdk_1.Utils.toArray(s, 'utf8').length;
121
- if (min !== undefined && bytes < min)
122
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(name, `at least ${min} length.`);
123
- if (max !== undefined && bytes > max)
124
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(name, `no more than ${max} length.`);
125
- return s;
126
- }
127
- function validateOptionalBase64String(s, name, min, max) {
128
- if (s === undefined)
129
- return undefined;
130
- return validateBase64String(s, name, min, max);
131
- }
132
- /**
133
- * Validate a Base64 string (structure and decoded size).
134
- *
135
- * @param s - base64 string
136
- * @param name - parameter name used in error messages
137
- * @param min - optional minimum decoded byte length
138
- * @param max - optional maximum decoded byte length
139
- * @returns validated base64 string
140
- * @throws WERR_INVALID_PARAMETER when invalid
141
- */
142
- function validateBase64String(s, name, min, max) {
143
- s = s.trim();
144
- if (s.length === 0) {
145
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(name, 'valid base64 string');
146
- }
147
- let paddingCount = 0;
148
- let validCharCount = 0;
149
- for (let i = 0; i < s.length; i++) {
150
- const char = s.charCodeAt(i);
151
- if (char >= 65 && char <= 90)
152
- continue; // A-Z
153
- if (char >= 97 && char <= 122)
154
- continue; // a-z
155
- if (char >= 48 && char <= 57)
156
- continue; // 0-9
157
- if (char === 43)
158
- continue; // +
159
- if (char === 47)
160
- continue; // /
161
- if (char === 61) {
162
- // =
163
- if (i < s.length - 2) {
164
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(name, 'valid base64 string');
165
- }
166
- paddingCount++;
167
- continue;
168
- }
169
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(name, 'valid base64 string');
170
- }
171
- // Padding rules
172
- if (paddingCount > 2) {
173
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(name, 'valid base64 string');
174
- }
175
- if (paddingCount > 0 && s.length % 4 !== 0) {
176
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(name, 'valid base64 string');
177
- }
178
- // Length must be multiple of 4 if no padding, or valid with padding
179
- const mod = s.length % 4;
180
- if (mod !== 0 && mod !== 4 - paddingCount) {
181
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(name, 'valid base64 string');
182
- }
183
- // Calculate decoded byte length: (valid chars * 6) / 8
184
- const encodedLength = s.length - paddingCount;
185
- const bytes = Math.floor((encodedLength * 3) / 4);
186
- if (min !== undefined && bytes < min) {
187
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(name, `at least ${min} bytes`);
188
- }
189
- if (max !== undefined && bytes > max) {
190
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(name, `no more than ${max} bytes`);
191
- }
192
- return s;
193
- }
194
- function validateOptionalHexString(s, name, min, max) {
195
- if (s === undefined)
196
- return undefined;
197
- return validateHexString(s, name, min, max);
198
- }
199
- /**
200
- * @param s
201
- * @param name
202
- * @param min if valid, string length minimum (not bytes)
203
- * @param max if valid, string length maximum (not bytes)
204
- * @returns
205
- */
206
- function validateHexString(s, name, min, max) {
207
- s = s.trim().toLowerCase();
208
- if (s.length % 2 === 1)
209
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(name, `even length, not ${s.length}.`);
210
- const hexRegex = /^[0-9A-Fa-f]+$/;
211
- if (!hexRegex.test(s))
212
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(name, `hexadecimal string.`);
213
- if (min !== undefined && s.length < min)
214
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(name, `at least ${min} length.`);
215
- if (max !== undefined && s.length > max)
216
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(name, `no more than ${max} length.`);
217
- return s;
218
- }
219
- function isHexString(s) {
220
- s = s.trim();
221
- if (s.length % 2 === 1)
222
- return false;
223
- const hexRegex = /^[0-9A-Fa-f]+$/;
224
- if (!hexRegex.test(s))
225
- return false;
226
- return true;
227
- }
228
- function validateCreateActionInput(i) {
229
- var _a;
230
- if (i.unlockingScript === undefined && i.unlockingScriptLength === undefined)
231
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('unlockingScript, unlockingScriptLength', `at least one valid value.`);
232
- const unlockingScript = validateOptionalHexString(i.unlockingScript, 'unlockingScript');
233
- const unlockingScriptLength = (_a = i.unlockingScriptLength) !== null && _a !== void 0 ? _a : unlockingScript.length / 2;
234
- if (unlockingScript && unlockingScriptLength !== unlockingScript.length / 2)
235
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('unlockingScriptLength', `length unlockingScript if both valid.`);
236
- const vi = {
237
- outpoint: parseWalletOutpoint(i.outpoint),
238
- inputDescription: validateStringLength(i.inputDescription, 'inputDescription', 5, 2000),
239
- unlockingScript,
240
- unlockingScriptLength,
241
- sequenceNumber: default0xffffffff(i.sequenceNumber)
242
- };
243
- return vi;
244
- }
245
- function validateCreateActionOutput(o) {
246
- const vo = {
247
- lockingScript: validateHexString(o.lockingScript, 'lockingScript'),
248
- satoshis: validateSatoshis(o.satoshis, 'satoshis'),
249
- outputDescription: validateStringLength(o.outputDescription, 'outputDescription', 5, 2000),
250
- basket: validateOptionalBasket(o.basket),
251
- customInstructions: o.customInstructions,
252
- tags: defaultEmpty(o.tags).map(t => validateTag(t))
253
- };
254
- return vo;
255
- }
256
- /**
257
- * Set all default true/false booleans to true or false if undefined.
258
- * Set all possibly undefined numbers to their default values.
259
- * Set all possibly undefined arrays to empty arrays.
260
- * Convert string outpoints to `{ txid: string, vout: number }`
261
- */
262
- function validateCreateActionOptions(options) {
263
- const o = options || {};
264
- const vo = {
265
- signAndProcess: defaultTrue(o.signAndProcess),
266
- acceptDelayedBroadcast: defaultTrue(o.acceptDelayedBroadcast),
267
- knownTxids: defaultEmpty(o.knownTxids),
268
- returnTXIDOnly: defaultFalse(o.returnTXIDOnly),
269
- noSend: defaultFalse(o.noSend),
270
- noSendChange: defaultEmpty(o.noSendChange).map(nsc => parseWalletOutpoint(nsc)),
271
- sendWith: defaultEmpty(o.sendWith),
272
- randomizeOutputs: defaultTrue(o.randomizeOutputs)
273
- };
274
- return vo;
275
- }
276
- /**
277
- * Validate the arguments for creating a new action.
278
- *
279
- * @param args
280
- * @returns validated arguments
281
- * @throws primarily WERR_INVALID_PARAMETER if args are invalid.
282
- */
283
- function validateCreateActionArgs(args) {
284
- var _a;
285
- const vargs = {
286
- description: validateStringLength(args.description, 'description', 5, 2000),
287
- inputBEEF: args.inputBEEF,
288
- inputs: defaultEmpty(args.inputs).map(i => validateCreateActionInput(i)),
289
- outputs: defaultEmpty(args.outputs).map(o => validateCreateActionOutput(o)),
290
- lockTime: defaultZero(args.lockTime),
291
- version: defaultOne(args.version),
292
- labels: defaultEmpty((_a = args.labels) === null || _a === void 0 ? void 0 : _a.map(l => validateLabel(l))),
293
- options: validateCreateActionOptions(args.options),
294
- isSendWith: false,
295
- isDelayed: false,
296
- isNoSend: false,
297
- isNewTx: false,
298
- isRemixChange: false,
299
- isSignAction: false,
300
- randomVals: undefined,
301
- includeAllSourceTransactions: false,
302
- isTestWerrReviewActions: false
303
- };
304
- vargs.isTestWerrReviewActions = vargs.labels.indexOf(types_1.specOpThrowReviewActions) >= 0;
305
- vargs.isSendWith = vargs.options.sendWith.length > 0;
306
- vargs.isRemixChange = !vargs.isSendWith && vargs.inputs.length === 0 && vargs.outputs.length === 0;
307
- vargs.isNewTx = vargs.isRemixChange || vargs.inputs.length > 0 || vargs.outputs.length > 0;
308
- vargs.isSignAction =
309
- vargs.isNewTx && (vargs.options.signAndProcess === false || vargs.inputs.some(i => i.unlockingScript === undefined));
310
- vargs.isDelayed = vargs.options.acceptDelayedBroadcast;
311
- vargs.isNoSend = vargs.options.noSend;
312
- return vargs;
313
- }
314
- /**
315
- * Set all default true/false booleans to true or false if undefined.
316
- * Set all possibly undefined numbers to their default values.
317
- * Set all possibly undefined arrays to empty arrays.
318
- * Convert string outpoints to `{ txid: string, vout: number }`
319
- */
320
- function validateSignActionOptions(options) {
321
- const o = options || {};
322
- const vo = {
323
- acceptDelayedBroadcast: defaultTrue(o.acceptDelayedBroadcast),
324
- returnTXIDOnly: defaultFalse(o.returnTXIDOnly),
325
- noSend: defaultFalse(o.noSend),
326
- sendWith: defaultEmpty(o.sendWith)
327
- };
328
- return vo;
329
- }
330
- function validateSignActionArgs(args) {
331
- const vargs = {
332
- spends: args.spends,
333
- reference: args.reference,
334
- options: validateSignActionOptions(args.options),
335
- isSendWith: false,
336
- isDelayed: false,
337
- isNoSend: false,
338
- isNewTx: true,
339
- isRemixChange: false,
340
- isTestWerrReviewActions: false
341
- };
342
- vargs.isSendWith = vargs.options.sendWith.length > 0;
343
- vargs.isDelayed = vargs.options.acceptDelayedBroadcast;
344
- vargs.isNoSend = vargs.options.noSend;
345
- return vargs;
346
- }
347
- function validateAbortActionArgs(args) {
348
- const vargs = {
349
- reference: validateBase64String(args.reference, 'reference')
350
- };
351
- return vargs;
352
- }
353
- function validateWalletPayment(args) {
354
- if (args === undefined)
355
- return undefined;
356
- const v = {
357
- derivationPrefix: validateBase64String(args.derivationPrefix, 'derivationPrefix'),
358
- derivationSuffix: validateBase64String(args.derivationSuffix, 'derivationSuffix'),
359
- senderIdentityKey: validateHexString(args.senderIdentityKey, 'senderIdentityKey')
360
- };
361
- return v;
362
- }
363
- function validateBasketInsertion(args) {
364
- if (args === undefined)
365
- return undefined;
366
- const v = {
367
- basket: validateBasket(args.basket),
368
- customInstructions: validateOptionalStringLength(args.customInstructions, 'customInstructions', 0, 1000), // TODO: real max??
369
- tags: defaultEmpty(args.tags).map(t => validateTag(t))
370
- };
371
- return v;
372
- }
373
- function validateInternalizeOutput(args) {
374
- if (args.protocol !== 'basket insertion' && args.protocol !== 'wallet payment')
375
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('protocol', `'basket insertion' or 'wallet payment'`);
376
- const v = {
377
- outputIndex: validatePositiveIntegerOrZero(args.outputIndex, 'outputIndex'),
378
- protocol: args.protocol,
379
- paymentRemittance: validateWalletPayment(args.paymentRemittance),
380
- insertionRemittance: validateBasketInsertion(args.insertionRemittance)
381
- };
382
- return v;
383
- }
384
- function validateOriginator(s) {
385
- if (s === undefined)
386
- return undefined;
387
- s = s.trim().toLowerCase();
388
- validateStringLength(s, 'originator', 1, 250);
389
- const sps = s.split('.');
390
- for (const sp of sps) {
391
- validateStringLength(sp, 'originator part', 1, 63);
392
- }
393
- return s;
394
- }
395
- function validateInternalizeActionArgs(args) {
396
- const vargs = {
397
- tx: args.tx,
398
- outputs: args.outputs.map(o => validateInternalizeOutput(o)),
399
- description: validateStringLength(args.description, 'description', 5, 2000),
400
- labels: (args.labels || []).map(t => validateLabel(t)),
401
- seekPermission: defaultTrue(args.seekPermission)
402
- };
403
- try {
404
- const beef = sdk_1.Beef.fromBinary(vargs.tx);
405
- if (beef.txs.length < 1)
406
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('tx', `at least one transaction to internalize an output from`);
407
- }
408
- catch (_a) {
409
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('tx', `valid with at least one transaction to internalize an output from`);
410
- }
411
- if (vargs.outputs.length < 1)
412
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('outputs', `at least one output to internalize from the transaction`);
413
- return vargs;
414
- }
415
- function validateOptionalOutpointString(outpoint, name) {
416
- if (outpoint === undefined)
417
- return undefined;
418
- return validateOutpointString(outpoint, name);
419
- }
420
- function validateOutpointString(outpoint, name) {
421
- const s = outpoint.split('.');
422
- if (s.length !== 2 || !Number.isInteger(Number(s[1])))
423
- throw new WERR_errors_1.WERR_INVALID_PARAMETER(name, `txid as hex string and numeric output index joined with '.'`);
424
- const txid = validateHexString(s[0], `${name} txid`, undefined, 64);
425
- const vout = validatePositiveIntegerOrZero(Number(s[1]), `${name} vout`);
426
- return `${txid}.${vout}`;
427
- }
428
- function validateRelinquishOutputArgs(args) {
429
- const vargs = {
430
- basket: validateBasket(args.basket),
431
- output: validateOutpointString(args.output, 'output')
432
- };
433
- return vargs;
434
- }
435
- function validateRelinquishCertificateArgs(args) {
436
- const vargs = {
437
- type: validateBase64String(args.type, 'type'),
438
- serialNumber: validateBase64String(args.serialNumber, 'serialNumber'),
439
- certifier: validateHexString(args.certifier, 'certifier')
440
- };
441
- return vargs;
442
- }
443
- function validateListCertificatesArgs(args) {
444
- const vargs = {
445
- certifiers: defaultEmpty(args.certifiers.map(c => validateHexString(c.trim(), 'certifiers'))),
446
- types: defaultEmpty(args.types.map(t => validateBase64String(t.trim(), 'types'))),
447
- limit: validateInteger(args.limit, 'limit', 10, 1, 10000),
448
- offset: validatePositiveIntegerOrZero(defaultZero(args.offset), 'offset'),
449
- privileged: defaultFalse(args.privileged),
450
- privilegedReason: validateOptionalStringLength(args.privilegedReason, 'privilegedReason', 5, 50),
451
- partial: undefined
452
- };
453
- return vargs;
454
- }
455
- function validateCertificateFields(fields) {
456
- for (const fieldName of Object.keys(fields)) {
457
- validateStringLength(fieldName, 'field name', 1, 50);
458
- }
459
- return fields;
460
- }
461
- function validateKeyringRevealer(kr, name) {
462
- if (kr === 'certifier')
463
- return kr;
464
- return validateHexString(kr, name);
465
- }
466
- function validateOptionalKeyringRevealer(kr, name) {
467
- if (kr === undefined)
468
- return undefined;
469
- return validateKeyringRevealer(kr, name);
470
- }
471
- function validateKeyringForSubject(kr, name) {
472
- for (const fn of Object.keys(kr)) {
473
- validateStringLength(fn, `${name} field name`, 1, 50);
474
- validateBase64String(kr[fn], `${name} field value`);
475
- }
476
- return kr;
477
- }
478
- function validateOptionalKeyringForSubject(kr, name) {
479
- if (kr === undefined)
480
- return undefined;
481
- return validateKeyringForSubject(kr, name);
482
- }
483
- /**
484
- *
485
- * @param args
486
- * @param subject Must be valid for "direct" `acquisitionProtocol`. public key of the certificate subject.
487
- * @returns
488
- */
489
- async function validateAcquireCertificateArgs(args) {
490
- const vargs = {
491
- acquisitionProtocol: args.acquisitionProtocol,
492
- type: validateBase64String(args.type, 'type'),
493
- serialNumber: validateOptionalBase64String(args.serialNumber, 'serialNumber'),
494
- certifier: validateHexString(args.certifier, 'certifier'),
495
- revocationOutpoint: validateOptionalOutpointString(args.revocationOutpoint, 'revocationOutpoint'),
496
- fields: validateCertificateFields(args.fields),
497
- signature: validateOptionalHexString(args.signature, 'signature'),
498
- certifierUrl: args.certifierUrl,
499
- keyringRevealer: validateOptionalKeyringRevealer(args.keyringRevealer, 'keyringRevealer'),
500
- keyringForSubject: validateOptionalKeyringForSubject(args.keyringForSubject, 'keyringForSubject'),
501
- privileged: defaultFalse(args.privileged),
502
- privilegedReason: validateOptionalStringLength(args.privilegedReason, 'privilegedReason', 5, 50)
503
- };
504
- if (vargs.privileged && !vargs.privilegedReason)
505
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('privilegedReason', `valid when 'privileged' is true `);
506
- if (vargs.acquisitionProtocol === 'direct') {
507
- if (!vargs.serialNumber)
508
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('serialNumber', 'valid when acquisitionProtocol is "direct"');
509
- if (!vargs.signature)
510
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('signature', 'valid when acquisitionProtocol is "direct"');
511
- if (!vargs.revocationOutpoint)
512
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('revocationOutpoint', 'valid when acquisitionProtocol is "direct"');
513
- }
514
- return vargs;
515
- }
516
- function validateAcquireIssuanceCertificateArgs(args) {
517
- if (args.acquisitionProtocol !== 'issuance')
518
- throw new WERR_errors_1.WERR_INTERNAL('Only acquire certificate via issuance requests allowed here.');
519
- if (args.serialNumber)
520
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('serialNumber', 'valid when acquisitionProtocol is "direct"');
521
- if (args.signature)
522
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('signature', 'valid when acquisitionProtocol is "direct"');
523
- if (args.revocationOutpoint)
524
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('revocationOutpoint', 'valid when acquisitionProtocol is "direct"');
525
- if (args.keyringRevealer)
526
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('keyringRevealer', 'valid when acquisitionProtocol is "direct"');
527
- if (args.keyringForSubject)
528
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('keyringForSubject', 'valid when acquisitionProtocol is "direct"');
529
- if (!args.certifierUrl)
530
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('certifierUrl', 'valid when acquisitionProtocol is "issuance"');
531
- if (args.privileged && !args.privilegedReason)
532
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('privilegedReason', `valid when 'privileged' is true `);
533
- const vargs = {
534
- type: validateBase64String(args.type, 'type'),
535
- certifier: validateHexString(args.certifier, 'certifier'),
536
- certifierUrl: args.certifierUrl,
537
- fields: validateCertificateFields(args.fields),
538
- privileged: defaultFalse(args.privileged),
539
- privilegedReason: validateOptionalStringLength(args.privilegedReason, 'privilegedReason', 5, 50),
540
- subject: ''
541
- };
542
- return vargs;
543
- }
544
- function validateAcquireDirectCertificateArgs(args) {
545
- if (args.acquisitionProtocol !== 'direct')
546
- throw new WERR_errors_1.WERR_INTERNAL('Only acquire direct certificate requests allowed here.');
547
- if (!args.serialNumber)
548
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('serialNumber', 'valid when acquisitionProtocol is "direct"');
549
- if (!args.signature)
550
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('signature', 'valid when acquisitionProtocol is "direct"');
551
- if (!args.revocationOutpoint)
552
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('revocationOutpoint', 'valid when acquisitionProtocol is "direct"');
553
- if (!args.keyringRevealer)
554
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('keyringRevealer', 'valid when acquisitionProtocol is "direct"');
555
- if (!args.keyringForSubject)
556
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('keyringForSubject', 'valid when acquisitionProtocol is "direct"');
557
- if (args.privileged && !args.privilegedReason)
558
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('privilegedReason', `valid when 'privileged' is true `);
559
- const vargs = {
560
- type: validateBase64String(args.type, 'type'),
561
- serialNumber: validateBase64String(args.serialNumber, 'serialNumber'),
562
- certifier: validateHexString(args.certifier, 'certifier'),
563
- revocationOutpoint: validateOutpointString(args.revocationOutpoint, 'revocationOutpoint'),
564
- fields: validateCertificateFields(args.fields),
565
- signature: validateHexString(args.signature, 'signature'),
566
- keyringRevealer: validateKeyringRevealer(args.keyringRevealer, 'keyringRevealer'),
567
- keyringForSubject: validateKeyringForSubject(args.keyringForSubject, 'keyringForSubject'),
568
- privileged: defaultFalse(args.privileged),
569
- privilegedReason: validateOptionalStringLength(args.privilegedReason, 'privilegedReason', 5, 50),
570
- subject: ''
571
- };
572
- return vargs;
573
- }
574
- function validateProveCertificateArgs(args) {
575
- if (args.privileged && !args.privilegedReason)
576
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('privilegedReason', `valid when 'privileged' is true `);
577
- const vargs = {
578
- type: validateOptionalBase64String(args.certificate.type, 'certificate.type'),
579
- serialNumber: validateOptionalBase64String(args.certificate.serialNumber, 'certificate.serialNumber'),
580
- certifier: validateOptionalHexString(args.certificate.certifier, 'certificate.certifier'),
581
- subject: validateOptionalHexString(args.certificate.subject, 'certificate.subject'),
582
- revocationOutpoint: validateOptionalOutpointString(args.certificate.revocationOutpoint, 'certificate.revocationOutpoint'),
583
- signature: validateOptionalHexString(args.certificate.signature, 'certificate.signature'),
584
- fieldsToReveal: defaultEmpty(args.fieldsToReveal).map(fieldName => validateStringLength(fieldName, `fieldsToReveal ${fieldName}`, 1, 50)),
585
- verifier: validateHexString(args.verifier, 'verifier'),
586
- privileged: defaultFalse(args.privileged),
587
- privilegedReason: validateOptionalStringLength(args.privilegedReason, 'privilegedReason', 5, 50)
588
- };
589
- return vargs;
590
- }
591
- function validateDiscoverByIdentityKeyArgs(args) {
592
- const vargs = {
593
- identityKey: validateHexString(args.identityKey, 'identityKey', 66, 66),
594
- limit: validateInteger(args.limit, 'limit', 10, 1, 10000),
595
- offset: validatePositiveIntegerOrZero(defaultZero(args.offset), 'offset'),
596
- seekPermission: defaultFalse(args.seekPermission)
597
- };
598
- return vargs;
599
- }
600
- function validateAttributes(attributes) {
601
- for (const fieldName of Object.keys(attributes)) {
602
- validateStringLength(fieldName, `field name ${fieldName}`, 1, 50);
603
- }
604
- return attributes;
605
- }
606
- function validateDiscoverByAttributesArgs(args) {
607
- const vargs = {
608
- attributes: validateAttributes(args.attributes),
609
- limit: validateInteger(args.limit, 'limit', 10, 1, 10000),
610
- offset: validatePositiveIntegerOrZero(defaultZero(args.offset), 'offset'),
611
- seekPermission: defaultFalse(args.seekPermission)
612
- };
613
- return vargs;
614
- }
615
- /**
616
- * @param {BasketStringUnder300Bytes} args.basket - Required. The associated basket name whose outputs should be listed.
617
- * @param {OutputTagStringUnder300Bytes[]} [args.tags] - Optional. Filter outputs based on these tags.
618
- * @param {'all' | 'any'} [args.tagQueryMode] - Optional. Filter mode, defining whether all or any of the tags must match. By default, any tag can match.
619
- * @param {'locking scripts' | 'entire transactions'} [args.include] - Optional. Whether to include locking scripts (with each output) or entire transactions (as aggregated BEEF, at the top level) in the result. By default, unless specified, neither are returned.
620
- * @param {BooleanDefaultFalse} [args.includeEntireTransactions] - Optional. Whether to include the entire transaction(s) in the result.
621
- * @param {BooleanDefaultFalse} [args.includeCustomInstructions] - Optional. Whether custom instructions should be returned in the result.
622
- * @param {BooleanDefaultFalse} [args.includeTags] - Optional. Whether the tags associated with the output should be returned.
623
- * @param {BooleanDefaultFalse} [args.includeLabels] - Optional. Whether the labels associated with the transaction containing the output should be returned.
624
- * @param {PositiveIntegerDefault10Max10000} [args.limit] - Optional limit on the number of outputs to return.
625
- * @param {number} [args.offset] - If positive or zero: Number of outputs to skip before starting to return results, oldest first.
626
- * If negative: Outputs are returned newest first and offset of -1 is the newest output.
627
- * When using negative offsets, caution is required as new outputs may be added between calls,
628
- * potentially causing outputs to be duplicated across calls.
629
- * @param {BooleanDefaultTrue} [args.seekPermission] — Optional. Whether to seek permission from the user for this operation if required. Default true, will return an error rather than proceed if set to false.
630
- */
631
- function validateListOutputsArgs(args) {
632
- let tagQueryMode;
633
- if (args.tagQueryMode === undefined || args.tagQueryMode === 'any')
634
- tagQueryMode = 'any';
635
- else if (args.tagQueryMode === 'all')
636
- tagQueryMode = 'all';
637
- else
638
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('tagQueryMode', `undefined, 'any', or 'all'`);
639
- const vargs = {
640
- basket: validateStringLength(args.basket, 'basket', 1, 300),
641
- tags: (args.tags || []).map(t => validateStringLength(t, 'tag', 1, 300)),
642
- tagQueryMode,
643
- includeLockingScripts: args.include === 'locking scripts',
644
- includeTransactions: args.include === 'entire transactions',
645
- includeCustomInstructions: defaultFalse(args.includeCustomInstructions),
646
- includeTags: defaultFalse(args.includeTags),
647
- includeLabels: defaultFalse(args.includeLabels),
648
- limit: validateInteger(args.limit, 'limit', 10, 1, 10000),
649
- offset: validateInteger(args.offset, 'offset', 0, undefined, undefined),
650
- seekPermission: defaultTrue(args.seekPermission),
651
- knownTxids: []
652
- };
653
- return vargs;
654
- }
655
- /**
656
- * @param {LabelStringUnder300Bytes[]} args.labels - An array of labels used to filter actions.
657
- * @param {'any' | 'all'} [args.labelQueryMode] - Optional. Specifies how to match labels (default is any which matches any of the labels).
658
- * @param {BooleanDefaultFalse} [args.includeLabels] - Optional. Whether to include transaction labels in the result set.
659
- * @param {BooleanDefaultFalse} [args.includeInputs] - Optional. Whether to include input details in the result set.
660
- * @param {BooleanDefaultFalse} [args.includeInputSourceLockingScripts] - Optional. Whether to include input source locking scripts in the result set.
661
- * @param {BooleanDefaultFalse} [args.includeInputUnlockingScripts] - Optional. Whether to include input unlocking scripts in the result set.
662
- * @param {BooleanDefaultFalse} [args.includeOutputs] - Optional. Whether to include output details in the result set.
663
- * @param {BooleanDefaultFalse} [args.includeOutputLockingScripts] - Optional. Whether to include output locking scripts in the result set.
664
- * @param {PositiveIntegerDefault10Max10000} [args.limit] - Optional. The maximum number of transactions to retrieve.
665
- * @param {PositiveIntegerOrZero} [args.offset] - Optional. Number of transactions to skip before starting to return the results.
666
- * @param {BooleanDefaultTrue} [args.seekPermission] — Optional. Whether to seek permission from the user for this operation if required. Default true, will return an error rather than proceed if set to false.
667
- */
668
- function validateListActionsArgs(args) {
669
- let labelQueryMode;
670
- if (args.labelQueryMode === undefined || args.labelQueryMode === 'any')
671
- labelQueryMode = 'any';
672
- else if (args.labelQueryMode === 'all')
673
- labelQueryMode = 'all';
674
- else
675
- throw new WERR_errors_1.WERR_INVALID_PARAMETER('labelQueryMode', `undefined, 'any', or 'all'`);
676
- const vargs = {
677
- labels: (args.labels || []).map(t => validateLabel(t)),
678
- labelQueryMode,
679
- includeLabels: defaultFalse(args.includeLabels),
680
- includeInputs: defaultFalse(args.includeInputs),
681
- includeInputSourceLockingScripts: defaultFalse(args.includeInputSourceLockingScripts),
682
- includeInputUnlockingScripts: defaultFalse(args.includeInputUnlockingScripts),
683
- includeOutputs: defaultFalse(args.includeOutputs),
684
- includeOutputLockingScripts: defaultFalse(args.includeOutputLockingScripts),
685
- limit: validateInteger(args.limit, 'limit', 10, 1, 10000),
686
- offset: validateInteger(args.offset, 'offset', 0, 0),
687
- seekPermission: defaultTrue(args.seekPermission)
688
- };
689
- return vargs;
690
- }
691
- //# sourceMappingURL=validationHelpers.js.map