@audius/sdk 3.0.8-beta.4 → 3.0.8-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nvmrc +1 -1
- package/dist/AudiusLibs.d.ts +3 -1
- package/dist/index.cjs.js +348 -248
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +348 -248
- package/dist/index.esm.js.map +1 -1
- package/dist/legacy.js +348 -248
- package/dist/legacy.js.map +1 -1
- package/dist/native-libs.js +313 -230
- package/dist/native-libs.js.map +1 -1
- package/dist/sdk/api/albums/types.d.ts +36 -36
- package/dist/sdk/api/playlists/types.d.ts +82 -82
- package/dist/sdk/api/tracks/TrackUploadHelper.d.ts +6 -6
- package/dist/services/discoveryProvider/DiscoveryProvider.d.ts +14 -0
- package/dist/services/web3Manager/Web3Manager.d.ts +5 -1
- package/dist/web-libs.js +313 -230
- package/dist/web-libs.js.map +1 -1
- package/package.json +2 -2
- package/src/AudiusLibs.ts +15 -1
- package/src/services/discoveryProvider/DiscoveryProvider.ts +21 -0
- package/src/services/web3Manager/Web3Manager.ts +41 -11
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@audius/sdk",
|
|
3
|
-
"version": "3.0.8-beta.
|
|
3
|
+
"version": "3.0.8-beta.6",
|
|
4
4
|
"audius": {
|
|
5
|
-
"releaseSHA": "
|
|
5
|
+
"releaseSHA": "ea2ae182bca1fca4f27f02f9fa991789e42fe6cf"
|
|
6
6
|
},
|
|
7
7
|
"description": "Audius SDK",
|
|
8
8
|
"keywords": [
|
package/src/AudiusLibs.ts
CHANGED
|
@@ -86,6 +86,7 @@ type AudiusLibsConfig = {
|
|
|
86
86
|
preferHigherPatchForPrimary: boolean
|
|
87
87
|
preferHigherPatchForSecondaries: boolean
|
|
88
88
|
localStorage: LocalStorage
|
|
89
|
+
useDiscoveryRelay: boolean
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
export class AudiusLibs {
|
|
@@ -332,6 +333,7 @@ export class AudiusLibs {
|
|
|
332
333
|
preferHigherPatchForPrimary: boolean
|
|
333
334
|
preferHigherPatchForSecondaries: boolean
|
|
334
335
|
localStorage: LocalStorage
|
|
336
|
+
useDiscoveryRelay: boolean
|
|
335
337
|
|
|
336
338
|
/**
|
|
337
339
|
* Constructs an Audius Libs instance with configs.
|
|
@@ -358,7 +360,8 @@ export class AudiusLibs {
|
|
|
358
360
|
isDebug = false,
|
|
359
361
|
preferHigherPatchForPrimary = true,
|
|
360
362
|
preferHigherPatchForSecondaries = true,
|
|
361
|
-
localStorage = getPlatformLocalStorage()
|
|
363
|
+
localStorage = getPlatformLocalStorage(),
|
|
364
|
+
useDiscoveryRelay = false,
|
|
362
365
|
}: AudiusLibsConfig) {
|
|
363
366
|
// set version
|
|
364
367
|
|
|
@@ -409,6 +412,7 @@ export class AudiusLibs {
|
|
|
409
412
|
this.preferHigherPatchForPrimary = preferHigherPatchForPrimary
|
|
410
413
|
this.preferHigherPatchForSecondaries = preferHigherPatchForSecondaries
|
|
411
414
|
this.localStorage = localStorage
|
|
415
|
+
this.useDiscoveryRelay = useDiscoveryRelay
|
|
412
416
|
|
|
413
417
|
// Schemas
|
|
414
418
|
const schemaValidator = new SchemaValidator()
|
|
@@ -536,6 +540,16 @@ export class AudiusLibs {
|
|
|
536
540
|
...this.discoveryProviderConfig
|
|
537
541
|
})
|
|
538
542
|
await this.discoveryProvider.init()
|
|
543
|
+
|
|
544
|
+
// set discovery provider in web3 for relay
|
|
545
|
+
if (this.web3Config && this.useDiscoveryRelay) {
|
|
546
|
+
const web3Manager = this.web3Manager
|
|
547
|
+
if (web3Manager === undefined || web3Manager === null) {
|
|
548
|
+
console.warn("useDiscoveryRelay is set to true but web3Manager is not configured")
|
|
549
|
+
} else {
|
|
550
|
+
this.web3Manager?.setDiscoveryProvider(this.discoveryProvider)
|
|
551
|
+
}
|
|
552
|
+
}
|
|
539
553
|
}
|
|
540
554
|
|
|
541
555
|
/** Creator Node */
|
|
@@ -22,6 +22,7 @@ import type { EthContracts } from '../ethContracts'
|
|
|
22
22
|
import type { Web3Manager } from '../web3Manager'
|
|
23
23
|
import { DiscoveryNodeSelector, FetchError, Middleware } from '../../sdk'
|
|
24
24
|
import fetch from 'cross-fetch'
|
|
25
|
+
import type { TransactionReceipt } from 'web3-core'
|
|
25
26
|
|
|
26
27
|
const MAX_MAKE_REQUEST_RETRY_COUNT = 5
|
|
27
28
|
const MAX_MAKE_REQUEST_RETRIES_WITH_404 = 2
|
|
@@ -93,6 +94,17 @@ type DiscoveryNodeChallenge = {
|
|
|
93
94
|
completed_blocknumber: number
|
|
94
95
|
}
|
|
95
96
|
|
|
97
|
+
export type DiscoveryRelayBody = {
|
|
98
|
+
contractRegistryKey?: string | null;
|
|
99
|
+
contractAddress?: string | null;
|
|
100
|
+
senderAddress?: string | null;
|
|
101
|
+
encodedABI?: string | null;
|
|
102
|
+
gasLimit?: number | null;
|
|
103
|
+
handle?: string | null;
|
|
104
|
+
nethermindContractAddress?: string | null;
|
|
105
|
+
nethermindEncodedAbi?: string | null;
|
|
106
|
+
}
|
|
107
|
+
|
|
96
108
|
/**
|
|
97
109
|
* Constructs a service class for a discovery node
|
|
98
110
|
* @param whitelist whether or not to only include specified nodes in selection
|
|
@@ -1068,6 +1080,15 @@ export class DiscoveryProvider {
|
|
|
1068
1080
|
)
|
|
1069
1081
|
}
|
|
1070
1082
|
|
|
1083
|
+
async relay(data: DiscoveryRelayBody): Promise<{ receipt: TransactionReceipt } | null | undefined> {
|
|
1084
|
+
const req = {
|
|
1085
|
+
endpoint: 'relay',
|
|
1086
|
+
method: 'post',
|
|
1087
|
+
data
|
|
1088
|
+
}
|
|
1089
|
+
return await this._makeRequest(req, true, 0, true)
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1071
1092
|
/**
|
|
1072
1093
|
* Retrieves an unclaimed ID
|
|
1073
1094
|
* @return encoded ID
|
|
@@ -18,6 +18,7 @@ import type { HttpProvider, TransactionReceipt, EventLog } from 'web3-core'
|
|
|
18
18
|
import type { EIP712TypedData } from 'eth-sig-util'
|
|
19
19
|
import type { DecodedLog } from 'abi-decoder'
|
|
20
20
|
import type { AudiusLibs } from '../../AudiusLibs'
|
|
21
|
+
import type { DiscoveryProvider } from '../discoveryProvider'
|
|
21
22
|
|
|
22
23
|
const DEFAULT_GAS_LIMIT = 2000000
|
|
23
24
|
|
|
@@ -40,18 +41,21 @@ export class Web3Manager {
|
|
|
40
41
|
ownerWallet?: EthereumWallet
|
|
41
42
|
// Need to maintain the user's provided handle for anti-abuse measures on relay
|
|
42
43
|
userSuppliedHandle?: string
|
|
44
|
+
discoveryProvider: Nullable<DiscoveryProvider>
|
|
45
|
+
|
|
43
46
|
|
|
44
47
|
constructor({
|
|
45
48
|
web3Config,
|
|
46
49
|
identityService,
|
|
47
50
|
hedgehog,
|
|
48
|
-
isServer = false
|
|
51
|
+
isServer = false,
|
|
49
52
|
}: Web3ManagerConfig) {
|
|
50
53
|
this.web3Config = web3Config
|
|
51
54
|
this.isServer = isServer
|
|
52
55
|
|
|
53
56
|
// Unset if externalWeb3 = true
|
|
54
57
|
this.identityService = identityService
|
|
58
|
+
this.discoveryProvider = null
|
|
55
59
|
this.hedgehog = hedgehog
|
|
56
60
|
this.AudiusABIDecoder = AudiusABIDecoder
|
|
57
61
|
}
|
|
@@ -116,6 +120,14 @@ export class Web3Manager {
|
|
|
116
120
|
this.web3 = web3
|
|
117
121
|
}
|
|
118
122
|
|
|
123
|
+
setDiscoveryProvider(discoveryProvider: DiscoveryProvider) {
|
|
124
|
+
this.discoveryProvider = discoveryProvider
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
useDiscoveryRelay() {
|
|
128
|
+
return !(this.discoveryProvider === null)
|
|
129
|
+
}
|
|
130
|
+
|
|
119
131
|
getWalletAddress() {
|
|
120
132
|
if (this.useExternalWeb3) {
|
|
121
133
|
// Lowercase the owner wallet. Consider using the checksum address.
|
|
@@ -231,16 +243,34 @@ export class Web3Manager {
|
|
|
231
243
|
const response = await retry(
|
|
232
244
|
async (bail) => {
|
|
233
245
|
try {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
246
|
+
if (this.useDiscoveryRelay()) {
|
|
247
|
+
// use discovery relay
|
|
248
|
+
const res = await this.discoveryProvider?.relay({
|
|
249
|
+
contractRegistryKey,
|
|
250
|
+
contractAddress,
|
|
251
|
+
senderAddress: this.ownerWallet!.getAddressString(),
|
|
252
|
+
encodedABI,
|
|
253
|
+
gasLimit,
|
|
254
|
+
handle: this.userSuppliedHandle,
|
|
255
|
+
nethermindContractAddress,
|
|
256
|
+
nethermindEncodedAbi
|
|
257
|
+
})
|
|
258
|
+
if (res === null || res === undefined) {
|
|
259
|
+
throw new Error("discovery relay returned empty response")
|
|
260
|
+
}
|
|
261
|
+
return res
|
|
262
|
+
} else {
|
|
263
|
+
return await this.identityService?.relay(
|
|
264
|
+
contractRegistryKey,
|
|
265
|
+
contractAddress,
|
|
266
|
+
this.ownerWallet!.getAddressString(),
|
|
267
|
+
encodedABI,
|
|
268
|
+
gasLimit,
|
|
269
|
+
this.userSuppliedHandle,
|
|
270
|
+
nethermindContractAddress,
|
|
271
|
+
nethermindEncodedAbi
|
|
272
|
+
)
|
|
273
|
+
}
|
|
244
274
|
} catch (e: any) {
|
|
245
275
|
// If forbidden, don't retry
|
|
246
276
|
if (e.response.status === 403) {
|