@audius/sdk 0.0.0 → 0.0.3
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/dist/browser.js +91280 -0
- package/dist/browser.js.map +1 -0
- package/dist/core.js.map +1 -1
- package/dist/index.js +25724 -25115
- package/dist/index.js.map +1 -1
- package/dist/legacy.d.ts +2443 -0
- package/dist/legacy.js +73459 -0
- package/dist/legacy.js.map +1 -0
- package/dist/sdk.js +10 -0
- package/dist/sdk.js.map +1 -0
- package/dist/types.d.ts +2443 -0
- package/examples/initAudiusLibs.js +4 -4
- package/examples/initializeVersions.js +22 -9
- package/initScripts/mainnet.js +38 -14
- package/package.json +7 -2
- package/rollup.config.js +49 -0
- package/src/api/base.d.ts +4 -0
- package/src/api/reactions.ts +39 -0
- package/src/libs.js +18 -63
- package/src/sdk/oauth/Oauth.ts +3 -3
- package/src/sdk/sdk.ts +2 -2
- package/src/sdk/sdkBrowserDist.ts +3 -0
- package/src/services/discoveryProvider/DiscoveryProvider.ts +7 -4
- package/src/services/ethWeb3Manager/EthWeb3Manager.ts +7 -9
- package/src/services/identity/IdentityService.ts +19 -0
- package/src/services/solanaWeb3Manager/transfer.js +1 -1
- package/src/utils/utils.ts +1 -1
- package/tests/governanceTest.js +1 -1
- package/tests/helpers.js +1 -1
- package/tests/providerSelectionTest.js +3 -3
- package/tests/stakingTest.js +1 -1
|
@@ -43,9 +43,9 @@ async function initAudiusLibs(
|
|
|
43
43
|
ethWeb3ProviderEndpoint,
|
|
44
44
|
ethWallet
|
|
45
45
|
),
|
|
46
|
-
discoveryProviderConfig:
|
|
47
|
-
new Set(['http://docker.for.mac.localhost:5000'])
|
|
48
|
-
|
|
46
|
+
discoveryProviderConfig: {
|
|
47
|
+
whitelist: new Set(['http://docker.for.mac.localhost:5000'])
|
|
48
|
+
},
|
|
49
49
|
isServer,
|
|
50
50
|
isDebug
|
|
51
51
|
}
|
|
@@ -63,7 +63,7 @@ async function initAudiusLibs(
|
|
|
63
63
|
ethContractsConfig.ownerWallet
|
|
64
64
|
),
|
|
65
65
|
creatorNodeConfig: AudiusLibs.configCreatorNode(creatorNodeEndpoint),
|
|
66
|
-
discoveryProviderConfig:
|
|
66
|
+
discoveryProviderConfig: {},
|
|
67
67
|
identityServiceConfig: AudiusLibs.configIdentityService(
|
|
68
68
|
identityServiceEndpoint
|
|
69
69
|
),
|
|
@@ -2,7 +2,8 @@ const Web3 = require('../src/web3')
|
|
|
2
2
|
const AudiusLibs = require('../src/index')
|
|
3
3
|
const serviceTypeList = ['discovery-node', 'content-node']
|
|
4
4
|
const dataWeb3ProviderEndpoint = 'https://sokol.poa.network:443'
|
|
5
|
-
const ethWeb3ProviderEndpoint =
|
|
5
|
+
const ethWeb3ProviderEndpoint =
|
|
6
|
+
'https://ropsten.infura.io/v3/c569c6faf4f14d15a49d0044e7ddd668'
|
|
6
7
|
const dataRegistryAddress = '0x09033761774Fe45F40A47191DdF873F18B62DE05'
|
|
7
8
|
const ethRegistryAddress = '0xB631ABAA63a26311366411b2025F0cAca00DE27F'
|
|
8
9
|
const ethTokenAddress = '0xF8e679Aa54361467B12c7394BFF57Eb890f6d934'
|
|
@@ -10,7 +11,7 @@ let latestVersionStr = '0.1.0'
|
|
|
10
11
|
|
|
11
12
|
const isServer = true
|
|
12
13
|
|
|
13
|
-
const getEnv = env => {
|
|
14
|
+
const getEnv = (env) => {
|
|
14
15
|
const value = process.env[env]
|
|
15
16
|
if (typeof value === 'undefined') {
|
|
16
17
|
console.log(`${env} has not been set.`)
|
|
@@ -25,7 +26,7 @@ const getEnv = env => {
|
|
|
25
26
|
export AUDIUS_OWNER_WALLET=
|
|
26
27
|
* */
|
|
27
28
|
|
|
28
|
-
async function initializeVersionServiceProviderContracts
|
|
29
|
+
async function initializeVersionServiceProviderContracts() {
|
|
29
30
|
let audiusLibsConfig
|
|
30
31
|
let privateKey = getEnv('AUDIUS_PRIVATE_KEY')
|
|
31
32
|
let ownerWallet = getEnv('AUDIUS_OWNER_WALLET')
|
|
@@ -36,7 +37,9 @@ async function initializeVersionServiceProviderContracts () {
|
|
|
36
37
|
console.log(privateKey)
|
|
37
38
|
console.log(ownerWallet)
|
|
38
39
|
|
|
39
|
-
const dataWeb3 = new Web3(
|
|
40
|
+
const dataWeb3 = new Web3(
|
|
41
|
+
new Web3.providers.HttpProvider(dataWeb3ProviderEndpoint)
|
|
42
|
+
)
|
|
40
43
|
let web3DataContractConfig = {
|
|
41
44
|
registryAddress: dataRegistryAddress,
|
|
42
45
|
useExternalWeb3: true,
|
|
@@ -46,7 +49,9 @@ async function initializeVersionServiceProviderContracts () {
|
|
|
46
49
|
}
|
|
47
50
|
}
|
|
48
51
|
|
|
49
|
-
const ethWeb3 = new Web3(
|
|
52
|
+
const ethWeb3 = new Web3(
|
|
53
|
+
new Web3.providers.HttpProvider(ethWeb3ProviderEndpoint)
|
|
54
|
+
)
|
|
50
55
|
audiusLibsConfig = {
|
|
51
56
|
web3Config: web3DataContractConfig,
|
|
52
57
|
ethWeb3Config: AudiusLibs.configEthWeb3(
|
|
@@ -55,7 +60,7 @@ async function initializeVersionServiceProviderContracts () {
|
|
|
55
60
|
ethWeb3,
|
|
56
61
|
ownerWallet
|
|
57
62
|
),
|
|
58
|
-
discoveryProviderConfig:
|
|
63
|
+
discoveryProviderConfig: {},
|
|
59
64
|
isServer: isServer
|
|
60
65
|
}
|
|
61
66
|
let audiusLibs = new AudiusLibs(audiusLibsConfig)
|
|
@@ -84,9 +89,17 @@ async function initializeVersionServiceProviderContracts () {
|
|
|
84
89
|
}
|
|
85
90
|
*/
|
|
86
91
|
for (const serviceType of serviceTypeList) {
|
|
87
|
-
let versionTx =
|
|
88
|
-
|
|
89
|
-
|
|
92
|
+
let versionTx =
|
|
93
|
+
await audiusLibs.ethContracts.ServiceTypeManagerClient.getCurrentVersion(
|
|
94
|
+
serviceType
|
|
95
|
+
)
|
|
96
|
+
let numVersionsTx =
|
|
97
|
+
await audiusLibs.ethContracts.ServiceTypeManagerClient.getNumberOfVersions(
|
|
98
|
+
serviceType
|
|
99
|
+
)
|
|
100
|
+
console.log(
|
|
101
|
+
`${serviceType} | current version: ${versionTx} | number of versions : ${numVersionsTx}`
|
|
102
|
+
)
|
|
90
103
|
}
|
|
91
104
|
|
|
92
105
|
console.log('/----version init---')
|
package/initScripts/mainnet.js
CHANGED
|
@@ -34,29 +34,47 @@ const run = async () => {
|
|
|
34
34
|
const versionStr = args[5]
|
|
35
35
|
let dryRun = true
|
|
36
36
|
// if args[6] is defined and the value is either bool or string false, set dryRun to false
|
|
37
|
-
if (args[6] &&
|
|
37
|
+
if (args[6] && ['false', false].includes(args[6])) {
|
|
38
38
|
dryRun = false
|
|
39
39
|
}
|
|
40
40
|
if (!serviceType || !versionStr) {
|
|
41
|
-
throw new Error(
|
|
41
|
+
throw new Error(
|
|
42
|
+
'missing arguments - format: node mainnet.js setversion <serviceType> <versionStr>'
|
|
43
|
+
)
|
|
42
44
|
}
|
|
43
|
-
await setServiceVersion(
|
|
45
|
+
await setServiceVersion(
|
|
46
|
+
audiusLibs,
|
|
47
|
+
serviceType,
|
|
48
|
+
versionStr,
|
|
49
|
+
privateKey,
|
|
50
|
+
dryRun
|
|
51
|
+
)
|
|
44
52
|
break
|
|
45
53
|
case 'addservicetype':
|
|
46
54
|
const newServiceType = args[4]
|
|
47
55
|
const serviceTypeMin = args[5]
|
|
48
56
|
const serviceTypeMax = args[6]
|
|
49
57
|
if (!newServiceType || !serviceTypeMin || !serviceTypeMax) {
|
|
50
|
-
throw new Error(
|
|
58
|
+
throw new Error(
|
|
59
|
+
'missing arguments - format: node mainnet.js addservicetype <serviceType> <serviceTypeMin> <serviceTypeMax>'
|
|
60
|
+
)
|
|
51
61
|
}
|
|
52
|
-
await addServiceType(
|
|
62
|
+
await addServiceType(
|
|
63
|
+
audiusLibs,
|
|
64
|
+
newServiceType,
|
|
65
|
+
serviceTypeMin,
|
|
66
|
+
serviceTypeMax,
|
|
67
|
+
privateKey
|
|
68
|
+
)
|
|
53
69
|
break
|
|
54
70
|
case 'getclaim':
|
|
55
71
|
await getClaimInfo(audiusLibs)
|
|
56
72
|
break
|
|
57
73
|
case 'fundclaim':
|
|
58
74
|
if (!args[4]) {
|
|
59
|
-
throw new Error(
|
|
75
|
+
throw new Error(
|
|
76
|
+
'missing argument - format: node mainnet.js fundclaim <amountOfAuds>'
|
|
77
|
+
)
|
|
60
78
|
}
|
|
61
79
|
|
|
62
80
|
const amountOfAuds = args[4]
|
|
@@ -77,7 +95,7 @@ const run = async () => {
|
|
|
77
95
|
|
|
78
96
|
run()
|
|
79
97
|
|
|
80
|
-
function getLibsConfig
|
|
98
|
+
function getLibsConfig(config, privateKey, ownerWallet) {
|
|
81
99
|
let audiusLibsConfig
|
|
82
100
|
if (!privateKey || !ownerWallet) {
|
|
83
101
|
throw new Error('Missing private key or owner wallet')
|
|
@@ -86,7 +104,9 @@ function getLibsConfig (config, privateKey, ownerWallet) {
|
|
|
86
104
|
console.log(privateKey)
|
|
87
105
|
console.log(ownerWallet)
|
|
88
106
|
|
|
89
|
-
const dataWeb3 = new Web3(
|
|
107
|
+
const dataWeb3 = new Web3(
|
|
108
|
+
new Web3.providers.HttpProvider(config.dataWeb3ProviderEndpoint)
|
|
109
|
+
)
|
|
90
110
|
const web3DataContractConfig = {
|
|
91
111
|
registryAddress: config.dataRegistryAddress,
|
|
92
112
|
useExternalWeb3: true,
|
|
@@ -96,7 +116,9 @@ function getLibsConfig (config, privateKey, ownerWallet) {
|
|
|
96
116
|
}
|
|
97
117
|
}
|
|
98
118
|
|
|
99
|
-
const ethWeb3 = new Web3(
|
|
119
|
+
const ethWeb3 = new Web3(
|
|
120
|
+
new Web3.providers.HttpProvider(config.ethWeb3ProviderEndpoint)
|
|
121
|
+
)
|
|
100
122
|
audiusLibsConfig = {
|
|
101
123
|
web3Config: web3DataContractConfig,
|
|
102
124
|
ethWeb3Config: AudiusLibs.configEthWeb3(
|
|
@@ -105,20 +127,20 @@ function getLibsConfig (config, privateKey, ownerWallet) {
|
|
|
105
127
|
ethWeb3,
|
|
106
128
|
ownerWallet
|
|
107
129
|
),
|
|
108
|
-
discoveryProviderConfig:
|
|
130
|
+
discoveryProviderConfig: {},
|
|
109
131
|
isServer: isServer
|
|
110
132
|
}
|
|
111
133
|
return audiusLibsConfig
|
|
112
134
|
}
|
|
113
135
|
|
|
114
|
-
async function getAudiusLibs
|
|
136
|
+
async function getAudiusLibs(config, privateKey, ownerWallet) {
|
|
115
137
|
const audiusLibsConfig = getLibsConfig(config, privateKey, ownerWallet)
|
|
116
138
|
const audiusLibs = new AudiusLibs(audiusLibsConfig)
|
|
117
139
|
await audiusLibs.init()
|
|
118
140
|
return audiusLibs
|
|
119
141
|
}
|
|
120
142
|
|
|
121
|
-
function _getEnv
|
|
143
|
+
function _getEnv(env) {
|
|
122
144
|
const value = process.env[env]
|
|
123
145
|
if (typeof value === 'undefined') {
|
|
124
146
|
throw new Error(`${env} has not been set.`)
|
|
@@ -126,6 +148,8 @@ function _getEnv (env) {
|
|
|
126
148
|
return value
|
|
127
149
|
}
|
|
128
150
|
|
|
129
|
-
function _throwArgError
|
|
130
|
-
throw new Error(
|
|
151
|
+
function _throwArgError() {
|
|
152
|
+
throw new Error(
|
|
153
|
+
'missing argument - format: node mainnet.js <configFilePath> [setversion, fundclaim, getclaim, stakeinfo] [additional options]'
|
|
154
|
+
)
|
|
131
155
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@audius/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/types.d.ts",
|
|
7
7
|
"browser": "dist/browser.js",
|
|
8
|
+
"sdkBrowserDistFile": "dist/sdk.js",
|
|
9
|
+
"sdkBrowserDistFileMini": "dist/sdk.min.js",
|
|
8
10
|
"legacy": "dist/legacy.js",
|
|
9
11
|
"legacyTypes": "dist/legacy.d.ts",
|
|
10
12
|
"core": "dist/core.js",
|
|
@@ -26,13 +28,14 @@
|
|
|
26
28
|
"dependencies": {
|
|
27
29
|
"@audius/anchor-audius-data": "0.0.2",
|
|
28
30
|
"@audius/hedgehog": "1.0.12",
|
|
31
|
+
"@babel/runtime": "^7.18.3",
|
|
29
32
|
"@certusone/wormhole-sdk": "0.1.1",
|
|
30
33
|
"@ethersproject/solidity": "5.0.5",
|
|
31
34
|
"@improbable-eng/grpc-web-node-http-transport": "0.15.0",
|
|
32
35
|
"@project-serum/anchor": "0.24.1",
|
|
33
36
|
"@solana/spl-token": "0.1.6",
|
|
34
37
|
"@solana/web3.js": "1.37.1",
|
|
35
|
-
"abi-decoder": "
|
|
38
|
+
"abi-decoder": "2.4.0",
|
|
36
39
|
"ajv": "6.12.2",
|
|
37
40
|
"async-retry": "1.3.1",
|
|
38
41
|
"axios": "0.19.2",
|
|
@@ -64,6 +67,7 @@
|
|
|
64
67
|
"web3": "1.7.1"
|
|
65
68
|
},
|
|
66
69
|
"devDependencies": {
|
|
70
|
+
"@babel/plugin-transform-runtime": "^7.18.2",
|
|
67
71
|
"@babel/preset-env": "7.16.11",
|
|
68
72
|
"@openzeppelin/test-helpers": "0.5.6",
|
|
69
73
|
"@rollup/plugin-alias": "3.1.9",
|
|
@@ -103,6 +107,7 @@
|
|
|
103
107
|
"rollup-plugin-dts": "4.2.0",
|
|
104
108
|
"rollup-plugin-ignore": "1.0.10",
|
|
105
109
|
"rollup-plugin-polyfill-node": "0.9.0",
|
|
110
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
106
111
|
"sinon": "9.0.2",
|
|
107
112
|
"standard": "16.0.4",
|
|
108
113
|
"ts-mocha": "9.0.2",
|
package/rollup.config.js
CHANGED
|
@@ -3,6 +3,7 @@ import babel from '@rollup/plugin-babel'
|
|
|
3
3
|
import json from '@rollup/plugin-json'
|
|
4
4
|
import resolve from '@rollup/plugin-node-resolve'
|
|
5
5
|
import typescript from '@rollup/plugin-typescript'
|
|
6
|
+
import { terser } from 'rollup-plugin-terser'
|
|
6
7
|
import dts from 'rollup-plugin-dts'
|
|
7
8
|
import nodePolyfills from 'rollup-plugin-polyfill-node'
|
|
8
9
|
import alias from '@rollup/plugin-alias'
|
|
@@ -73,6 +74,33 @@ const browserConfig = {
|
|
|
73
74
|
external: external.filter((dep) => !browserInternal.includes(dep))
|
|
74
75
|
}
|
|
75
76
|
|
|
77
|
+
const browserDistFileConfig = {
|
|
78
|
+
plugins: [
|
|
79
|
+
ignore(['web3', 'graceful-fs', 'node-localstorage']),
|
|
80
|
+
resolve({ extensions, preferBuiltins: false, browser: true }),
|
|
81
|
+
commonjs({
|
|
82
|
+
extensions,
|
|
83
|
+
transformMixedEsModules: true,
|
|
84
|
+
dynamicRequireTargets: [
|
|
85
|
+
'data-contracts/ABIs/*.json',
|
|
86
|
+
'eth-contracts/ABIs/*.json'
|
|
87
|
+
]
|
|
88
|
+
}),
|
|
89
|
+
alias({
|
|
90
|
+
entries: [{ find: 'stream', replacement: 'stream-browserify' }]
|
|
91
|
+
}),
|
|
92
|
+
nodePolyfills(),
|
|
93
|
+
babel({
|
|
94
|
+
babelHelpers: 'runtime',
|
|
95
|
+
extensions,
|
|
96
|
+
plugins: ['@babel/plugin-transform-runtime']
|
|
97
|
+
}),
|
|
98
|
+
json(),
|
|
99
|
+
typescript()
|
|
100
|
+
],
|
|
101
|
+
external: ['web3']
|
|
102
|
+
}
|
|
103
|
+
|
|
76
104
|
const browserLegacyConfig = {
|
|
77
105
|
plugins: [
|
|
78
106
|
ignore(['web3', 'graceful-fs', 'node-localstorage']),
|
|
@@ -128,6 +156,27 @@ export default [
|
|
|
128
156
|
...browserConfig
|
|
129
157
|
},
|
|
130
158
|
|
|
159
|
+
/**
|
|
160
|
+
* SDK bundled for prebuilt package file to be used in browser
|
|
161
|
+
* Does not include libs but does include polyfills and all deps/dev deps
|
|
162
|
+
*/
|
|
163
|
+
{
|
|
164
|
+
input: 'src/sdk/sdkBrowserDist.ts',
|
|
165
|
+
output: [
|
|
166
|
+
{
|
|
167
|
+
file: pkg.sdkBrowserDistFile,
|
|
168
|
+
globals: {
|
|
169
|
+
web3: 'window.Web3'
|
|
170
|
+
},
|
|
171
|
+
format: 'iife',
|
|
172
|
+
esModule: false,
|
|
173
|
+
sourcemap: true,
|
|
174
|
+
plugins: [terser()]
|
|
175
|
+
}
|
|
176
|
+
],
|
|
177
|
+
...browserDistFileConfig
|
|
178
|
+
},
|
|
179
|
+
|
|
131
180
|
/**
|
|
132
181
|
* Legacy bundle for a browser environment
|
|
133
182
|
* Includes libs but does not include polyfills
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Base } from './base'
|
|
2
|
+
|
|
3
|
+
export class Reactions extends Base {
|
|
4
|
+
constructor(...args: any[]) {
|
|
5
|
+
super(...args)
|
|
6
|
+
this.submitReaction = this.submitReaction.bind(this)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Submit a user's reaction, represented by a numberic ID,
|
|
11
|
+
* to an entity e.g. a notification for a received tip.
|
|
12
|
+
*/
|
|
13
|
+
async submitReaction({
|
|
14
|
+
reactedTo,
|
|
15
|
+
reactionValue,
|
|
16
|
+
logger = console
|
|
17
|
+
}: {
|
|
18
|
+
reactedTo: string
|
|
19
|
+
reactionValue: number
|
|
20
|
+
logger: any
|
|
21
|
+
}): Promise<{ success: boolean; error: string | null }> {
|
|
22
|
+
try {
|
|
23
|
+
await this.identityService.submitReaction({
|
|
24
|
+
reactedTo,
|
|
25
|
+
reactionValue
|
|
26
|
+
})
|
|
27
|
+
logger.info(
|
|
28
|
+
`Successfully submitted reaction for entity ${reactedTo} and reaction value ${reactionValue}.`
|
|
29
|
+
)
|
|
30
|
+
return { success: true, error: null }
|
|
31
|
+
} catch (e) {
|
|
32
|
+
const errorMessage = (e as Error).message
|
|
33
|
+
logger.error(
|
|
34
|
+
`Could not successfully submit reaction for entity ${reactedTo} and reaction value ${reactionValue}. Error: ${errorMessage}`
|
|
35
|
+
)
|
|
36
|
+
return { success: false, error: errorMessage }
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
package/src/libs.js
CHANGED
|
@@ -5,7 +5,7 @@ const { SolanaAudiusData } = require('./services/solanaAudiusData/index')
|
|
|
5
5
|
const { Web3Manager } = require('./services/web3Manager')
|
|
6
6
|
const { EthContracts } = require('./services/ethContracts')
|
|
7
7
|
const SolanaWeb3Manager = require('./services/solanaWeb3Manager/index')
|
|
8
|
-
const { AudiusContracts } = require('./services/dataContracts
|
|
8
|
+
const { AudiusContracts } = require('./services/dataContracts')
|
|
9
9
|
const { IdentityService } = require('./services/identity')
|
|
10
10
|
const { Comstock } = require('./services/comstock')
|
|
11
11
|
const { Hedgehog } = require('./services/hedgehog')
|
|
@@ -33,51 +33,15 @@ const { PublicKey } = require('@solana/web3.js')
|
|
|
33
33
|
const {
|
|
34
34
|
RewardsAttester
|
|
35
35
|
} = require('./services/solanaWeb3Manager/rewardsAttester')
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Configures a discovery provider wrapper
|
|
39
|
-
* @param {Set<string>?} whitelist whether or not to include only specified nodes (default no whitelist)
|
|
40
|
-
* @param {Set<string>?} blacklist whether or not to exclude specified nodes (default no blacklist)
|
|
41
|
-
* @param {number?} reselectTimeout timeout to clear locally cached discovery providers
|
|
42
|
-
* @param {(selection: string) => void?} selectionCallback invoked with the select discovery provider
|
|
43
|
-
* @param {object?} monitoringCallbacks callbacks to be invoked with metrics from requests sent to a service
|
|
44
|
-
* @param {function} monitoringCallbacks.request
|
|
45
|
-
* @param {function} monitoringCallbacks.healthCheck
|
|
46
|
-
* @param {number?} selectionRequestTimeout the amount of time (ms) an individual request should take before reselecting
|
|
47
|
-
* @param {number?} selectionRequestRetries the number of retries to a given discovery node we make before reselecting
|
|
48
|
-
* @param {number?} unhealthySlotDiffPlays the number of slots we would consider a discovery node unhealthy
|
|
49
|
-
* @param {number?} unhealthyBlockDiff the number of missed blocks after which we would consider a discovery node unhealthy
|
|
50
|
-
*/
|
|
51
|
-
static configDiscoveryProvider(
|
|
52
|
-
whitelist = null,
|
|
53
|
-
blacklist = null,
|
|
54
|
-
reselectTimeout = null,
|
|
55
|
-
selectionCallback = null,
|
|
56
|
-
monitoringCallbacks = {},
|
|
57
|
-
selectionRequestTimeout = null,
|
|
58
|
-
selectionRequestRetries = null,
|
|
59
|
-
unhealthySlotDiffPlays = null,
|
|
60
|
-
unhealthyBlockDiff = null
|
|
61
|
-
) {
|
|
62
|
-
return {
|
|
63
|
-
whitelist,
|
|
64
|
-
blacklist,
|
|
65
|
-
reselectTimeout,
|
|
66
|
-
selectionCallback,
|
|
67
|
-
monitoringCallbacks,
|
|
68
|
-
selectionRequestTimeout,
|
|
69
|
-
selectionRequestRetries,
|
|
70
|
-
unhealthySlotDiffPlays,
|
|
71
|
-
unhealthyBlockDiff
|
|
72
|
-
}
|
|
73
|
-
}
|
|
36
|
+
const { Reactions } = require('./api/reactions')
|
|
74
37
|
|
|
38
|
+
class AudiusLibs {
|
|
75
39
|
/**
|
|
76
40
|
* Configures an identity service wrapper
|
|
77
41
|
* @param {string} url
|
|
78
42
|
* @param {boolean?} useHedgehogLocalStorage whether or not to read hedgehog entropy in local storage
|
|
79
43
|
*/
|
|
80
|
-
static configIdentityService(url, useHedgehogLocalStorage = true) {
|
|
44
|
+
static configIdentityService (url, useHedgehogLocalStorage = true) {
|
|
81
45
|
return { url, useHedgehogLocalStorage }
|
|
82
46
|
}
|
|
83
47
|
|
|
@@ -85,7 +49,7 @@ class AudiusLibs {
|
|
|
85
49
|
* Configures an identity service wrapper
|
|
86
50
|
* @param {string} url
|
|
87
51
|
*/
|
|
88
|
-
static configComstock(url) {
|
|
52
|
+
static configComstock (url) {
|
|
89
53
|
return { url }
|
|
90
54
|
}
|
|
91
55
|
|
|
@@ -100,7 +64,7 @@ class AudiusLibs {
|
|
|
100
64
|
* @param {function} monitoringCallbacks.request
|
|
101
65
|
* @param {function} monitoringCallbacks.healthCheck
|
|
102
66
|
*/
|
|
103
|
-
static configCreatorNode(
|
|
67
|
+
static configCreatorNode (
|
|
104
68
|
fallbackUrl,
|
|
105
69
|
lazyConnect = false,
|
|
106
70
|
passList = null,
|
|
@@ -124,7 +88,7 @@ class AudiusLibs {
|
|
|
124
88
|
* @param {?string} walletOverride wallet address to force use instead of the first wallet on the provided web3
|
|
125
89
|
* @param {?number} walletIndex if using a wallet returned from web3, pick the wallet at this index
|
|
126
90
|
*/
|
|
127
|
-
static async configExternalWeb3(
|
|
91
|
+
static async configExternalWeb3 (
|
|
128
92
|
registryAddress,
|
|
129
93
|
web3Provider,
|
|
130
94
|
networkId,
|
|
@@ -150,7 +114,7 @@ class AudiusLibs {
|
|
|
150
114
|
* @param {string} registryAddress
|
|
151
115
|
* @param {string | Web3 | Array<string>} providers web3 provider endpoint(s)
|
|
152
116
|
*/
|
|
153
|
-
static configInternalWeb3(registryAddress, providers, privateKey) {
|
|
117
|
+
static configInternalWeb3 (registryAddress, providers, privateKey) {
|
|
154
118
|
let providerList
|
|
155
119
|
if (typeof providers === 'string') {
|
|
156
120
|
providerList = providers.split(',')
|
|
@@ -183,7 +147,7 @@ class AudiusLibs {
|
|
|
183
147
|
* @param {string?} claimDistributionContractAddress
|
|
184
148
|
* @param {string?} wormholeContractAddress
|
|
185
149
|
*/
|
|
186
|
-
static configEthWeb3(
|
|
150
|
+
static configEthWeb3 (
|
|
187
151
|
tokenAddress,
|
|
188
152
|
registryAddress,
|
|
189
153
|
providers,
|
|
@@ -223,7 +187,7 @@ class AudiusLibs {
|
|
|
223
187
|
* @param {string} config.ethBridgeAddress
|
|
224
188
|
* @param {string} config.ethTokenBridgeAddress
|
|
225
189
|
*/
|
|
226
|
-
static configWormhole({
|
|
190
|
+
static configWormhole ({
|
|
227
191
|
rpcHosts,
|
|
228
192
|
solBridgeAddress,
|
|
229
193
|
solTokenBridgeAddress,
|
|
@@ -267,7 +231,7 @@ class AudiusLibs {
|
|
|
267
231
|
* @param {PublicKey|string} audiusDataProgramId program ID for the audius-data Anchor program
|
|
268
232
|
* @param {Idl} audiusDataIdl IDL for the audius-data Anchor program.
|
|
269
233
|
*/
|
|
270
|
-
static configSolanaWeb3({
|
|
234
|
+
static configSolanaWeb3 ({
|
|
271
235
|
solanaClusterEndpoint,
|
|
272
236
|
mintAddress,
|
|
273
237
|
solanaTokenAddress,
|
|
@@ -319,7 +283,7 @@ class AudiusLibs {
|
|
|
319
283
|
* @param {string} config.programId Program ID of the audius data program
|
|
320
284
|
* @param {string} config.adminAccount Public Key of admin account
|
|
321
285
|
*/
|
|
322
|
-
static configSolanaAudiusData({ programId, adminAccount }) {
|
|
286
|
+
static configSolanaAudiusData ({ programId, adminAccount }) {
|
|
323
287
|
return {
|
|
324
288
|
programId,
|
|
325
289
|
adminAccount
|
|
@@ -331,12 +295,12 @@ class AudiusLibs {
|
|
|
331
295
|
* Unless default-valued, all configs are optional.
|
|
332
296
|
* @example
|
|
333
297
|
* const audius = AudiusLibs({
|
|
334
|
-
* discoveryProviderConfig:
|
|
298
|
+
* discoveryProviderConfig: {},
|
|
335
299
|
* creatorNodeConfig: configCreatorNode('https://my-creator.node')
|
|
336
300
|
* })
|
|
337
301
|
* await audius.init()
|
|
338
302
|
*/
|
|
339
|
-
constructor({
|
|
303
|
+
constructor ({
|
|
340
304
|
web3Config,
|
|
341
305
|
ethWeb3Config,
|
|
342
306
|
solanaWeb3Config,
|
|
@@ -394,6 +358,7 @@ class AudiusLibs {
|
|
|
394
358
|
this.Playlist = null
|
|
395
359
|
this.File = null
|
|
396
360
|
this.Rewards = null
|
|
361
|
+
this.Reactions = null
|
|
397
362
|
|
|
398
363
|
this.preferHigherPatchForPrimary = preferHigherPatchForPrimary
|
|
399
364
|
this.preferHigherPatchForSecondaries = preferHigherPatchForSecondaries
|
|
@@ -405,7 +370,7 @@ class AudiusLibs {
|
|
|
405
370
|
}
|
|
406
371
|
|
|
407
372
|
/** Init services based on presence of a relevant config. */
|
|
408
|
-
async init() {
|
|
373
|
+
async init () {
|
|
409
374
|
this.userStateManager = new UserStateManager()
|
|
410
375
|
// Config external web3 is an async function, so await it here in case it needs to be
|
|
411
376
|
this.web3Config = await this.web3Config
|
|
@@ -525,21 +490,10 @@ class AudiusLibs {
|
|
|
525
490
|
/** Discovery Provider */
|
|
526
491
|
if (this.discoveryProviderConfig) {
|
|
527
492
|
this.discoveryProvider = new DiscoveryProvider({
|
|
528
|
-
whitelist: this.discoveryProviderConfig.whitelist,
|
|
529
|
-
blacklist: this.discoveryProviderConfig.blacklist,
|
|
530
493
|
userStateManager: this.userStateManager,
|
|
531
494
|
ethContracts: this.ethContracts,
|
|
532
495
|
web3Manager: this.web3Manager,
|
|
533
|
-
|
|
534
|
-
selectionCallback: this.discoveryProviderConfig.selectionCallback,
|
|
535
|
-
monitoringCallbacks: this.discoveryProviderConfig.monitoringCallbacks,
|
|
536
|
-
selectionRequestTimeout:
|
|
537
|
-
this.discoveryProviderConfig.selectionRequestTimeout,
|
|
538
|
-
selectionRequestRetries:
|
|
539
|
-
this.discoveryProviderConfig.selectionRequestRetries,
|
|
540
|
-
unhealthySlothDiffPlays:
|
|
541
|
-
this.discoveryProviderConfig.unhealthySlotDiffPlays,
|
|
542
|
-
unhealthBlockDiff: this.discoveryProviderConfig.unhealthyBlockDiff
|
|
496
|
+
...this.discoveryProviderConfig
|
|
543
497
|
})
|
|
544
498
|
await this.discoveryProvider.init()
|
|
545
499
|
}
|
|
@@ -602,6 +556,7 @@ class AudiusLibs {
|
|
|
602
556
|
this.Playlist = new Playlist(...services)
|
|
603
557
|
this.File = new File(this.User, ...services)
|
|
604
558
|
this.Rewards = new Rewards(this.ServiceProvider, ...services)
|
|
559
|
+
this.Reactions = new Reactions(...services)
|
|
605
560
|
}
|
|
606
561
|
}
|
|
607
562
|
|
package/src/sdk/oauth/Oauth.ts
CHANGED
|
@@ -105,13 +105,13 @@ const OAUTH_URL = 'https://audius.co/oauth/auth'
|
|
|
105
105
|
const CSRF_TOKEN_KEY = 'audiusOauthState'
|
|
106
106
|
|
|
107
107
|
type OauthConfig = {
|
|
108
|
-
appName
|
|
108
|
+
appName: string
|
|
109
109
|
discoveryProvider: DiscoveryProvider
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
export class Oauth {
|
|
113
113
|
discoveryProvider: DiscoveryProvider
|
|
114
|
-
appName: string
|
|
114
|
+
appName: string
|
|
115
115
|
activePopupWindow: null | Window
|
|
116
116
|
popupCheckInterval: NodeJS.Timer | null
|
|
117
117
|
loginSuccessCallback: LoginSuccessCallback | null
|
|
@@ -125,7 +125,7 @@ export class Oauth {
|
|
|
125
125
|
)
|
|
126
126
|
}
|
|
127
127
|
this.discoveryProvider = discoveryProvider
|
|
128
|
-
this.appName = appName
|
|
128
|
+
this.appName = appName
|
|
129
129
|
this.activePopupWindow = null
|
|
130
130
|
this.loginSuccessCallback = null
|
|
131
131
|
this.loginErrorCallback = null
|
package/src/sdk/sdk.ts
CHANGED
|
@@ -34,14 +34,14 @@ type SdkConfig = {
|
|
|
34
34
|
/**
|
|
35
35
|
* The Audius SDK
|
|
36
36
|
*/
|
|
37
|
-
export const sdk = async (config
|
|
37
|
+
export const sdk = async (config: SdkConfig) => {
|
|
38
38
|
const {
|
|
39
39
|
appName,
|
|
40
40
|
discoveryNodeConfig,
|
|
41
41
|
ethContractsConfig,
|
|
42
42
|
ethWeb3Config,
|
|
43
43
|
identityServiceConfig
|
|
44
|
-
} = config
|
|
44
|
+
} = config
|
|
45
45
|
|
|
46
46
|
/** Initialize services */
|
|
47
47
|
|
|
@@ -50,7 +50,10 @@ export type UserProfile = {
|
|
|
50
50
|
name: string
|
|
51
51
|
handle: string
|
|
52
52
|
verified: boolean
|
|
53
|
-
|
|
53
|
+
profilePicture:
|
|
54
|
+
| { '150x150': string; '480x480': string; '1000x1000': string }
|
|
55
|
+
| null
|
|
56
|
+
| undefined
|
|
54
57
|
sub: number
|
|
55
58
|
iat: string
|
|
56
59
|
}
|
|
@@ -615,11 +618,11 @@ export class DiscoveryProvider {
|
|
|
615
618
|
*/
|
|
616
619
|
async verifyToken(token: string): Promise<UserProfile | false> {
|
|
617
620
|
const req = Requests.verifyToken(token)
|
|
618
|
-
const res = await this._makeRequest<UserProfile
|
|
619
|
-
if (res == null
|
|
621
|
+
const res = await this._makeRequest<UserProfile | null>(req)
|
|
622
|
+
if (res == null) {
|
|
620
623
|
return false
|
|
621
624
|
} else {
|
|
622
|
-
return res
|
|
625
|
+
return res
|
|
623
626
|
}
|
|
624
627
|
}
|
|
625
628
|
|
|
@@ -46,15 +46,13 @@ export class EthWeb3Manager {
|
|
|
46
46
|
this.identityService = identityService
|
|
47
47
|
this.hedgehog = hedgehog
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
this.ownerWallet = storedWallet
|
|
57
|
-
}
|
|
49
|
+
if (this.web3Config.ownerWallet) {
|
|
50
|
+
this.ownerWallet = this.web3Config.ownerWallet
|
|
51
|
+
} else if (this.hedgehog) {
|
|
52
|
+
// Hedgehog might not exist (in the case of @audius/sdk)
|
|
53
|
+
const storedWallet = this.hedgehog.getWallet()
|
|
54
|
+
if (storedWallet) {
|
|
55
|
+
this.ownerWallet = storedWallet
|
|
58
56
|
}
|
|
59
57
|
}
|
|
60
58
|
}
|