@audius/sdk 0.0.0

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 (278) hide show
  1. package/.eslintrc +38 -0
  2. package/.prettierrc.js +1 -0
  3. package/.python-version +1 -0
  4. package/Dockerfile +15 -0
  5. package/README.md +3 -0
  6. package/babel.config.js +3 -0
  7. package/data-contracts/ABIs/AdminUpgradeabilityProxy.json +132 -0
  8. package/data-contracts/ABIs/BaseAdminUpgradeabilityProxy.json +113 -0
  9. package/data-contracts/ABIs/BaseUpgradeabilityProxy.json +22 -0
  10. package/data-contracts/ABIs/DiscoveryProviderFactory.json +189 -0
  11. package/data-contracts/ABIs/DiscoveryProviderFactoryInterface.json +61 -0
  12. package/data-contracts/ABIs/DiscoveryProviderStorage.json +205 -0
  13. package/data-contracts/ABIs/DiscoveryProviderStorageInterface.json +65 -0
  14. package/data-contracts/ABIs/ECDSA.json +4 -0
  15. package/data-contracts/ABIs/IPLDBlacklistFactory.json +168 -0
  16. package/data-contracts/ABIs/Initializable.json +4 -0
  17. package/data-contracts/ABIs/Migrations.json +67 -0
  18. package/data-contracts/ABIs/OpenZeppelinUpgradesAddress.json +4 -0
  19. package/data-contracts/ABIs/Ownable.json +79 -0
  20. package/data-contracts/ABIs/PlaylistFactory.json +669 -0
  21. package/data-contracts/ABIs/PlaylistFactoryInterface.json +42 -0
  22. package/data-contracts/ABIs/PlaylistStorage.json +250 -0
  23. package/data-contracts/ABIs/PlaylistStorageInterface.json +129 -0
  24. package/data-contracts/ABIs/Proxy.json +10 -0
  25. package/data-contracts/ABIs/Registry.json +240 -0
  26. package/data-contracts/ABIs/RegistryContract.json +102 -0
  27. package/data-contracts/ABIs/RegistryContractInterface.json +28 -0
  28. package/data-contracts/ABIs/RegistryInterface.json +66 -0
  29. package/data-contracts/ABIs/SigningLogic.json +43 -0
  30. package/data-contracts/ABIs/SigningLogicInitializable.json +46 -0
  31. package/data-contracts/ABIs/SocialFeatureFactory.json +460 -0
  32. package/data-contracts/ABIs/SocialFeatureStorage.json +225 -0
  33. package/data-contracts/ABIs/SocialFeatureStorageInterface.json +123 -0
  34. package/data-contracts/ABIs/TestContract.json +135 -0
  35. package/data-contracts/ABIs/TestContractInterface.json +19 -0
  36. package/data-contracts/ABIs/TestContractWithStorage.json +165 -0
  37. package/data-contracts/ABIs/TestContractWithStorageInterface.json +24 -0
  38. package/data-contracts/ABIs/TestStorage.json +144 -0
  39. package/data-contracts/ABIs/TestStorageInterface.json +42 -0
  40. package/data-contracts/ABIs/TestUserReplicaSetManager.json +432 -0
  41. package/data-contracts/ABIs/TrackFactory.json +391 -0
  42. package/data-contracts/ABIs/TrackFactoryInterface.json +73 -0
  43. package/data-contracts/ABIs/TrackStorage.json +223 -0
  44. package/data-contracts/ABIs/TrackStorageInterface.json +121 -0
  45. package/data-contracts/ABIs/UpgradeabilityProxy.json +37 -0
  46. package/data-contracts/ABIs/UserFactory.json +657 -0
  47. package/data-contracts/ABIs/UserFactoryInterface.json +65 -0
  48. package/data-contracts/ABIs/UserLibraryFactory.json +334 -0
  49. package/data-contracts/ABIs/UserReplicaSetManager.json +418 -0
  50. package/data-contracts/ABIs/UserStorage.json +233 -0
  51. package/data-contracts/ABIs/UserStorageInterface.json +93 -0
  52. package/data-contracts/signatureSchemas.ts +1236 -0
  53. package/dist/core.d.ts +446 -0
  54. package/dist/core.js +769 -0
  55. package/dist/core.js.map +1 -0
  56. package/dist/index.d.ts +689 -0
  57. package/dist/index.js +72850 -0
  58. package/dist/index.js.map +1 -0
  59. package/eth-contracts/ABIs/Address.json +4 -0
  60. package/eth-contracts/ABIs/AudiusAdminUpgradeabilityProxy.json +105 -0
  61. package/eth-contracts/ABIs/AudiusClaimDistributor.json +4968 -0
  62. package/eth-contracts/ABIs/AudiusToken.json +724 -0
  63. package/eth-contracts/ABIs/BaseUpgradeabilityProxy.json +23 -0
  64. package/eth-contracts/ABIs/Checkpointing.json +4 -0
  65. package/eth-contracts/ABIs/ClaimsManager.json +539 -0
  66. package/eth-contracts/ABIs/Context.json +11 -0
  67. package/eth-contracts/ABIs/DelegateManager.json +989 -0
  68. package/eth-contracts/ABIs/DelegateManagerV2.json +1049 -0
  69. package/eth-contracts/ABIs/DelegateManagerV2Bad.json +1049 -0
  70. package/eth-contracts/ABIs/ERC20.json +252 -0
  71. package/eth-contracts/ABIs/ERC20Burnable.json +287 -0
  72. package/eth-contracts/ABIs/ERC20Detailed.json +270 -0
  73. package/eth-contracts/ABIs/ERC20Mintable.json +364 -0
  74. package/eth-contracts/ABIs/ERC20Pausable.json +397 -0
  75. package/eth-contracts/ABIs/EthRewardsManager.json +174 -0
  76. package/eth-contracts/ABIs/Governance.json +938 -0
  77. package/eth-contracts/ABIs/GovernanceUpgraded.json +953 -0
  78. package/eth-contracts/ABIs/GovernanceV2.json +938 -0
  79. package/eth-contracts/ABIs/IERC20.json +200 -0
  80. package/eth-contracts/ABIs/Initializable.json +4 -0
  81. package/eth-contracts/ABIs/InitializableV2.json +14 -0
  82. package/eth-contracts/ABIs/Migrations.json +71 -0
  83. package/eth-contracts/ABIs/MinterRole.json +91 -0
  84. package/eth-contracts/ABIs/MockAccount.json +62 -0
  85. package/eth-contracts/ABIs/MockDelegateManager.json +55 -0
  86. package/eth-contracts/ABIs/MockStakingCaller.json +259 -0
  87. package/eth-contracts/ABIs/MockWormhole.json +106 -0
  88. package/eth-contracts/ABIs/OpenZeppelinUpgradesAddress.json +4 -0
  89. package/eth-contracts/ABIs/Ownable.json +93 -0
  90. package/eth-contracts/ABIs/Pausable.json +150 -0
  91. package/eth-contracts/ABIs/PauserRole.json +91 -0
  92. package/eth-contracts/ABIs/Proxy.json +10 -0
  93. package/eth-contracts/ABIs/Registry.json +288 -0
  94. package/eth-contracts/ABIs/Roles.json +4 -0
  95. package/eth-contracts/ABIs/SafeERC20.json +4 -0
  96. package/eth-contracts/ABIs/SafeMath.json +4 -0
  97. package/eth-contracts/ABIs/ServiceProviderFactory.json +1153 -0
  98. package/eth-contracts/ABIs/ServiceTypeManager.json +337 -0
  99. package/eth-contracts/ABIs/Staking.json +555 -0
  100. package/eth-contracts/ABIs/StakingUpgraded.json +570 -0
  101. package/eth-contracts/ABIs/TestContract.json +44 -0
  102. package/eth-contracts/ABIs/TrustedNotifierManager.json +265 -0
  103. package/eth-contracts/ABIs/Uint256Helpers.json +4 -0
  104. package/eth-contracts/ABIs/UpgradeabilityProxy.json +40 -0
  105. package/eth-contracts/ABIs/Wormhole.json +45 -0
  106. package/eth-contracts/ABIs/WormholeClient.json +155 -0
  107. package/examples/file.mp3 +0 -0
  108. package/examples/initAudiusLibs.js +86 -0
  109. package/examples/initializeVersions.js +95 -0
  110. package/examples/pic.jpg +0 -0
  111. package/initScripts/configureLocalDiscProv.js +167 -0
  112. package/initScripts/helpers/claim.js +43 -0
  113. package/initScripts/helpers/distributeTokens.js +24 -0
  114. package/initScripts/helpers/spRegistration.js +138 -0
  115. package/initScripts/helpers/utils.js +34 -0
  116. package/initScripts/helpers/version.js +93 -0
  117. package/initScripts/local.js +617 -0
  118. package/initScripts/mainnet.js +131 -0
  119. package/initScripts/manageProdRelayerWallets.js +191 -0
  120. package/package.json +125 -0
  121. package/rollup.config.js +164 -0
  122. package/scripts/AudiusClaimDistributor.json +4968 -0
  123. package/scripts/Wormhole.json +155 -0
  124. package/scripts/addCIDToIpldBlacklist.js +124 -0
  125. package/scripts/circleci-test.sh +53 -0
  126. package/scripts/communityRewards/transferCommunityRewardsToSolana.js +222 -0
  127. package/scripts/ipfs.sh +58 -0
  128. package/scripts/migrate_contracts.sh +25 -0
  129. package/scripts/reset.sh +65 -0
  130. package/scripts/test.sh +77 -0
  131. package/src/api/account.js +670 -0
  132. package/src/api/base.js +122 -0
  133. package/src/api/file.js +168 -0
  134. package/src/api/playlist.js +328 -0
  135. package/src/api/rewards.d.ts +4 -0
  136. package/src/api/rewards.js +682 -0
  137. package/src/api/serviceProvider.js +154 -0
  138. package/src/api/track.js +604 -0
  139. package/src/api/user.js +888 -0
  140. package/src/api/user.test.js +172 -0
  141. package/src/constants.ts +7 -0
  142. package/src/core.ts +3 -0
  143. package/src/index.js +6 -0
  144. package/src/libs.d.ts +3 -0
  145. package/src/libs.js +619 -0
  146. package/src/sanityChecks/addSecondaries.js +40 -0
  147. package/src/sanityChecks/assignReplicaSetIfNecessary.js +10 -0
  148. package/src/sanityChecks/index.d.ts +9 -0
  149. package/src/sanityChecks/index.js +31 -0
  150. package/src/sanityChecks/isCreator.js +73 -0
  151. package/src/sanityChecks/needsRecoveryEmail.js +20 -0
  152. package/src/sanityChecks/rolloverNodes.js +74 -0
  153. package/src/sanityChecks/sanitizeNodes.js +24 -0
  154. package/src/sanityChecks/syncNodes.js +28 -0
  155. package/src/sdk/constants.ts +10 -0
  156. package/src/sdk/index.ts +1 -0
  157. package/src/sdk/oauth/Oauth.ts +265 -0
  158. package/src/sdk/oauth/index.ts +1 -0
  159. package/src/sdk/sdk.ts +102 -0
  160. package/src/service-selection/ServiceSelection.test.ts +320 -0
  161. package/src/service-selection/ServiceSelection.ts +460 -0
  162. package/src/service-selection/constants.ts +14 -0
  163. package/src/service-selection/index.ts +1 -0
  164. package/src/services/ABIDecoder/AudiusABIDecoder.ts +71 -0
  165. package/src/services/ABIDecoder/index.ts +1 -0
  166. package/src/services/comstock/Comstock.ts +39 -0
  167. package/src/services/comstock/index.ts +1 -0
  168. package/src/services/contracts/ContractClient.ts +227 -0
  169. package/src/services/contracts/GovernedContractClient.ts +53 -0
  170. package/src/services/contracts/ProviderSelection.ts +42 -0
  171. package/src/services/creatorNode/CreatorNode.ts +1065 -0
  172. package/src/services/creatorNode/CreatorNodeSelection.test.ts +997 -0
  173. package/src/services/creatorNode/CreatorNodeSelection.ts +488 -0
  174. package/src/services/creatorNode/constants.ts +10 -0
  175. package/src/services/creatorNode/index.ts +2 -0
  176. package/src/services/dataContracts/AudiusContracts.ts +234 -0
  177. package/src/services/dataContracts/IPLDBlacklistFactoryClient.ts +73 -0
  178. package/src/services/dataContracts/PlaylistFactoryClient.ts +370 -0
  179. package/src/services/dataContracts/RegistryClient.ts +95 -0
  180. package/src/services/dataContracts/SocialFeatureFactoryClient.ts +196 -0
  181. package/src/services/dataContracts/TrackFactoryClient.ts +131 -0
  182. package/src/services/dataContracts/UserFactoryClient.ts +351 -0
  183. package/src/services/dataContracts/UserLibraryFactoryClient.ts +115 -0
  184. package/src/services/dataContracts/UserReplicaSetManagerClient.ts +206 -0
  185. package/src/services/dataContracts/index.ts +1 -0
  186. package/src/services/discoveryProvider/DiscoveryProvider.ts +1168 -0
  187. package/src/services/discoveryProvider/DiscoveryProviderSelection.test.ts +536 -0
  188. package/src/services/discoveryProvider/DiscoveryProviderSelection.ts +383 -0
  189. package/src/services/discoveryProvider/constants.ts +13 -0
  190. package/src/services/discoveryProvider/index.ts +1 -0
  191. package/src/services/discoveryProvider/requests.ts +629 -0
  192. package/src/services/ethContracts/AudiusTokenClient.ts +163 -0
  193. package/src/services/ethContracts/ClaimDistributionClient.ts +45 -0
  194. package/src/services/ethContracts/ClaimsManagerClient.ts +102 -0
  195. package/src/services/ethContracts/DelegateManagerClient.ts +480 -0
  196. package/src/services/ethContracts/EthContracts.ts +359 -0
  197. package/src/services/ethContracts/EthRewardsManagerClient.ts +33 -0
  198. package/src/services/ethContracts/GovernanceClient.ts +451 -0
  199. package/src/services/ethContracts/RegistryClient.ts +33 -0
  200. package/src/services/ethContracts/ServiceProviderFactoryClient.ts +691 -0
  201. package/src/services/ethContracts/ServiceTypeManagerClient.ts +112 -0
  202. package/src/services/ethContracts/StakingProxyClient.ts +97 -0
  203. package/src/services/ethContracts/TrustedNotifierManagerClient.ts +101 -0
  204. package/src/services/ethContracts/WormholeClient.ts +97 -0
  205. package/src/services/ethContracts/index.ts +1 -0
  206. package/src/services/ethWeb3Manager/EthWeb3Manager.ts +239 -0
  207. package/src/services/ethWeb3Manager/index.ts +1 -0
  208. package/src/services/hedgehog/Hedgehog.ts +96 -0
  209. package/src/services/hedgehog/index.ts +1 -0
  210. package/src/services/identity/IdentityService.ts +551 -0
  211. package/src/services/identity/index.ts +1 -0
  212. package/src/services/identity/requests.ts +65 -0
  213. package/src/services/schemaValidator/SchemaValidator.ts +105 -0
  214. package/src/services/schemaValidator/index.ts +1 -0
  215. package/src/services/schemaValidator/schemas/trackSchema.json +267 -0
  216. package/src/services/schemaValidator/schemas/userSchema.json +230 -0
  217. package/src/services/solanaAudiusData/errors.ts +20 -0
  218. package/src/services/solanaAudiusData/index.ts +1189 -0
  219. package/src/services/solanaWeb3Manager/errors.js +101 -0
  220. package/src/services/solanaWeb3Manager/index.d.ts +46 -0
  221. package/src/services/solanaWeb3Manager/index.js +655 -0
  222. package/src/services/solanaWeb3Manager/padBNToUint8Array.ts +7 -0
  223. package/src/services/solanaWeb3Manager/rewards.js +941 -0
  224. package/src/services/solanaWeb3Manager/rewardsAttester.ts +1093 -0
  225. package/src/services/solanaWeb3Manager/tokenAccount.js +149 -0
  226. package/src/services/solanaWeb3Manager/transactionHandler.js +345 -0
  227. package/src/services/solanaWeb3Manager/transfer.js +272 -0
  228. package/src/services/solanaWeb3Manager/userBank.js +160 -0
  229. package/src/services/solanaWeb3Manager/utils.d.ts +31 -0
  230. package/src/services/solanaWeb3Manager/utils.js +163 -0
  231. package/src/services/solanaWeb3Manager/wAudio.js +28 -0
  232. package/src/services/solanaWeb3Manager/wAudio.test.js +30 -0
  233. package/src/services/web3Manager/Web3Config.ts +14 -0
  234. package/src/services/web3Manager/Web3Manager.ts +360 -0
  235. package/src/services/web3Manager/XMLHttpRequest.ts +11 -0
  236. package/src/services/web3Manager/index.ts +2 -0
  237. package/src/services/wormhole/index.js +424 -0
  238. package/src/types.ts +8 -0
  239. package/src/userStateManager.ts +53 -0
  240. package/src/utils/apiSigning.ts +51 -0
  241. package/src/utils/captcha.ts +97 -0
  242. package/src/utils/estimateGas.ts +64 -0
  243. package/src/utils/fileHasher.ts +278 -0
  244. package/src/utils/importContractABI.d.ts +9 -0
  245. package/src/utils/importContractABI.js +19 -0
  246. package/src/utils/index.ts +11 -0
  247. package/src/utils/multiProvider.ts +72 -0
  248. package/src/utils/network.test.ts +127 -0
  249. package/src/utils/network.ts +308 -0
  250. package/src/utils/promiseFight.test.ts +87 -0
  251. package/src/utils/promiseFight.ts +36 -0
  252. package/src/utils/signatures.ts +139 -0
  253. package/src/utils/types.ts +34 -0
  254. package/src/utils/utils.test.ts +36 -0
  255. package/src/utils/utils.ts +235 -0
  256. package/src/utils/uuid.ts +14 -0
  257. package/src/web3.d.ts +9 -0
  258. package/src/web3.js +8 -0
  259. package/tests/assets/static_image.png +0 -0
  260. package/tests/assets/static_text.txt +1 -0
  261. package/tests/audiusTokenClientTest.js +37 -0
  262. package/tests/creatorNodeTest.js +19 -0
  263. package/tests/fileHasherTest.js +125 -0
  264. package/tests/governanceTest.js +382 -0
  265. package/tests/helpers.js +105 -0
  266. package/tests/index.js +14 -0
  267. package/tests/playlistClientTest.js +157 -0
  268. package/tests/providerSelectionTest.js +241 -0
  269. package/tests/registryClientTest.js +19 -0
  270. package/tests/rewardsAttesterTest.js +373 -0
  271. package/tests/serviceTypeManagerClientTest.js +33 -0
  272. package/tests/socialFeatureClientTest.js +79 -0
  273. package/tests/stakingTest.js +302 -0
  274. package/tests/trackClientTest.js +86 -0
  275. package/tests/userClientTest.js +121 -0
  276. package/tsconfig.json +10 -0
  277. package/types/@audius-hedgehog/index.d.ts +39 -0
  278. package/types/abi-decoder/index.d.ts +41 -0
@@ -0,0 +1,1236 @@
1
+ /**
2
+ * This file includes schemas for use in EIP-712 compliant signature generation and
3
+ * signature validation, generator functions for generating data
4
+ * in the form needed by eth_personalSign / eth-sig-util's signTypedData functions,
5
+ * generators for contract signing domains, and a helper function for generating
6
+ * cryptographically secure nonces in nodejs or in the browser.
7
+ * modeled off: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md
8
+ */
9
+
10
+ import type {
11
+ EIP712Domain,
12
+ EIP712Message,
13
+ EIP712TypedData,
14
+ EIP712TypeProperty,
15
+ EIP712Types
16
+ } from 'eth-sig-util'
17
+
18
+ type DomainFn = (chainId: number, contactAddress: string) => EIP712Domain
19
+
20
+ function getDomainData(
21
+ contractName: string,
22
+ signatureVersion: string,
23
+ chainId: number,
24
+ contractAddress: string
25
+ ): EIP712Domain {
26
+ return {
27
+ name: contractName,
28
+ version: signatureVersion,
29
+ chainId: chainId,
30
+ verifyingContract: contractAddress
31
+ }
32
+ }
33
+
34
+ const getSocialFeatureFactoryDomain: DomainFn = (chainId, contractAddress) => {
35
+ return getDomainData('Social Feature Factory', '1', chainId, contractAddress)
36
+ }
37
+
38
+ const getUserFactoryDomain: DomainFn = (chainId, contractAddress) => {
39
+ return getDomainData('User Factory', '1', chainId, contractAddress)
40
+ }
41
+
42
+ const getTrackFactoryDomain: DomainFn = (chainId, contractAddress) => {
43
+ return getDomainData('Track Factory', '1', chainId, contractAddress)
44
+ }
45
+
46
+ const getPlaylistFactoryDomain: DomainFn = (chainId, contractAddress) => {
47
+ return getDomainData('Playlist Factory', '1', chainId, contractAddress)
48
+ }
49
+
50
+ const getUserLibraryFactoryDomain: DomainFn = (chainId, contractAddress) => {
51
+ return getDomainData('User Library Factory', '1', chainId, contractAddress)
52
+ }
53
+
54
+ const getIPLDBlacklistFactoryDomain: DomainFn = (chainId, contractAddress) => {
55
+ return getDomainData('IPLD Blacklist Factory', '1', chainId, contractAddress)
56
+ }
57
+
58
+ const getUserReplicaSetManagerDomain: DomainFn = (chainId, contractAddress) => {
59
+ return getDomainData(
60
+ 'User Replica Set Manager',
61
+ '1',
62
+ chainId,
63
+ contractAddress
64
+ )
65
+ }
66
+
67
+ export const domains = {
68
+ getSocialFeatureFactoryDomain,
69
+ getUserFactoryDomain,
70
+ getTrackFactoryDomain,
71
+ getPlaylistFactoryDomain,
72
+ getUserLibraryFactoryDomain,
73
+ getIPLDBlacklistFactoryDomain,
74
+ getUserReplicaSetManagerDomain
75
+ }
76
+
77
+ /* contract signing domain */
78
+ const domain = [
79
+ { name: 'name', type: 'string' },
80
+ { name: 'version', type: 'string' },
81
+ { name: 'chainId', type: 'uint256' },
82
+ { name: 'verifyingContract', type: 'address' }
83
+ ]
84
+
85
+ /* user factory requests */
86
+ const addUserRequest = [
87
+ { name: 'handle', type: 'bytes16' },
88
+ { name: 'nonce', type: 'bytes32' }
89
+ ]
90
+
91
+ /* rather than having a schema type for every update op, we have a type for each unique
92
+ * structure */
93
+ const updateUserBytes32 = [
94
+ { name: 'userId', type: 'uint' },
95
+ { name: 'newValue', type: 'bytes32' },
96
+ { name: 'nonce', type: 'bytes32' }
97
+ ]
98
+
99
+ const updateUserString = [
100
+ { name: 'userId', type: 'uint' },
101
+ { name: 'newValue', type: 'string' },
102
+ { name: 'nonce', type: 'bytes32' }
103
+ ]
104
+
105
+ const updateUserBool = [
106
+ { name: 'userId', type: 'uint' },
107
+ { name: 'newValue', type: 'bool' },
108
+ { name: 'nonce', type: 'bytes32' }
109
+ ]
110
+
111
+ /* track factory requests */
112
+ const addTrackRequest = [
113
+ { name: 'trackOwnerId', type: 'uint' },
114
+ { name: 'multihashDigest', type: 'bytes32' },
115
+ { name: 'multihashHashFn', type: 'uint8' },
116
+ { name: 'multihashSize', type: 'uint8' },
117
+ { name: 'nonce', type: 'bytes32' }
118
+ ]
119
+
120
+ const updateTrackRequest = [
121
+ { name: 'trackId', type: 'uint' },
122
+ { name: 'trackOwnerId', type: 'uint' },
123
+ { name: 'multihashDigest', type: 'bytes32' },
124
+ { name: 'multihashHashFn', type: 'uint8' },
125
+ { name: 'multihashSize', type: 'uint8' },
126
+ { name: 'nonce', type: 'bytes32' }
127
+ ]
128
+
129
+ const deleteTrackRequest = [
130
+ { name: 'trackId', type: 'uint' },
131
+ { name: 'nonce', type: 'bytes32' }
132
+ ]
133
+
134
+ /* social features */
135
+ const addTrackRepostRequest = [
136
+ { name: 'userId', type: 'uint' },
137
+ { name: 'trackId', type: 'uint' },
138
+ { name: 'nonce', type: 'bytes32' }
139
+ ]
140
+
141
+ const deleteTrackRepostRequest = addTrackRepostRequest
142
+
143
+ const addPlaylistRepostRequest = [
144
+ { name: 'userId', type: 'uint' },
145
+ { name: 'playlistId', type: 'uint' },
146
+ { name: 'nonce', type: 'bytes32' }
147
+ ]
148
+
149
+ const deletePlaylistRepostRequest = addPlaylistRepostRequest
150
+
151
+ const userFollowRequest = [
152
+ { name: 'followerUserId', type: 'uint' },
153
+ { name: 'followeeUserId', type: 'uint' },
154
+ { name: 'nonce', type: 'bytes32' }
155
+ ]
156
+
157
+ const deleteUserFollowRequest = userFollowRequest
158
+
159
+ const createPlaylistRequest = [
160
+ { name: 'playlistOwnerId', type: 'uint' },
161
+ { name: 'playlistName', type: 'string' },
162
+ { name: 'isPrivate', type: 'bool' },
163
+ { name: 'isAlbum', type: 'bool' },
164
+ { name: 'trackIdsHash', type: 'bytes32' },
165
+ { name: 'nonce', type: 'bytes32' }
166
+ ]
167
+
168
+ const deletePlaylistRequest = [
169
+ { name: 'playlistId', type: 'uint' },
170
+ { name: 'nonce', type: 'bytes32' }
171
+ ]
172
+
173
+ const addPlaylistTrackRequest = [
174
+ { name: 'playlistId', type: 'uint' },
175
+ { name: 'addedTrackId', type: 'uint' },
176
+ { name: 'nonce', type: 'bytes32' }
177
+ ]
178
+
179
+ const deletePlaylistTrackRequest = [
180
+ { name: 'playlistId', type: 'uint' },
181
+ { name: 'deletedTrackId', type: 'uint' },
182
+ { name: 'deletedTrackTimestamp', type: 'uint' },
183
+ { name: 'nonce', type: 'bytes32' }
184
+ ]
185
+
186
+ const orderPlaylistTracksRequest = [
187
+ { name: 'playlistId', type: 'uint' },
188
+ { name: 'trackIdsHash', type: 'bytes32' },
189
+ { name: 'nonce', type: 'bytes32' }
190
+ ]
191
+
192
+ const updatePlaylistPrivacyRequest = [
193
+ { name: 'playlistId', type: 'uint' },
194
+ { name: 'updatedPlaylistPrivacy', type: 'bool' },
195
+ { name: 'nonce', type: 'bytes32' }
196
+ ]
197
+
198
+ const updatePlaylistNameRequest = [
199
+ { name: 'playlistId', type: 'uint' },
200
+ { name: 'updatedPlaylistName', type: 'string' },
201
+ { name: 'nonce', type: 'bytes32' }
202
+ ]
203
+
204
+ const updatePlaylistCoverPhotoRequest = [
205
+ { name: 'playlistId', type: 'uint' },
206
+ { name: 'playlistImageMultihashDigest', type: 'bytes32' },
207
+ { name: 'nonce', type: 'bytes32' }
208
+ ]
209
+
210
+ const updatePlaylistDescriptionRequest = [
211
+ { name: 'playlistId', type: 'uint' },
212
+ { name: 'playlistDescription', type: 'string' },
213
+ { name: 'nonce', type: 'bytes32' }
214
+ ]
215
+
216
+ const updatePlaylistUPCRequest = [
217
+ { name: 'playlistId', type: 'uint' },
218
+ { name: 'playlistUPC', type: 'bytes32' },
219
+ { name: 'nonce', type: 'bytes32' }
220
+ ]
221
+
222
+ const trackSaveRequest = [
223
+ { name: 'userId', type: 'uint' },
224
+ { name: 'trackId', type: 'uint' },
225
+ { name: 'nonce', type: 'bytes32' }
226
+ ]
227
+
228
+ const deleteTrackSaveRequest = trackSaveRequest
229
+
230
+ const playlistSaveRequest = [
231
+ { name: 'userId', type: 'uint' },
232
+ { name: 'playlistId', type: 'uint' },
233
+ { name: 'nonce', type: 'bytes32' }
234
+ ]
235
+
236
+ const deletePlaylistSaveRequest = playlistSaveRequest
237
+
238
+ const addIPLDBlacklist = [
239
+ { name: 'multihashDigest', type: 'bytes32' },
240
+ { name: 'nonce', type: 'bytes32' }
241
+ ]
242
+
243
+ // User replica set manager schemas
244
+ const proposeAddOrUpdateContentNode = [
245
+ { name: 'cnodeSpId', type: 'uint' },
246
+ { name: 'cnodeDelegateOwnerWallet', type: 'address' },
247
+ { name: 'cnodeOwnerWallet', type: 'address' },
248
+ { name: 'proposerSpId', type: 'uint' },
249
+ { name: 'nonce', type: 'bytes32' }
250
+ ]
251
+
252
+ const updateReplicaSet = [
253
+ { name: 'userId', type: 'uint' },
254
+ { name: 'primaryId', type: 'uint' },
255
+ { name: 'secondaryIdsHash', type: 'bytes32' },
256
+ { name: 'oldPrimaryId', type: 'uint' },
257
+ { name: 'oldSecondaryIdsHash', type: 'bytes32' },
258
+ { name: 'nonce', type: 'bytes32' }
259
+ ]
260
+
261
+ export const schemas = {
262
+ domain,
263
+ addUserRequest,
264
+ updateUserBytes32,
265
+ updateUserString,
266
+ updateUserBool,
267
+ addTrackRequest,
268
+ updateTrackRequest,
269
+ deleteTrackRequest,
270
+ addTrackRepostRequest,
271
+ deleteTrackRepostRequest,
272
+ addPlaylistRepostRequest,
273
+ deletePlaylistRepostRequest,
274
+ userFollowRequest,
275
+ deleteUserFollowRequest,
276
+ createPlaylistRequest,
277
+ deletePlaylistRequest,
278
+ addPlaylistTrackRequest,
279
+ deletePlaylistTrackRequest,
280
+ orderPlaylistTracksRequest,
281
+ updatePlaylistPrivacyRequest,
282
+ updatePlaylistNameRequest,
283
+ updatePlaylistCoverPhotoRequest,
284
+ updatePlaylistDescriptionRequest,
285
+ updatePlaylistUPCRequest,
286
+ trackSaveRequest,
287
+ deleteTrackSaveRequest,
288
+ playlistSaveRequest,
289
+ deletePlaylistSaveRequest,
290
+ addIPLDBlacklist,
291
+ proposeAddOrUpdateContentNode,
292
+ updateReplicaSet
293
+ }
294
+
295
+ type MessageSchema = readonly EIP712TypeProperty[]
296
+
297
+ function getRequestData(
298
+ domainDataFn: DomainFn,
299
+ chainId: number,
300
+ contractAddress: string,
301
+ messageTypeName: string,
302
+ messageSchema: MessageSchema,
303
+ message: EIP712Message
304
+ ): EIP712TypedData {
305
+ const domainData = domainDataFn(chainId, contractAddress)
306
+ const types: EIP712Types = {
307
+ EIP712Domain: schemas.domain
308
+ }
309
+ types[messageTypeName] = messageSchema
310
+ return {
311
+ types: types,
312
+ domain: domainData,
313
+ primaryType: messageTypeName,
314
+ message: message
315
+ }
316
+ }
317
+
318
+ /* User Factory Generators */
319
+ const getAddUserRequestData = (
320
+ chainId: number,
321
+ contractAddress: string,
322
+ handle: string,
323
+ nonce: string
324
+ ) => {
325
+ const message = {
326
+ handle: handle,
327
+ nonce: nonce
328
+ }
329
+ return getRequestData(
330
+ domains.getUserFactoryDomain,
331
+ chainId,
332
+ contractAddress,
333
+ 'AddUserRequest',
334
+ schemas.addUserRequest,
335
+ message
336
+ )
337
+ }
338
+
339
+ function _getUpdateUserRequestData(
340
+ chainId: number,
341
+ contractAddress: string,
342
+ messageTypeName: string,
343
+ schema: MessageSchema,
344
+ userId: number,
345
+ newValue: unknown,
346
+ nonce: string
347
+ ) {
348
+ const message = {
349
+ userId: userId,
350
+ newValue: newValue,
351
+ nonce: nonce
352
+ }
353
+ return getRequestData(
354
+ domains.getUserFactoryDomain,
355
+ chainId,
356
+ contractAddress,
357
+ messageTypeName,
358
+ schema,
359
+ message
360
+ )
361
+ }
362
+
363
+ export type UserUpdateRequestFn = (
364
+ chainId: number,
365
+ contactAddress: string,
366
+ userId: number,
367
+ newValue: unknown,
368
+ nonce: string
369
+ ) => EIP712TypedData
370
+
371
+ const getUpdateUserMultihashRequestData: UserUpdateRequestFn = (
372
+ chainId,
373
+ contractAddress,
374
+ userId,
375
+ newValue,
376
+ nonce
377
+ ) => {
378
+ return _getUpdateUserRequestData(
379
+ chainId,
380
+ contractAddress,
381
+ 'UpdateUserMultihashRequest',
382
+ schemas.updateUserBytes32,
383
+ userId,
384
+ newValue,
385
+ nonce
386
+ )
387
+ }
388
+
389
+ const getUpdateUserNameRequestData: UserUpdateRequestFn = (
390
+ chainId,
391
+ contractAddress,
392
+ userId,
393
+ newValue,
394
+ nonce
395
+ ) => {
396
+ return _getUpdateUserRequestData(
397
+ chainId,
398
+ contractAddress,
399
+ 'UpdateUserNameRequest',
400
+ schemas.updateUserBytes32,
401
+ userId,
402
+ newValue,
403
+ nonce
404
+ )
405
+ }
406
+
407
+ const getUpdateUserLocationRequestData: UserUpdateRequestFn = (
408
+ chainId,
409
+ contractAddress,
410
+ userId,
411
+ newValue,
412
+ nonce
413
+ ) => {
414
+ return _getUpdateUserRequestData(
415
+ chainId,
416
+ contractAddress,
417
+ 'UpdateUserLocationRequest',
418
+ schemas.updateUserBytes32,
419
+ userId,
420
+ newValue,
421
+ nonce
422
+ )
423
+ }
424
+
425
+ const getUpdateUserProfilePhotoRequestData: UserUpdateRequestFn = (
426
+ chainId,
427
+ contractAddress,
428
+ userId,
429
+ newValue,
430
+ nonce
431
+ ) => {
432
+ return _getUpdateUserRequestData(
433
+ chainId,
434
+ contractAddress,
435
+ 'UpdateUserProfilePhotoRequest',
436
+ schemas.updateUserBytes32,
437
+ userId,
438
+ newValue,
439
+ nonce
440
+ )
441
+ }
442
+
443
+ const getUpdateUserCoverPhotoRequestData: UserUpdateRequestFn = (
444
+ chainId,
445
+ contractAddress,
446
+ userId,
447
+ newValue,
448
+ nonce
449
+ ) => {
450
+ return _getUpdateUserRequestData(
451
+ chainId,
452
+ contractAddress,
453
+ 'UpdateUserCoverPhotoRequest',
454
+ schemas.updateUserBytes32,
455
+ userId,
456
+ newValue,
457
+ nonce
458
+ )
459
+ }
460
+
461
+ const getUpdateUserBioRequestData: UserUpdateRequestFn = (
462
+ chainId,
463
+ contractAddress,
464
+ userId,
465
+ newValue,
466
+ nonce
467
+ ) => {
468
+ return _getUpdateUserRequestData(
469
+ chainId,
470
+ contractAddress,
471
+ 'UpdateUserBioRequest',
472
+ schemas.updateUserString,
473
+ userId,
474
+ newValue,
475
+ nonce
476
+ )
477
+ }
478
+
479
+ const getUpdateUserCreatorNodeRequestData: UserUpdateRequestFn = (
480
+ chainId,
481
+ contractAddress,
482
+ userId,
483
+ newValue,
484
+ nonce
485
+ ) => {
486
+ return _getUpdateUserRequestData(
487
+ chainId,
488
+ contractAddress,
489
+ 'UpdateUserCreatorNodeRequest',
490
+ schemas.updateUserString,
491
+ userId,
492
+ newValue,
493
+ nonce
494
+ )
495
+ }
496
+
497
+ const getUpdateUserCreatorRequestData: UserUpdateRequestFn = (
498
+ chainId,
499
+ contractAddress,
500
+ userId,
501
+ newValue,
502
+ nonce
503
+ ) => {
504
+ return _getUpdateUserRequestData(
505
+ chainId,
506
+ contractAddress,
507
+ 'UpdateUserCreatorRequest',
508
+ schemas.updateUserBool,
509
+ userId,
510
+ newValue,
511
+ nonce
512
+ )
513
+ }
514
+
515
+ const getUpdateUserVerifiedRequestData: UserUpdateRequestFn = (
516
+ chainId,
517
+ contractAddress,
518
+ userId,
519
+ newValue,
520
+ nonce
521
+ ) => {
522
+ return _getUpdateUserRequestData(
523
+ chainId,
524
+ contractAddress,
525
+ 'UpdateUserVerifiedRequest',
526
+ schemas.updateUserBool,
527
+ userId,
528
+ newValue,
529
+ nonce
530
+ )
531
+ }
532
+
533
+ /* Track Factory Generators */
534
+ const getAddTrackRequestData = (
535
+ chainId: number,
536
+ contractAddress: string,
537
+ trackOwnerId: number,
538
+ multihashDigest: string,
539
+ multihashHashFn: number,
540
+ multihashSize: number,
541
+ nonce: string
542
+ ) => {
543
+ const message = {
544
+ trackOwnerId: trackOwnerId,
545
+ multihashDigest: multihashDigest,
546
+ multihashHashFn: multihashHashFn,
547
+ multihashSize: multihashSize,
548
+ nonce: nonce
549
+ }
550
+ return getRequestData(
551
+ domains.getTrackFactoryDomain,
552
+ chainId,
553
+ contractAddress,
554
+ 'AddTrackRequest',
555
+ schemas.addTrackRequest,
556
+ message
557
+ )
558
+ }
559
+
560
+ const getUpdateTrackRequestData = (
561
+ chainId: number,
562
+ contractAddress: string,
563
+ trackId: number,
564
+ trackOwnerId: number,
565
+ multihashDigest: string,
566
+ multihashHashFn: number,
567
+ multihashSize: number,
568
+ nonce: string
569
+ ) => {
570
+ const message = {
571
+ trackId: trackId,
572
+ trackOwnerId: trackOwnerId,
573
+ multihashDigest: multihashDigest,
574
+ multihashHashFn: multihashHashFn,
575
+ multihashSize: multihashSize,
576
+ nonce: nonce
577
+ }
578
+ return getRequestData(
579
+ domains.getTrackFactoryDomain,
580
+ chainId,
581
+ contractAddress,
582
+ 'UpdateTrackRequest',
583
+ schemas.updateTrackRequest,
584
+ message
585
+ )
586
+ }
587
+
588
+ const getDeleteTrackRequestData = (
589
+ chainId: number,
590
+ contractAddress: string,
591
+ trackId: number,
592
+ nonce: string
593
+ ) => {
594
+ const message = {
595
+ trackId: trackId,
596
+ nonce: nonce
597
+ }
598
+ return getRequestData(
599
+ domains.getTrackFactoryDomain,
600
+ chainId,
601
+ contractAddress,
602
+ 'DeleteTrackRequest',
603
+ schemas.deleteTrackRequest,
604
+ message
605
+ )
606
+ }
607
+
608
+ /* Social Feature Factory Generators */
609
+ const getAddTrackRepostRequestData = (
610
+ chainId: number,
611
+ contractAddress: string,
612
+ userId: number,
613
+ trackId: number,
614
+ nonce: string
615
+ ) => {
616
+ const message = {
617
+ userId: userId,
618
+ trackId: trackId,
619
+ nonce: nonce
620
+ }
621
+ return getRequestData(
622
+ domains.getSocialFeatureFactoryDomain,
623
+ chainId,
624
+ contractAddress,
625
+ 'AddTrackRepostRequest',
626
+ schemas.addTrackRepostRequest,
627
+ message
628
+ )
629
+ }
630
+
631
+ const getDeleteTrackRepostRequestData = (
632
+ chainId: number,
633
+ contractAddress: string,
634
+ userId: number,
635
+ trackId: number,
636
+ nonce: string
637
+ ) => {
638
+ const message = {
639
+ userId: userId,
640
+ trackId: trackId,
641
+ nonce: nonce
642
+ }
643
+ return getRequestData(
644
+ domains.getSocialFeatureFactoryDomain,
645
+ chainId,
646
+ contractAddress,
647
+ 'DeleteTrackRepostRequest',
648
+ schemas.deleteTrackRepostRequest,
649
+ message
650
+ )
651
+ }
652
+
653
+ const getAddPlaylistRepostRequestData = (
654
+ chainId: number,
655
+ contractAddress: string,
656
+ userId: number,
657
+ playlistId: number,
658
+ nonce: string
659
+ ) => {
660
+ const message = {
661
+ userId: userId,
662
+ playlistId: playlistId,
663
+ nonce: nonce
664
+ }
665
+ return getRequestData(
666
+ domains.getSocialFeatureFactoryDomain,
667
+ chainId,
668
+ contractAddress,
669
+ 'AddPlaylistRepostRequest',
670
+ schemas.addPlaylistRepostRequest,
671
+ message
672
+ )
673
+ }
674
+
675
+ const getDeletePlaylistRepostRequestData = (
676
+ chainId: number,
677
+ contractAddress: string,
678
+ userId: number,
679
+ playlistId: number,
680
+ nonce: string
681
+ ) => {
682
+ const message = {
683
+ userId: userId,
684
+ playlistId: playlistId,
685
+ nonce: nonce
686
+ }
687
+ return getRequestData(
688
+ domains.getSocialFeatureFactoryDomain,
689
+ chainId,
690
+ contractAddress,
691
+ 'DeletePlaylistRepostRequest',
692
+ schemas.deletePlaylistRepostRequest,
693
+ message
694
+ )
695
+ }
696
+
697
+ const getUserFollowRequestData = (
698
+ chainId: number,
699
+ contractAddress: string,
700
+ followerUserId: number,
701
+ followeeUserId: number,
702
+ nonce: string
703
+ ) => {
704
+ const message = {
705
+ followerUserId: followerUserId,
706
+ followeeUserId: followeeUserId,
707
+ nonce: nonce
708
+ }
709
+ return getRequestData(
710
+ domains.getSocialFeatureFactoryDomain,
711
+ chainId,
712
+ contractAddress,
713
+ 'UserFollowRequest',
714
+ schemas.userFollowRequest,
715
+ message
716
+ )
717
+ }
718
+
719
+ const getDeleteUserFollowRequestData = (
720
+ chainId: number,
721
+ contractAddress: string,
722
+ followerUserId: number,
723
+ followeeUserId: number,
724
+ nonce: string
725
+ ) => {
726
+ const message = {
727
+ followerUserId: followerUserId,
728
+ followeeUserId: followeeUserId,
729
+ nonce: nonce
730
+ }
731
+ return getRequestData(
732
+ domains.getSocialFeatureFactoryDomain,
733
+ chainId,
734
+ contractAddress,
735
+ 'DeleteUserFollowRequest',
736
+ schemas.deleteUserFollowRequest,
737
+ message
738
+ )
739
+ }
740
+
741
+ const getTrackSaveRequestData = (
742
+ chainId: number,
743
+ contractAddress: string,
744
+ userId: number,
745
+ trackId: number,
746
+ nonce: string
747
+ ) => {
748
+ const message = {
749
+ userId: userId,
750
+ trackId: trackId,
751
+ nonce: nonce
752
+ }
753
+
754
+ return getRequestData(
755
+ domains.getUserLibraryFactoryDomain,
756
+ chainId,
757
+ contractAddress,
758
+ 'TrackSaveRequest',
759
+ schemas.trackSaveRequest,
760
+ message
761
+ )
762
+ }
763
+
764
+ const getDeleteTrackSaveRequestData = (
765
+ chainId: number,
766
+ contractAddress: string,
767
+ userId: number,
768
+ trackId: number,
769
+ nonce: string
770
+ ) => {
771
+ const message = {
772
+ userId: userId,
773
+ trackId: trackId,
774
+ nonce: nonce
775
+ }
776
+
777
+ return getRequestData(
778
+ domains.getUserLibraryFactoryDomain,
779
+ chainId,
780
+ contractAddress,
781
+ 'DeleteTrackSaveRequest',
782
+ schemas.deleteTrackSaveRequest,
783
+ message
784
+ )
785
+ }
786
+
787
+ const getPlaylistSaveRequestData = (
788
+ chainId: number,
789
+ contractAddress: string,
790
+ userId: number,
791
+ playlistId: number,
792
+ nonce: string
793
+ ) => {
794
+ const message = {
795
+ userId: userId,
796
+ playlistId: playlistId,
797
+ nonce: nonce
798
+ }
799
+
800
+ return getRequestData(
801
+ domains.getUserLibraryFactoryDomain,
802
+ chainId,
803
+ contractAddress,
804
+ 'PlaylistSaveRequest',
805
+ schemas.playlistSaveRequest,
806
+ message
807
+ )
808
+ }
809
+
810
+ const getDeletePlaylistSaveRequestData = (
811
+ chainId: number,
812
+ contractAddress: string,
813
+ userId: number,
814
+ playlistId: number,
815
+ nonce: string
816
+ ) => {
817
+ const message = {
818
+ userId: userId,
819
+ playlistId: playlistId,
820
+ nonce: nonce
821
+ }
822
+
823
+ return getRequestData(
824
+ domains.getUserLibraryFactoryDomain,
825
+ chainId,
826
+ contractAddress,
827
+ 'DeletePlaylistSaveRequest',
828
+ schemas.deletePlaylistSaveRequest,
829
+ message
830
+ )
831
+ }
832
+
833
+ /* Playlist Factory Generators */
834
+
835
+ /* NOTE: Ensure the value for trackIds hash is generated using the following snippet prior to calling this generator function:
836
+ * web3New.utils.soliditySha3(web3New.eth.abi.encodeParameter('uint[]', trackIds))
837
+ */
838
+ const getCreatePlaylistRequestData = (
839
+ chainId: number,
840
+ contractAddress: string,
841
+ playlistOwnerId: number,
842
+ playlistName: string,
843
+ isPrivate: boolean,
844
+ isAlbum: boolean,
845
+ trackIdsHash: string | null,
846
+ nonce: string
847
+ ) => {
848
+ const message = {
849
+ playlistOwnerId: playlistOwnerId,
850
+ playlistName: playlistName,
851
+ isPrivate: isPrivate,
852
+ isAlbum: isAlbum,
853
+ trackIdsHash: trackIdsHash,
854
+ nonce: nonce
855
+ }
856
+
857
+ return getRequestData(
858
+ domains.getPlaylistFactoryDomain,
859
+ chainId,
860
+ contractAddress,
861
+ 'CreatePlaylistRequest',
862
+ schemas.createPlaylistRequest,
863
+ message
864
+ )
865
+ }
866
+
867
+ const getDeletePlaylistRequestData = (
868
+ chainId: number,
869
+ contractAddress: string,
870
+ playlistId: number,
871
+ nonce: string
872
+ ) => {
873
+ const message = {
874
+ playlistId: playlistId,
875
+ nonce: nonce
876
+ }
877
+ return getRequestData(
878
+ domains.getPlaylistFactoryDomain,
879
+ chainId,
880
+ contractAddress,
881
+ 'DeletePlaylistRequest',
882
+ schemas.deletePlaylistRequest,
883
+ message
884
+ )
885
+ }
886
+
887
+ const getAddPlaylistTrackRequestData = (
888
+ chainId: number,
889
+ contractAddress: string,
890
+ playlistId: number,
891
+ addedTrackId: number,
892
+ nonce: string
893
+ ) => {
894
+ const message = {
895
+ playlistId: playlistId,
896
+ addedTrackId: addedTrackId,
897
+ nonce: nonce
898
+ }
899
+
900
+ return getRequestData(
901
+ domains.getPlaylistFactoryDomain,
902
+ chainId,
903
+ contractAddress,
904
+ 'AddPlaylistTrackRequest',
905
+ schemas.addPlaylistTrackRequest,
906
+ message
907
+ )
908
+ }
909
+
910
+ const getDeletePlaylistTrackRequestData = (
911
+ chainId: number,
912
+ contractAddress: string,
913
+ playlistId: number,
914
+ deletedTrackId: number,
915
+ deletedTrackTimestamp: number,
916
+ nonce: string
917
+ ) => {
918
+ const message = {
919
+ playlistId: playlistId,
920
+ deletedTrackId: deletedTrackId,
921
+ deletedTrackTimestamp: deletedTrackTimestamp,
922
+ nonce: nonce
923
+ }
924
+
925
+ return getRequestData(
926
+ domains.getPlaylistFactoryDomain,
927
+ chainId,
928
+ contractAddress,
929
+ 'DeletePlaylistTrackRequest',
930
+ schemas.deletePlaylistTrackRequest,
931
+ message
932
+ )
933
+ }
934
+
935
+ const getOrderPlaylistTracksRequestData = (
936
+ chainId: number,
937
+ contractAddress: string,
938
+ playlistId: number,
939
+ trackIdsHash: string | null,
940
+ nonce: string
941
+ ) => {
942
+ const message = {
943
+ playlistId: playlistId,
944
+ trackIdsHash: trackIdsHash,
945
+ nonce: nonce
946
+ }
947
+
948
+ return getRequestData(
949
+ domains.getPlaylistFactoryDomain,
950
+ chainId,
951
+ contractAddress,
952
+ 'OrderPlaylistTracksRequest',
953
+ schemas.orderPlaylistTracksRequest,
954
+ message
955
+ )
956
+ }
957
+
958
+ const getUpdatePlaylistNameRequestData = (
959
+ chainId: number,
960
+ contractAddress: string,
961
+ playlistId: number,
962
+ updatedPlaylistName: string,
963
+ nonce: string
964
+ ) => {
965
+ const message = {
966
+ playlistId: playlistId,
967
+ updatedPlaylistName: updatedPlaylistName,
968
+ nonce: nonce
969
+ }
970
+
971
+ return getRequestData(
972
+ domains.getPlaylistFactoryDomain,
973
+ chainId,
974
+ contractAddress,
975
+ 'UpdatePlaylistNameRequest',
976
+ schemas.updatePlaylistNameRequest,
977
+ message
978
+ )
979
+ }
980
+
981
+ const getUpdatePlaylistPrivacyRequestData = (
982
+ chainId: number,
983
+ contractAddress: string,
984
+ playlistId: number,
985
+ updatedPlaylistPrivacy: string,
986
+ nonce: string
987
+ ) => {
988
+ const message = {
989
+ playlistId: playlistId,
990
+ updatedPlaylistPrivacy: updatedPlaylistPrivacy,
991
+ nonce: nonce
992
+ }
993
+
994
+ return getRequestData(
995
+ domains.getPlaylistFactoryDomain,
996
+ chainId,
997
+ contractAddress,
998
+ 'UpdatePlaylistPrivacyRequest',
999
+ schemas.updatePlaylistPrivacyRequest,
1000
+ message
1001
+ )
1002
+ }
1003
+
1004
+ const getUpdatePlaylistCoverPhotoRequestData = (
1005
+ chainId: number,
1006
+ contractAddress: string,
1007
+ playlistId: number,
1008
+ playlistImageMultihashDigest: string,
1009
+ nonce: string
1010
+ ) => {
1011
+ const message = {
1012
+ playlistId: playlistId,
1013
+ playlistImageMultihashDigest: playlistImageMultihashDigest,
1014
+ nonce: nonce
1015
+ }
1016
+
1017
+ return getRequestData(
1018
+ domains.getPlaylistFactoryDomain,
1019
+ chainId,
1020
+ contractAddress,
1021
+ 'UpdatePlaylistCoverPhotoRequest',
1022
+ schemas.updatePlaylistCoverPhotoRequest,
1023
+ message
1024
+ )
1025
+ }
1026
+
1027
+ const getUpdatePlaylistUPCRequestData = (
1028
+ chainId: number,
1029
+ contractAddress: string,
1030
+ playlistId: number,
1031
+ playlistUPC: string,
1032
+ nonce: string
1033
+ ) => {
1034
+ const message = {
1035
+ playlistId: playlistId,
1036
+ playlistUPC: playlistUPC,
1037
+ nonce: nonce
1038
+ }
1039
+
1040
+ return getRequestData(
1041
+ domains.getPlaylistFactoryDomain,
1042
+ chainId,
1043
+ contractAddress,
1044
+ 'UpdatePlaylistUPCRequest',
1045
+ schemas.updatePlaylistUPCRequest,
1046
+ message
1047
+ )
1048
+ }
1049
+
1050
+ const getUpdatePlaylistDescriptionRequestData = (
1051
+ chainId: number,
1052
+ contractAddress: string,
1053
+ playlistId: number,
1054
+ playlistDescription: string,
1055
+ nonce: string
1056
+ ) => {
1057
+ const message = {
1058
+ playlistId: playlistId,
1059
+ playlistDescription: playlistDescription,
1060
+ nonce: nonce
1061
+ }
1062
+
1063
+ return getRequestData(
1064
+ domains.getPlaylistFactoryDomain,
1065
+ chainId,
1066
+ contractAddress,
1067
+ 'UpdatePlaylistDescriptionRequest',
1068
+ schemas.updatePlaylistDescriptionRequest,
1069
+ message
1070
+ )
1071
+ }
1072
+
1073
+ const addIPLDToBlacklistRequestData = (
1074
+ chainId: number,
1075
+ contractAddress: string,
1076
+ multihashDigest: string,
1077
+ nonce: string
1078
+ ) => {
1079
+ const message = {
1080
+ multihashDigest: multihashDigest,
1081
+ nonce: nonce
1082
+ }
1083
+ return getRequestData(
1084
+ domains.getIPLDBlacklistFactoryDomain,
1085
+ chainId,
1086
+ contractAddress,
1087
+ 'AddIPLDToBlacklistRequest',
1088
+ schemas.addIPLDBlacklist,
1089
+ message
1090
+ )
1091
+ }
1092
+
1093
+ /* User Replica Set Manager Generators */
1094
+ const getProposeAddOrUpdateContentNodeRequestData = (
1095
+ chainId: number,
1096
+ contractAddress: string,
1097
+ cnodeSpId: number,
1098
+ cnodeDelegateOwnerWallet: string,
1099
+ cnodeOwnerWallet: string,
1100
+ proposerSpId: number,
1101
+ nonce: string
1102
+ ) => {
1103
+ const message = {
1104
+ cnodeSpId,
1105
+ cnodeDelegateOwnerWallet,
1106
+ cnodeOwnerWallet,
1107
+ proposerSpId,
1108
+ nonce
1109
+ }
1110
+ return getRequestData(
1111
+ domains.getUserReplicaSetManagerDomain,
1112
+ chainId,
1113
+ contractAddress,
1114
+ 'ProposeAddOrUpdateContentNode',
1115
+ schemas.proposeAddOrUpdateContentNode,
1116
+ message
1117
+ )
1118
+ }
1119
+
1120
+ const getUpdateReplicaSetRequestData = (
1121
+ chainId: number,
1122
+ contractAddress: string,
1123
+ userId: number,
1124
+ primaryId: number,
1125
+ secondaryIdsHash: string | null,
1126
+ oldPrimaryId: number,
1127
+ oldSecondaryIdsHash: string | null,
1128
+ nonce: string
1129
+ ) => {
1130
+ const message = {
1131
+ userId,
1132
+ primaryId,
1133
+ secondaryIdsHash,
1134
+ oldPrimaryId,
1135
+ oldSecondaryIdsHash,
1136
+ nonce
1137
+ }
1138
+ return getRequestData(
1139
+ domains.getUserReplicaSetManagerDomain,
1140
+ chainId,
1141
+ contractAddress,
1142
+ 'UpdateReplicaSet',
1143
+ schemas.updateReplicaSet,
1144
+ message
1145
+ )
1146
+ }
1147
+
1148
+ export const generators = {
1149
+ getUpdateUserMultihashRequestData,
1150
+ getAddUserRequestData,
1151
+ getUpdateUserNameRequestData,
1152
+ getUpdateUserLocationRequestData,
1153
+ getUpdateUserProfilePhotoRequestData,
1154
+ getUpdateUserCoverPhotoRequestData,
1155
+ getUpdateUserBioRequestData,
1156
+ getUpdateUserCreatorNodeRequestData,
1157
+ getUpdateUserCreatorRequestData,
1158
+ getUpdateUserVerifiedRequestData,
1159
+ getAddTrackRequestData,
1160
+ getUpdateTrackRequestData,
1161
+ getDeleteTrackRequestData,
1162
+ getAddTrackRepostRequestData,
1163
+ getDeleteTrackRepostRequestData,
1164
+ getAddPlaylistRepostRequestData,
1165
+ getDeletePlaylistRepostRequestData,
1166
+ getUserFollowRequestData,
1167
+ getDeleteUserFollowRequestData,
1168
+ getTrackSaveRequestData,
1169
+ getDeleteTrackSaveRequestData,
1170
+ getPlaylistSaveRequestData,
1171
+ getDeletePlaylistSaveRequestData,
1172
+ getCreatePlaylistRequestData,
1173
+ getDeletePlaylistRequestData,
1174
+ getAddPlaylistTrackRequestData,
1175
+ getDeletePlaylistTrackRequestData,
1176
+ getOrderPlaylistTracksRequestData,
1177
+ getUpdatePlaylistNameRequestData,
1178
+ getUpdatePlaylistPrivacyRequestData,
1179
+ getUpdatePlaylistCoverPhotoRequestData,
1180
+ getUpdatePlaylistUPCRequestData,
1181
+ getUpdatePlaylistDescriptionRequestData,
1182
+ addIPLDToBlacklistRequestData,
1183
+ getProposeAddOrUpdateContentNodeRequestData,
1184
+ getUpdateReplicaSetRequestData
1185
+ }
1186
+
1187
+ type NodeCrypto = { randomBytes: (size: number) => Buffer }
1188
+
1189
+ /** Return a secure random hex string of nChar length in a browser-compatible way
1190
+ * Taken from https://stackoverflow.com/questions/37378237/how-to-generate-a-random-token-of-32-bit-in-javascript
1191
+ */
1192
+ function browserRandomHash(nChar: number) {
1193
+ // convert number of characters to number of bytes
1194
+ const nBytes = Math.ceil((nChar = (+nChar || 8) / 2))
1195
+
1196
+ // create a typed array of that many bytes
1197
+ const u = new Uint8Array(nBytes)
1198
+
1199
+ // populate it wit crypto-random values
1200
+ window.crypto.getRandomValues(u)
1201
+
1202
+ // convert it to an Array of Strings (e.g. '01', 'AF', ..)
1203
+ const zpad = function (str: string) {
1204
+ return '00'.slice(str.length) + str
1205
+ }
1206
+ const a = Array.prototype.map.call(u, function (x) {
1207
+ return zpad(x.toString(16))
1208
+ })
1209
+
1210
+ // Array of String to String
1211
+ let str = a.join('').toLowerCase()
1212
+ // and snip off the excess digit if we want an odd number
1213
+ if (nChar % 2) str = str.slice(1)
1214
+
1215
+ // return what we made
1216
+ return str
1217
+ }
1218
+
1219
+ // We need to detect whether the nodejs crypto module is available to determine how to
1220
+ // generate secure random numbers below
1221
+ let nodeCrypto: NodeCrypto | null
1222
+
1223
+ try {
1224
+ nodeCrypto = require('crypto')
1225
+ } catch (e) {
1226
+ nodeCrypto = null
1227
+ }
1228
+
1229
+ export function getNonce() {
1230
+ // detect whether we are in browser or in nodejs, and use the correct csprng
1231
+ if (typeof window === 'undefined' || window === null) {
1232
+ return '0x' + (nodeCrypto as NodeCrypto).randomBytes(32).toString('hex')
1233
+ } else {
1234
+ return '0x' + browserRandomHash(64)
1235
+ }
1236
+ }