@audius/sdk 0.0.13 → 0.0.14

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.
@@ -0,0 +1,689 @@
1
+ import { UserImporterOptions, ImportCandidate } from 'ipfs-unixfs-importer';
2
+ import * as ipfs_unixfs_importer_types_src_types from 'ipfs-unixfs-importer/types/src/types';
3
+ import * as Web3 from 'web3';
4
+ import Web3__default from 'web3';
5
+ import * as BN from 'bn.js';
6
+ import { AbiItem } from 'web3-utils';
7
+ import * as axios from 'axios';
8
+ import { AxiosResponse, AxiosRequestConfig, AxiosError } from 'axios';
9
+ import FormData from 'form-data';
10
+ import Wallet from 'ethereumjs-wallet';
11
+ import { HttpProvider, AbstractProvider, Log, TransactionReceipt } from 'web3-core';
12
+ import abiDecoder from 'abi-decoder';
13
+ import { Hedgehog } from '@audius/hedgehog';
14
+ import { EIP712TypedData } from 'eth-sig-util';
15
+
16
+ declare type Content = ReadableStream | Buffer | string;
17
+ interface ImageHasher {
18
+ options: UserImporterOptions;
19
+ content: ImportCandidate;
20
+ }
21
+ interface NonImageHasher {
22
+ options: UserImporterOptions;
23
+ content: Uint8Array;
24
+ }
25
+ interface HashedImage {
26
+ path: string | undefined;
27
+ cid: string;
28
+ size: number;
29
+ }
30
+
31
+ type ContractABI = {
32
+ abi: AbiItem[]
33
+ contractName: string
34
+ }
35
+
36
+ declare class Utils {
37
+ static importDataContractABI(pathStr: string): ContractABI;
38
+ static importEthContractABI(pathStr: string): ContractABI;
39
+ static utf8ToHex(utf8Str: string): string;
40
+ static padRight(hexStr: string, size: number): string;
41
+ static hexToUtf8(hexStr: string): string;
42
+ static keccak256(utf8Str: string): string;
43
+ static isBN(number: number | string): boolean;
44
+ static toBN(number: number, base?: number): BN;
45
+ static BN(): typeof BN;
46
+ static checkStrLen(str: string, maxLen: number, minLen?: number): void;
47
+ static wait(milliseconds: number): Promise<void>;
48
+ static isFQDN(url: string): boolean;
49
+ static isHttps(url: string): boolean;
50
+ static isHealthy(url: string): Promise<any>;
51
+ static formatOptionalMultihash(multihash: string): string;
52
+ static decodeMultihash(multihash: string): {
53
+ digest: string;
54
+ hashFn: number;
55
+ size: number;
56
+ };
57
+ /**
58
+ * Given a digest value (written on chain, obtained through AudiusABIDecoder.decodeMethod),
59
+ * convert back to a IFPS CIDv0
60
+ * @param multihashDigest digest value from decodeMultihash
61
+ * @returns String CID value
62
+ */
63
+ static encodeMultihash(multihashDigest: string): string;
64
+ static parseDataFromResponse(response: AxiosResponse): any;
65
+ static configureWeb3(web3Provider: string, chainNetworkId: string, requiresAccount?: boolean): Promise<false | Web3.default>;
66
+ static get zeroAddress(): string;
67
+ static isZeroAddress(address: string): boolean;
68
+ static makeUuid(): string;
69
+ /**
70
+ * Decodes a string id into an int. Returns null if an invalid ID.
71
+ */
72
+ static decodeHashId(id: string): number | null;
73
+ /**
74
+ * Encodes an int to a string based hashid
75
+ */
76
+ static encodeHashId(id: number | null): string | null;
77
+ /**
78
+ * If `promise` responds before `timeoutMs`,
79
+ * this function returns its response; else rejects with `timeoutMessage`
80
+ */
81
+ static racePromiseWithTimeout(promise: Promise<void>, timeoutMs: number, timeoutMessage: string): Promise<unknown>;
82
+ static fileHasher: {
83
+ convertNanosToMillis(nanoSeconds: bigint): bigint;
84
+ initImageHasher(content: ipfs_unixfs_importer_types_src_types.ImportCandidate, options: ipfs_unixfs_importer_types_src_types.UserImporterOptions): ImageHasher;
85
+ initNonImageHasher(content: Uint8Array, options: ipfs_unixfs_importer_types_src_types.UserImporterOptions): NonImageHasher;
86
+ convertToBuffer(content: Content, logger: any): Promise<Buffer>;
87
+ hashNonImages(content: Uint8Array, options?: ipfs_unixfs_importer_types_src_types.UserImporterOptions): Promise<string>;
88
+ hashImages(content: ipfs_unixfs_importer_types_src_types.ImportCandidate, options?: ipfs_unixfs_importer_types_src_types.UserImporterOptions): Promise<HashedImage[]>;
89
+ generateNonImageCid(content: Content, logger?: any): Promise<string>;
90
+ generateImageCids(content: ipfs_unixfs_importer_types_src_types.ImportCandidate, logger?: any): Promise<HashedImage[]>;
91
+ };
92
+ }
93
+
94
+ declare global {
95
+ interface Window {
96
+ grecaptcha: {
97
+ ready: (callback: () => void) => Promise<void>;
98
+ execute: (siteKey: string, config: {
99
+ action: string;
100
+ }) => Promise<string>;
101
+ };
102
+ }
103
+ }
104
+ interface CaptchaConfig {
105
+ siteKey: string;
106
+ serviceKey: string;
107
+ }
108
+ declare class Captcha {
109
+ siteKey: string;
110
+ serviceKey: string;
111
+ constructor({ siteKey, serviceKey }: CaptchaConfig);
112
+ /**
113
+ * Intended to be called by clients. Will generate a token used to calculate recaptcha score.
114
+ * @param action name for this "action" for grouping
115
+ */
116
+ generate(action: string): Promise<string>;
117
+ /**
118
+ * Intended to be called by services. According to recaptcha v3 docs:
119
+ * A score of 1.0 is very likely a good interaction, 0.0 is very likely a bot
120
+ * @param token
121
+ * @param minScore score must be >= minScore to be ok
122
+ * @returns
123
+ * {boolean | null} ok - whether score > minScore (false if something went wrong)
124
+ * {number | null} score - the raw score [0, 1] (or null if a score was not computed)
125
+ */
126
+ verify(token: string, minScore?: number): Promise<{
127
+ score: any;
128
+ ok: boolean;
129
+ hostname: any;
130
+ }>;
131
+ }
132
+
133
+ interface ContractMethod {
134
+ arguments: string[];
135
+ estimateGas: (config: {
136
+ from: Wallet | string | undefined;
137
+ gas: number | undefined;
138
+ }) => Promise<number>;
139
+ _method: {
140
+ name: string;
141
+ inputs: Array<{
142
+ type: string;
143
+ }>;
144
+ };
145
+ encodeABI: () => string;
146
+ send: <Tx>(config: {
147
+ from: Wallet | undefined;
148
+ gas: number;
149
+ gasPrice?: number;
150
+ }) => Tx;
151
+ }
152
+
153
+ declare type Providers = [
154
+ HttpProvider,
155
+ ...Array<HttpProvider | AbstractProvider>
156
+ ];
157
+
158
+ declare type SchemaConfig = {
159
+ schema: {
160
+ definitions: Record<string, {
161
+ required: string[];
162
+ properties: Record<string, {
163
+ default: unknown;
164
+ }>;
165
+ } | {}>;
166
+ };
167
+ baseDefinition: string;
168
+ validate?: (obj: Record<string, unknown>) => void;
169
+ };
170
+ declare type Schemas = {
171
+ TrackSchema: SchemaConfig;
172
+ UserSchema: SchemaConfig;
173
+ };
174
+
175
+ declare type Web3Config = {
176
+ ownerWallet: Wallet;
177
+ providers: Providers;
178
+ useExternalWeb3: boolean;
179
+ internalWeb3Config: {
180
+ web3ProviderEndpoints: string[];
181
+ privateKey: string;
182
+ };
183
+ externalWeb3Config: {
184
+ web3: Web3__default;
185
+ ownerWallet: Wallet;
186
+ };
187
+ };
188
+
189
+ declare class AudiusABIDecoder {
190
+ static decodeMethod(contractName: string, encodedABI: string): abiDecoder.DecodedMethod;
191
+ static decodeLogs(_: string, logs: Log[]): abiDecoder.DecodedLog;
192
+ }
193
+
194
+ declare type TimeFrame = 'day' | 'week' | 'month' | 'year' | 'millennium';
195
+
196
+ declare type Data = Record<string, unknown>;
197
+ declare type RelayTransaction = {
198
+ resp: {
199
+ txHash: string;
200
+ txParams: {
201
+ data: string;
202
+ gasLimit: string;
203
+ gasPrice: number;
204
+ nonce: string;
205
+ to: string;
206
+ value: string;
207
+ };
208
+ };
209
+ };
210
+ declare type TransactionData = {
211
+ recentBlockhash: string;
212
+ secpInstruction?: {
213
+ publicKey: string;
214
+ message: string;
215
+ signature: any;
216
+ recoveryId: number;
217
+ };
218
+ instruction: {
219
+ keys: Array<{
220
+ pubkey: string;
221
+ isSigner?: boolean;
222
+ isWritable?: boolean;
223
+ }>;
224
+ programId: string;
225
+ data: Record<string, unknown>;
226
+ };
227
+ };
228
+ declare type AttestationResult = {
229
+ status: string;
230
+ userId: string;
231
+ challengeId: string;
232
+ amount: number;
233
+ source: string;
234
+ specifier: string;
235
+ error?: string;
236
+ phase?: string;
237
+ reason?: string;
238
+ };
239
+ declare class IdentityService {
240
+ identityServiceEndpoint: string;
241
+ captcha: Captcha;
242
+ web3Manager: Web3Manager | null;
243
+ constructor(identityServiceEndpoint: string, captcha: Captcha);
244
+ setWeb3Manager(web3Manager: Web3Manager): void;
245
+ getFn(params: {
246
+ lookupKey: string;
247
+ username: string;
248
+ }): Promise<{
249
+ iv: string;
250
+ cipherText: string;
251
+ }>;
252
+ setAuthFn(obj: Data): Promise<unknown>;
253
+ setUserFn(obj: Data & {
254
+ token?: string;
255
+ }): Promise<unknown>;
256
+ getUserEvents(walletAddress: string): Promise<unknown>;
257
+ sendRecoveryInfo(obj: Record<string, unknown>): Promise<unknown>;
258
+ /**
259
+ * Check if an email address has been previously registered.
260
+ */
261
+ checkIfEmailRegistered(email: string): Promise<{
262
+ exists: boolean;
263
+ }>;
264
+ getUserEmail(): Promise<{
265
+ email: string | undefined | null;
266
+ }>;
267
+ /**
268
+ * Associates a user with a twitter uuid.
269
+ * @param uuid from the Twitter API
270
+ * @param userId
271
+ * @param handle User handle
272
+ */
273
+ associateTwitterUser(uuid: string, userId: number, handle: string): Promise<unknown>;
274
+ /**
275
+ * Associates a user with an instagram uuid.
276
+ * @param uuid from the Instagram API
277
+ * @param userId
278
+ * @param handle
279
+ */
280
+ associateInstagramUser(uuid: string, userId: number, handle: string): Promise<unknown>;
281
+ /**
282
+ * Logs a track listen for a given user id.
283
+ * @param trackId
284
+ * @param userId
285
+ * @param listenerAddress if logging this listen on behalf of another IP address, pass through here
286
+ * @param signatureData if logging this listen via a 3p service, a signed piece of data proving authenticity
287
+ */
288
+ logTrackListen(trackId: number, userId: number, listenerAddress: string, signatureData?: {
289
+ signature: string;
290
+ timestamp: string;
291
+ }, solanaListen?: boolean): Promise<unknown>;
292
+ /**
293
+ * Return listen history tracks for a given user id.
294
+ * @param userId - User ID
295
+ * @param limit - max # of items to return
296
+ * @param offset - offset into list to return from (for pagination)
297
+ */
298
+ getListenHistoryTracks(userId: number, limit?: number, offset?: number): Promise<unknown>;
299
+ /**
300
+ * Looks up a Twitter account by handle.
301
+ * @returns twitter API response.
302
+ */
303
+ lookupTwitterHandle(handle: string): Promise<unknown>;
304
+ /**
305
+ * Gets tracks trending on Audius.
306
+ * @param timeFrame one of day, week, month, or year
307
+ * @param idsArray track ids
308
+ * @param limit
309
+ * @param offset
310
+ */
311
+ getTrendingTracks(timeFrame?: string | null, idsArray?: number[] | null, limit?: number | null, offset?: number | null): Promise<{
312
+ listenCounts: Array<{
313
+ trackId: number;
314
+ listens: number;
315
+ }>;
316
+ }>;
317
+ /**
318
+ * Gets listens for tracks bucketted by timeFrame.
319
+ * @param timeFrame one of day, week, month, or year
320
+ * @param idsArray track ids
321
+ * @param startTime parseable by Date.parse
322
+ * @param endTime parseable by Date.parse
323
+ * @param limit
324
+ * @param offset
325
+ */
326
+ getTrackListens(timeFrame?: TimeFrame | null, idsArray?: number[] | null, startTime?: string | null, endTime?: string | null, limit?: number | null, offset?: number | null): Promise<{
327
+ bucket: Array<{
328
+ trackId: number;
329
+ date: string;
330
+ listens: number;
331
+ }>;
332
+ }>;
333
+ createUserRecord(email: string, walletAddress: string): Promise<unknown>;
334
+ relay(contractRegistryKey: string | null | undefined, contractAddress: string | null | undefined, senderAddress: string, encodedABI: string, gasLimit: number): Promise<{
335
+ receipt: TransactionReceipt;
336
+ }>;
337
+ ethRelay(contractAddress: string, senderAddress: Wallet | string, encodedABI: string, gasLimit: string): Promise<RelayTransaction>;
338
+ wormholeRelay({ senderAddress, permit, transferTokens }: {
339
+ senderAddress: string;
340
+ permit: string;
341
+ transferTokens: string[];
342
+ }): Promise<unknown>;
343
+ /**
344
+ * Gets the correct wallet that will relay a txn for `senderAddress`
345
+ * @param senderAddress wallet
346
+ */
347
+ getEthRelayer(senderAddress: string): Promise<unknown>;
348
+ getRandomFeePayer(): Promise<unknown>;
349
+ solanaRelay(transactionData: TransactionData): Promise<unknown>;
350
+ solanaRelayRaw(transactionData: TransactionData): Promise<unknown>;
351
+ getMinimumDelegationAmount(wallet: string): Promise<unknown>;
352
+ updateMinimumDelegationAmount(wallet: string, minimumDelegationAmount: number, signedData: AxiosRequestConfig['headers']): Promise<unknown>;
353
+ /**
354
+ * Sends an attestation result to identity.
355
+ *
356
+ */
357
+ sendAttestationResult(data: AttestationResult): Promise<unknown>;
358
+ _makeRequest<T = unknown>(axiosRequestObj: AxiosRequestConfig): Promise<T>;
359
+ _signData(): Promise<{
360
+ "Encoded-Data-Message": string;
361
+ "Encoded-Data-Signature": string | undefined;
362
+ } | {
363
+ "Encoded-Data-Message"?: undefined;
364
+ "Encoded-Data-Signature"?: undefined;
365
+ }>;
366
+ }
367
+
368
+ /** singleton class to be instantiated and persisted with every AudiusLibs */
369
+ declare class Web3Manager {
370
+ web3Config: Web3Config;
371
+ isServer: boolean;
372
+ identityService: IdentityService;
373
+ hedgehog: Hedgehog;
374
+ AudiusABIDecoder: typeof AudiusABIDecoder;
375
+ web3: Web3__default | undefined;
376
+ useExternalWeb3: boolean | undefined;
377
+ ownerWallet: Wallet;
378
+ constructor(web3Config: Web3Config, identityService: IdentityService, hedgehog: Hedgehog, isServer: boolean);
379
+ init(): Promise<void>;
380
+ getWeb3(): Web3__default;
381
+ setWeb3(web3: Web3__default): void;
382
+ getWalletAddress(): any;
383
+ setOwnerWallet(ownerWallet: Wallet): void;
384
+ web3IsExternal(): boolean | undefined;
385
+ getOwnerWalletPrivateKey(): Buffer;
386
+ /**
387
+ * Signs provided string data (should be timestamped).
388
+ * @param data
389
+ */
390
+ sign(data: string): Promise<string | undefined>;
391
+ /**
392
+ * Given a data payload and signature, verifies that signature is valid, and returns
393
+ * Ethereum wallet address used to sign data.
394
+ * @param data information that was signed
395
+ * @param signature hex-formatted signature of data generated by web3 personalSign method
396
+ */
397
+ verifySignature(data: string, signature: string): Promise<string>;
398
+ signTypedData(signatureData: EIP712TypedData): Promise<unknown>;
399
+ sendTransaction(contractMethod: ContractMethod, contractRegistryKey?: string | null, contractAddress?: string | null, txRetries?: number, txGasLimit?: number): Promise<TransactionReceipt>;
400
+ provider(url: string, timeout: number): HttpProvider;
401
+ monkeyPatchProvider(httpProvider: HttpProvider): HttpProvider;
402
+ }
403
+
404
+ declare type CurrentUser = {
405
+ user_id: string;
406
+ wallet: string;
407
+ blocknumber: number;
408
+ track_blocknumber: number;
409
+ creator_node_endpoint: string;
410
+ is_creator: boolean;
411
+ };
412
+ /**
413
+ * Singleton class to store the current user if initialized.
414
+ * Some instances of AudiusLibs and services require a current user to
415
+ * return valid queries, e.g. requesting the a discprov to return a reposted track.
416
+ */
417
+ declare class UserStateManager {
418
+ currentUser: CurrentUser | null;
419
+ constructor();
420
+ /**
421
+ * Sets this.currentUser with currentUser
422
+ * @param {Object} currentUser fields to override this.currentUser with
423
+ */
424
+ setCurrentUser(currentUser: CurrentUser): void;
425
+ getCurrentUser(): CurrentUser | null;
426
+ getCurrentUserId(): string | null;
427
+ clearUser(): void;
428
+ }
429
+
430
+ declare type Metadata = {
431
+ track_segments: unknown;
432
+ download?: {
433
+ is_downloadable: boolean;
434
+ cid: string;
435
+ };
436
+ cover_art_sizes: string;
437
+ };
438
+ declare type ProgressCB = (loaded: number, total: number) => void;
439
+ declare type MonitoringCallbacks = {
440
+ request?: Function;
441
+ healthCheck?: Function;
442
+ };
443
+ declare type ClockValueRequestConfig = {
444
+ user: CurrentUser;
445
+ endpoint: string;
446
+ timeout?: number;
447
+ };
448
+ declare type FileUploadResponse = {
449
+ data: {
450
+ uuid: string;
451
+ };
452
+ error: Error;
453
+ };
454
+ declare class CreatorNode {
455
+ /**
456
+ * Pulls off the primary creator node from a creator node endpoint string.
457
+ * @param endpoints user.creator_node_endpoint
458
+ */
459
+ static getPrimary(endpoints: string): string | undefined;
460
+ /**
461
+ * Pulls off the secondary creator nodes from a creator node endpoint string.
462
+ * @param endpoints user.creator_node_endpoint
463
+ */
464
+ static getSecondaries(endpoints: string): string[];
465
+ /**
466
+ * Pulls the user's creator nodes out of the list
467
+ * @param endpoints user.creator_node_endpoint
468
+ */
469
+ static getEndpoints(endpoints: string): string[];
470
+ /**
471
+ * Builds the creator_node_endpoint value off of a primary and secondaries list
472
+ * @param primary the primary endpoint
473
+ * @param secondaries a list of secondary endpoints
474
+ */
475
+ static buildEndpoint(primary: string, secondaries: string[]): string;
476
+ /**
477
+ * Pulls off the user's clock value from a creator node endpoint and the user's wallet address.
478
+ * @param endpoint content node endpoint
479
+ * @param wallet user wallet address
480
+ * @param timeout max time alloted for clock request
481
+ * @param params optional query string params
482
+ */
483
+ static getClockValue(endpoint: string, wallet: string, timeout: number, params?: Record<string, string>): Promise<any>;
484
+ /**
485
+ * Checks if a download is available from provided creator node endpoints
486
+ * @param endpoints creator node endpoints
487
+ * @param trackId
488
+ */
489
+ static checkIfDownloadAvailable(endpoints: string, trackId: number): Promise<any>;
490
+ web3Manager: Web3Manager;
491
+ creatorNodeEndpoint: string;
492
+ isServer: boolean;
493
+ userStateManager: UserStateManager;
494
+ lazyConnect: boolean;
495
+ schemas: Schemas;
496
+ passList: Set<string> | null;
497
+ blockList: Set<string> | null;
498
+ monitoringCallbacks: MonitoringCallbacks;
499
+ connected: boolean;
500
+ connecting: boolean;
501
+ authToken: null;
502
+ maxBlockNumber: number;
503
+ /**
504
+ * Constructs a service class for a creator node
505
+ * @param web3Manager
506
+ * @param creatorNodeEndpoint fallback creator node endpoint (to be deprecated)
507
+ * @param isServer
508
+ * @param userStateManager singleton UserStateManager instance
509
+ * @param lazyConnect whether or not to lazy connect (sign in) on load
510
+ * @param schemas
511
+ * @param passList whether or not to include only specified nodes (default null)
512
+ * @param blockList whether or not to exclude any nodes (default null)
513
+ * @param monitoringCallbacks callbacks to be invoked with metrics from requests sent to a service
514
+ */
515
+ constructor(web3Manager: Web3Manager, creatorNodeEndpoint: string, isServer: boolean, userStateManager: UserStateManager, lazyConnect: boolean, schemas: Schemas, passList?: Set<string> | null, blockList?: Set<string> | null, monitoringCallbacks?: MonitoringCallbacks);
516
+ init(): Promise<void>;
517
+ /** Establishes a connection to a content node endpoint */
518
+ connect(): Promise<void>;
519
+ /** Checks if connected, otherwise establishing a connection */
520
+ ensureConnected(): Promise<void>;
521
+ getEndpoint(): string;
522
+ /**
523
+ * Switch from one creatorNodeEndpoint to another including logging out from the old node, updating the endpoint and logging into new node */
524
+ setEndpoint(creatorNodeEndpoint: string): Promise<void>;
525
+ /** Clear all connection state in this class by deleting authToken and setting 'connected' = false */
526
+ clearConnection(): void;
527
+ /**
528
+ * Uploads creator content to a creator node
529
+ * @param metadata the creator metadata
530
+ */
531
+ uploadCreatorContent(metadata: Metadata, blockNumber?: null): Promise<any>;
532
+ /**
533
+ * Creates a creator on the creator node, associating user id with file content
534
+ * @param audiusUserId returned by user creation on-blockchain
535
+ * @param metadataFileUUID unique ID for metadata file
536
+ * @param blockNumber
537
+ */
538
+ associateCreator(audiusUserId: number, metadataFileUUID: string, blockNumber: number): Promise<void>;
539
+ /**
540
+ * Uploads a track (including audio and image content) to a creator node
541
+ * @param trackFile the audio content
542
+ * @param coverArtFile the image content
543
+ * @param metadata the metadata for the track
544
+ * @param onProgress an optional on progress callback
545
+ */
546
+ uploadTrackContent(trackFile: File, coverArtFile: File, metadata: Metadata, onProgress?: ProgressCB): Promise<any>;
547
+ /**
548
+ * Uploads track metadata to a creator node
549
+ * The metadata object must include a `track_id` field or a
550
+ * source file must be provided (returned from uploading track content).
551
+ * @param metadata
552
+ * @param sourceFile
553
+ */
554
+ uploadTrackMetadata(metadata: Metadata, sourceFile: string): Promise<any>;
555
+ /**
556
+ * Creates a track on the content node, associating track id with file content
557
+ * @param audiusTrackId returned by track creation on-blockchain
558
+ * @param metadataFileUUID unique ID for metadata file
559
+ * @param blockNumber
560
+ * @param transcodedTrackUUID the CID for the transcoded master if this is a first-time upload
561
+ */
562
+ associateTrack(audiusTrackId: number, metadataFileUUID: string, blockNumber: number, transcodedTrackUUID: string): Promise<void>;
563
+ /**
564
+ * Uploads an image to the connected content node
565
+ * @param file image to upload
566
+ * @param onProgress called with loaded bytes and total bytes
567
+ * @param timeoutMs timeout in ms axios request to upload file to CN will wait
568
+ * @return response body
569
+ */
570
+ uploadImage(file: File, square: boolean | undefined, onProgress: ProgressCB, timeoutMs?: number | null): Promise<{
571
+ uuid: string;
572
+ }>;
573
+ /**
574
+ * @param file track to upload
575
+ * @param onProgress called with loaded bytes and total bytes
576
+ * @return response body
577
+ */
578
+ uploadTrackAudio(file: File, onProgress: ProgressCB): Promise<any>;
579
+ handleAsyncTrackUpload(file: File, onProgress: ProgressCB): Promise<any>;
580
+ pollProcessingStatus(uuid: string): Promise<any>;
581
+ /**
582
+ * Gets the task progress given the task type and uuid associated with the task
583
+ * @param uuid the uuid of the track transcoding task
584
+ * @returns the status, and the success or failed response if the task is complete
585
+ */
586
+ getTrackContentProcessingStatus(uuid: string): Promise<any>;
587
+ /**
588
+ * Given a particular endpoint to a creator node, check whether
589
+ * this user has a sync in progress on that node.
590
+ * @param endpoint
591
+ * @param timeout ms
592
+ */
593
+ getSyncStatus(endpoint: string, timeout?: number | null): Promise<{
594
+ status: any;
595
+ userBlockNumber: number;
596
+ trackBlockNumber: number;
597
+ isBehind: boolean;
598
+ isConfigured: boolean;
599
+ }>;
600
+ /**
601
+ * Syncs a secondary creator node for a given user
602
+ * @param secondary
603
+ * @param primary specific primary to use
604
+ * @param immediate whether or not this is a blocking request and handled right away
605
+ * @param validate whether or not to validate the provided secondary is valid
606
+ */
607
+ syncSecondary(secondary: string, primary?: string, immediate?: boolean, validate?: boolean): Promise<axios.AxiosResponse<any> | undefined>;
608
+ /**
609
+ * Signs up a creator node user with a wallet address
610
+ * @param walletAddress
611
+ */
612
+ _signupNodeUser(walletAddress: string): Promise<void>;
613
+ /**
614
+ * Logs user into cnode, if not already logged in.
615
+ * Requests a challenge from cnode, sends signed challenge response to cn.
616
+ * If successful, receive and set authToken locally.
617
+ */
618
+ _loginNodeUser(): Promise<void>;
619
+ /** Calls logout on the content node. Needs an authToken for this since logout is an authenticated endpoint */
620
+ _logoutNodeUser(): Promise<void>;
621
+ /**
622
+ * Gets and returns the clock values across the replica set for the wallet in userStateManager.
623
+ * @returns Array of objects with the structure:
624
+ *
625
+ * {
626
+ * type: 'primary' or 'secondary',
627
+ * endpoint: <Content Node endpoint>,
628
+ * clockValue: clock value (should be an integer) or null
629
+ * }
630
+ *
631
+ * 'clockValue' may be null if the request to fetch the clock value fails
632
+ */
633
+ getClockValuesFromReplicaSet(): Promise<{
634
+ type: string;
635
+ endpoint: string;
636
+ clockValue: any;
637
+ }[] | undefined>;
638
+ /**
639
+ * Wrapper around getClockValue() to return either a proper or null clock value
640
+ * @param {Object} param
641
+ * @param {Object} param.user user metadata object from userStateManager
642
+ * @param {string} param.endpoint the Content Node endpoint to check the clock value for
643
+ * @param {number?} [param.timeout=1000] the max time allotted for a clock request; defaulted to 1000ms
644
+ */
645
+ _clockValueRequest({ user, endpoint, timeout }: ClockValueRequestConfig): Promise<{
646
+ type: string;
647
+ endpoint: string;
648
+ clockValue: any;
649
+ }>;
650
+ /**
651
+ * Makes an axios request to the connected creator node.
652
+ * @param requiresConnection if set, the currently configured creator node
653
+ * is connected to before the request is made.
654
+ * @return response body
655
+ */
656
+ _makeRequest(axiosRequestObj: AxiosRequestConfig, requiresConnection?: boolean): Promise<any>;
657
+ /**
658
+ * Create headers and formData for file upload
659
+ * @param file the file to upload
660
+ * @returns headers and formData in an object
661
+ */
662
+ createFormDataAndUploadHeaders(file: File, extraFormDataOptions?: Record<string, unknown>): {
663
+ headers: Record<string, string | null>;
664
+ formData: FormData;
665
+ };
666
+ /**
667
+ * Uploads a file to the connected creator node.
668
+ * @param file
669
+ * @param route route to handle upload (image_upload, track_upload, etc.)
670
+ * @param onProgress called with loaded bytes and total bytes
671
+ * @param extraFormDataOptions extra FormData fields passed to the upload
672
+ * @param retries max number of attempts made for axios request to upload file to CN before erroring
673
+ * @param timeoutMs timeout in ms axios request to upload file to CN will wait
674
+ */
675
+ _uploadFile(file: File, route: string, onProgress?: ProgressCB, extraFormDataOptions?: Record<string, unknown>, retries?: number, timeoutMs?: number | null): Promise<FileUploadResponse>;
676
+ _handleErrorHelper(e: Error | AxiosError, requestUrl?: string, requestId?: string | null): Promise<void>;
677
+ }
678
+
679
+ type Options = { skipRollover: boolean }
680
+
681
+ declare class SanityChecks {
682
+ libs: any
683
+ options: Options
684
+
685
+ constructor(libsInstance: any, options?: Options): void
686
+ async run(creatorNodeWhitelist: string[] | null): Promise<void>
687
+ }
688
+
689
+ export { CreatorNode, SanityChecks, Utils };