@campnetwork/origin 1.0.0-alpha.9 → 1.0.1-alpha.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.
- package/LICENSE +21 -21
- package/README.md +1073 -1139
- package/dist/core.cjs +71 -72
- package/dist/core.d.ts +9 -5
- package/dist/core.esm.d.ts +9 -5
- package/dist/core.esm.js +76 -77
- package/dist/react/index.esm.d.ts +9 -7
- package/dist/react/index.esm.js +282 -185
- package/package.json +95 -73
package/README.md
CHANGED
|
@@ -1,1139 +1,1073 @@
|
|
|
1
|
-
<p align="center">
|
|
2
|
-
<img src="https://imgur.com/7nLZezD.png" height="200px"/>
|
|
3
|
-
</p>
|
|
4
|
-
<br/>
|
|
5
|
-
|
|
6
|
-
<p align="center">
|
|
7
|
-
<a href="https://www.npmjs.com/package/@campnetwork/origin"><img src="https://img.shields.io/npm/v/@campnetwork/origin?style=for-the-badge" alt="npm version"/></a>
|
|
8
|
-
<img alt="GitHub License" src="https://img.shields.io/github/license/campaign-layer/camp-sdk?style=for-the-badge">
|
|
9
|
-
<img src="https://img.shields.io/npm/last-update/%40campnetwork%2Forigin?style=for-the-badge" alt="npm last update"/>
|
|
10
|
-
<img alt="NPM Downloads" src="https://img.shields.io/npm/d18m/%40campnetwork%2Forigin?style=for-the-badge">
|
|
11
|
-
</p>
|
|
12
|
-
|
|
13
|
-
# Origin SDK
|
|
14
|
-
|
|
15
|
-
The Origin SDK currently exposes the following modules:
|
|
16
|
-
|
|
17
|
-
- `"@campnetwork/origin"` - The main entry point for the SDK, exposes the following classes:
|
|
18
|
-
- `TwitterAPI` - For fetching user Twitter data from
|
|
19
|
-
- `SpotifyAPI` - For fetching user Spotify data from
|
|
20
|
-
- `Auth` - For authenticating users with the Origin SDK
|
|
21
|
-
- `"@campnetwork/origin/react"` - Exposes the CampProvider and CampContext, as well as React components and hooks for authentication and fetching user data via
|
|
22
|
-
|
|
23
|
-
# Installation
|
|
24
|
-
|
|
25
|
-
```bash
|
|
26
|
-
npm install @campnetwork/origin
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
# Core
|
|
30
|
-
|
|
31
|
-
The core modules can be imported either as a CommonJS module or as an ES6 module.
|
|
32
|
-
|
|
33
|
-
### CommonJS
|
|
34
|
-
|
|
35
|
-
```js
|
|
36
|
-
const { TwitterAPI, SpotifyAPI, Auth } = require("@campnetwork/origin");
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### ES6
|
|
40
|
-
|
|
41
|
-
```js
|
|
42
|
-
import { TwitterAPI, SpotifyAPI, Auth } from "@campnetwork/origin";
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
## Socials
|
|
46
|
-
|
|
47
|
-
### TwitterAPI
|
|
48
|
-
|
|
49
|
-
The TwitterAPI class is the entry point for fetching user Twitter data from
|
|
50
|
-
|
|
51
|
-
**Note: The methods for fetching data will only return data for users who have authenticated to your app via the Origin SDK.**
|
|
52
|
-
|
|
53
|
-
#### Constructor
|
|
54
|
-
|
|
55
|
-
`apiKey` - The API key of your app.
|
|
56
|
-
|
|
57
|
-
```js
|
|
58
|
-
const twitter = new TwitterAPI({
|
|
59
|
-
apiKey: string,
|
|
60
|
-
});
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
#### Methods
|
|
64
|
-
|
|
65
|
-
##### fetchUserByUsername
|
|
66
|
-
|
|
67
|
-
`fetchUserByUsername(twitterUserName: string)`
|
|
68
|
-
|
|
69
|
-
```js
|
|
70
|
-
const user = await twitter.fetchUserByUsername("jack");
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
##### fetchTweetsByUsername
|
|
74
|
-
|
|
75
|
-
`fetchTweetsByUsername(twitterUserName: string, page: number, limit: number)`
|
|
76
|
-
|
|
77
|
-
```js
|
|
78
|
-
const tweets = await twitter.fetchTweetsByUsername("jack", 1, 10);
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
##### fetchFollowersByUsername
|
|
82
|
-
|
|
83
|
-
`fetchFollowersByUsername(twitterUserName: string, page: number, limit: number)`
|
|
84
|
-
|
|
85
|
-
```js
|
|
86
|
-
const followers = await twitter.fetchFollowersByUsername("jack", 1, 10);
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
##### fetchFollowingByUsername
|
|
90
|
-
|
|
91
|
-
`fetchFollowingByUsername(twitterUserName: string, page: number, limit: number)`
|
|
92
|
-
|
|
93
|
-
```js
|
|
94
|
-
const following = await twitter.fetchFollowingByUsername("jack", 1, 10);
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
##### fetchTweetById
|
|
98
|
-
|
|
99
|
-
`fetchTweetById(tweetId: string)`
|
|
100
|
-
|
|
101
|
-
```js
|
|
102
|
-
const tweet = await twitter.fetchTweetById("1234567890");
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
##### fetchUserByWalletAddress
|
|
106
|
-
|
|
107
|
-
`fetchUserByWalletAddress(walletAddress: string, page: number, limit: number)`
|
|
108
|
-
|
|
109
|
-
```js
|
|
110
|
-
const user = await twitter.fetchUserByWalletAddress("0x1234567890", 1, 10);
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
##### fetchRepostedByUsername
|
|
114
|
-
|
|
115
|
-
`fetchRepostedByUsername(twitterUserName: string, page: number, limit: number)`
|
|
116
|
-
|
|
117
|
-
```js
|
|
118
|
-
const reposts = await twitter.fetchRepostedByUsername("jack", 1, 10);
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
##### fetchRepliesByUsername
|
|
122
|
-
|
|
123
|
-
`fetchRepliesByUsername(twitterUserName: string, page: number, limit: number)`
|
|
124
|
-
|
|
125
|
-
```js
|
|
126
|
-
const replies = await twitter.fetchRepliesByUsername("jack", 1, 10);
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
##### fetchLikesByUsername
|
|
130
|
-
|
|
131
|
-
`fetchLikesByUsername(twitterUserName: string, page: number, limit: number)`
|
|
132
|
-
|
|
133
|
-
```js
|
|
134
|
-
const likes = await twitter.fetchLikesByUsername("jack", 1, 10);
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
##### fetchFollowsByUsername
|
|
138
|
-
|
|
139
|
-
`fetchFollowsByUsername(twitterUserName: string, page: number, limit: number)`
|
|
140
|
-
|
|
141
|
-
```js
|
|
142
|
-
const follows = await twitter.fetchFollowsByUsername("jack", 1, 10);
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
##### fetchViewedTweetsByUsername
|
|
146
|
-
|
|
147
|
-
`fetchViewedTweetsByUsername(twitterUserName: string, page: number, limit: number)`
|
|
148
|
-
|
|
149
|
-
```js
|
|
150
|
-
const viewedTweets = await twitter.fetchViewedTweetsByUsername("jack", 1, 10);
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
### SpotifyAPI
|
|
154
|
-
|
|
155
|
-
The SpotifyAPI class is the entry point for fetching user Spotify data from
|
|
156
|
-
|
|
157
|
-
**Note: The methods for fetching data will only return data for users who have authenticated to your app via the Origin SDK.**
|
|
158
|
-
|
|
159
|
-
#### Constructor
|
|
160
|
-
|
|
161
|
-
`apiKey` - The API key of your app.
|
|
162
|
-
|
|
163
|
-
```js
|
|
164
|
-
const spotify = new SpotifyAPI({
|
|
165
|
-
apiKey: string,
|
|
166
|
-
});
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
#### Methods
|
|
170
|
-
|
|
171
|
-
##### fetchSavedTracksById
|
|
172
|
-
|
|
173
|
-
`fetchSavedTracksById(spotifyId: string)`
|
|
174
|
-
|
|
175
|
-
```js
|
|
176
|
-
const savedTracks = await spotify.fetchSavedTracksById("1234567890");
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
##### fetchPlayedTracksById
|
|
180
|
-
|
|
181
|
-
`fetchPlayedTracksById(spotifyId: string)`
|
|
182
|
-
|
|
183
|
-
```js
|
|
184
|
-
const playedTracks = await spotify.fetchPlayedTracksById("1234567890");
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
##### fetchSavedAlbumsById
|
|
188
|
-
|
|
189
|
-
`fetchSavedAlbumsById(spotifyId: string)`
|
|
190
|
-
|
|
191
|
-
```js
|
|
192
|
-
const savedAlbums = await spotify.fetchSavedAlbumsById("1234567890");
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
##### fetchSavedPlaylistsById
|
|
196
|
-
|
|
197
|
-
`fetchSavedPlaylistsById(spotifyId: string)`
|
|
198
|
-
|
|
199
|
-
```js
|
|
200
|
-
const savedPlaylists = await spotify.fetchSavedPlaylistsById("1234567890");
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
##### fetchTracksInAlbum
|
|
204
|
-
|
|
205
|
-
`fetchTracksInAlbum(spotifyId: string, albumId: string)`
|
|
206
|
-
|
|
207
|
-
```js
|
|
208
|
-
const tracks = await spotify.fetchTracksInAlbum("1234567890", "1234567890");
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
##### fetchTracksInPlaylist
|
|
212
|
-
|
|
213
|
-
`fetchTracksInPlaylist(spotifyId: string, playlistId: string)`
|
|
214
|
-
|
|
215
|
-
```js
|
|
216
|
-
const tracks = await spotify.fetchTracksInPlaylist("1234567890", "1234567890");
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
##### fetchUserByWalletAddress
|
|
220
|
-
|
|
221
|
-
`fetchUserByWalletAddress(walletAddress: string)`
|
|
222
|
-
|
|
223
|
-
```js
|
|
224
|
-
const user = await spotify.fetchUserByWalletAddress("0x1234567890");
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
### TikTokAPI
|
|
228
|
-
|
|
229
|
-
The TikTokAPI class is the entry point for fetching user TikTok data from
|
|
230
|
-
|
|
231
|
-
**Note: The methods for fetching data will only return data for users who have authenticated to your app via the Origin SDK.**
|
|
232
|
-
|
|
233
|
-
#### Constructor
|
|
234
|
-
|
|
235
|
-
`apiKey` - The API key of your app.
|
|
236
|
-
|
|
237
|
-
```js
|
|
238
|
-
const tiktok = new TikTokAPI({
|
|
239
|
-
apiKey: string,
|
|
240
|
-
});
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
#### Methods
|
|
244
|
-
|
|
245
|
-
##### fetchUserByUsername
|
|
246
|
-
|
|
247
|
-
`fetchUserByUsername(tiktokUserName: string)`
|
|
248
|
-
|
|
249
|
-
```js
|
|
250
|
-
const user = await tiktok.fetchUserByUsername("jack");
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
##### fetchVideoById
|
|
254
|
-
|
|
255
|
-
`fetchVideoById(userHandle: string, videoId: string)`
|
|
256
|
-
|
|
257
|
-
```js
|
|
258
|
-
const video = await tiktok.fetchVideo("jack", "1234567890");
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
## Auth
|
|
262
|
-
|
|
263
|
-
The Auth class is the entry point for authenticating users with the Origin SDK. It requires a clientId to be instantiated.
|
|
264
|
-
|
|
265
|
-
**Note: The Auth class is only to be used on the client side.**
|
|
266
|
-
|
|
267
|
-
### Constructor
|
|
268
|
-
|
|
269
|
-
- `clientId` - The client ID of your app. This is required to authenticate users with the Origin SDK.
|
|
270
|
-
- `redirectUri` - The URI to redirect to after the user completes oauth for any of the socials. Defaults to `window.location.href`.
|
|
271
|
-
The `redirectUri` can also be an object with the following optional properties:
|
|
272
|
-
- `twitter` - The URI to redirect to after the user completes oauth for Twitter.
|
|
273
|
-
- `
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
`
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
The `
|
|
470
|
-
|
|
471
|
-
```js
|
|
472
|
-
|
|
473
|
-
```
|
|
474
|
-
|
|
475
|
-
####
|
|
476
|
-
|
|
477
|
-
`
|
|
478
|
-
|
|
479
|
-
The `
|
|
480
|
-
|
|
481
|
-
```js
|
|
482
|
-
await auth.
|
|
483
|
-
```
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
`
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
```
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
<
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
```jsx
|
|
710
|
-
import {
|
|
711
|
-
|
|
712
|
-
function App() {
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
<
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
const
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
```
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
)
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
- `
|
|
955
|
-
- `
|
|
956
|
-
- `
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
- `
|
|
965
|
-
- `
|
|
966
|
-
- `
|
|
967
|
-
- `
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
- `
|
|
999
|
-
- `
|
|
1000
|
-
- `
|
|
1001
|
-
- `
|
|
1002
|
-
- `
|
|
1003
|
-
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
- `
|
|
1010
|
-
- `
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
####
|
|
1018
|
-
|
|
1019
|
-
- `
|
|
1020
|
-
- `
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
- `
|
|
1025
|
-
- `
|
|
1026
|
-
- `
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
- `
|
|
1031
|
-
- `
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
- `user.multiplier` - User's Origin multiplier
|
|
1075
|
-
- `user.points` - User's Origin points
|
|
1076
|
-
- `user.active` - Whether user's Origin is active
|
|
1077
|
-
- `teams` - Array of team data
|
|
1078
|
-
- `dataSources` - Array of data source information
|
|
1079
|
-
|
|
1080
|
-
#### `setOriginConsent(consent: boolean)`
|
|
1081
|
-
|
|
1082
|
-
Sets the user's consent for Origin usage.
|
|
1083
|
-
|
|
1084
|
-
- `consent`: `true` or `false`.
|
|
1085
|
-
- **Returns:** Promise that resolves on success, throws APIError on failure.
|
|
1086
|
-
|
|
1087
|
-
### Utility Methods
|
|
1088
|
-
|
|
1089
|
-
#### `getJwt()`
|
|
1090
|
-
|
|
1091
|
-
Gets the current JWT token.
|
|
1092
|
-
|
|
1093
|
-
- **Returns:** The JWT string.
|
|
1094
|
-
|
|
1095
|
-
#### `setViemClient(client: any)`
|
|
1096
|
-
|
|
1097
|
-
Sets the viem wallet client for blockchain interactions.
|
|
1098
|
-
|
|
1099
|
-
- `client`: The viem wallet client instance.
|
|
1100
|
-
|
|
1101
|
-
---
|
|
1102
|
-
|
|
1103
|
-
You can call these methods as `await auth.origin.methodName(...)` after authenticating with the SDK. For more details, see the inline code documentation.
|
|
1104
|
-
|
|
1105
|
-
# Contributing
|
|
1106
|
-
|
|
1107
|
-
Install the dependencies.
|
|
1108
|
-
|
|
1109
|
-
```bash
|
|
1110
|
-
npm install
|
|
1111
|
-
```
|
|
1112
|
-
|
|
1113
|
-
Build the SDK.
|
|
1114
|
-
|
|
1115
|
-
```bash
|
|
1116
|
-
npm run build
|
|
1117
|
-
```
|
|
1118
|
-
|
|
1119
|
-
This will generate the SDK in the `dist` folder.
|
|
1120
|
-
|
|
1121
|
-
You can also run the following command to watch for changes and rebuild the SDK automatically:
|
|
1122
|
-
|
|
1123
|
-
```bash
|
|
1124
|
-
npm run dev
|
|
1125
|
-
```
|
|
1126
|
-
|
|
1127
|
-
In order to use the sdk in a local project, you can link the sdk to the project.
|
|
1128
|
-
|
|
1129
|
-
```bash
|
|
1130
|
-
npm link
|
|
1131
|
-
```
|
|
1132
|
-
|
|
1133
|
-
Then, in the project you want to use the sdk in, run:
|
|
1134
|
-
|
|
1135
|
-
```bash
|
|
1136
|
-
npm link @campnetwork/origin
|
|
1137
|
-
```
|
|
1138
|
-
|
|
1139
|
-
This will link the local sdk to the project.
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://imgur.com/7nLZezD.png" height="200px"/>
|
|
3
|
+
</p>
|
|
4
|
+
<br/>
|
|
5
|
+
|
|
6
|
+
<p align="center">
|
|
7
|
+
<a href="https://www.npmjs.com/package/@campnetwork/origin"><img src="https://img.shields.io/npm/v/@campnetwork/origin?style=for-the-badge" alt="npm version"/></a>
|
|
8
|
+
<img alt="GitHub License" src="https://img.shields.io/github/license/campaign-layer/camp-sdk?style=for-the-badge">
|
|
9
|
+
<img src="https://img.shields.io/npm/last-update/%40campnetwork%2Forigin?style=for-the-badge" alt="npm last update"/>
|
|
10
|
+
<img alt="NPM Downloads" src="https://img.shields.io/npm/d18m/%40campnetwork%2Forigin?style=for-the-badge">
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
# Origin SDK
|
|
14
|
+
|
|
15
|
+
The Origin SDK currently exposes the following modules:
|
|
16
|
+
|
|
17
|
+
- `"@campnetwork/origin"` - The main entry point for the SDK, exposes the following classes:
|
|
18
|
+
- `TwitterAPI` - For fetching user Twitter data from Origin
|
|
19
|
+
- `SpotifyAPI` - For fetching user Spotify data from Origin
|
|
20
|
+
- `Auth` - For authenticating users with the Origin SDK
|
|
21
|
+
- `"@campnetwork/origin/react"` - Exposes the CampProvider and CampContext, as well as React components and hooks for authentication and fetching user data via Origin
|
|
22
|
+
|
|
23
|
+
# Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @campnetwork/origin
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
# Core
|
|
30
|
+
|
|
31
|
+
The core modules can be imported either as a CommonJS module or as an ES6 module.
|
|
32
|
+
|
|
33
|
+
### CommonJS
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
const { TwitterAPI, SpotifyAPI, Auth } = require("@campnetwork/origin");
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### ES6
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
import { TwitterAPI, SpotifyAPI, Auth } from "@campnetwork/origin";
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Socials
|
|
46
|
+
|
|
47
|
+
### TwitterAPI
|
|
48
|
+
|
|
49
|
+
The TwitterAPI class is the entry point for fetching user Twitter data from Origin. It requires an API key to be instantiated.
|
|
50
|
+
|
|
51
|
+
**Note: The methods for fetching data will only return data for users who have authenticated to your app via the Origin SDK.**
|
|
52
|
+
|
|
53
|
+
#### Constructor
|
|
54
|
+
|
|
55
|
+
`apiKey` - The API key of your app.
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
const twitter = new TwitterAPI({
|
|
59
|
+
apiKey: string,
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
#### Methods
|
|
64
|
+
|
|
65
|
+
##### fetchUserByUsername
|
|
66
|
+
|
|
67
|
+
`fetchUserByUsername(twitterUserName: string)`
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
const user = await twitter.fetchUserByUsername("jack");
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
##### fetchTweetsByUsername
|
|
74
|
+
|
|
75
|
+
`fetchTweetsByUsername(twitterUserName: string, page: number, limit: number)`
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
const tweets = await twitter.fetchTweetsByUsername("jack", 1, 10);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
##### fetchFollowersByUsername
|
|
82
|
+
|
|
83
|
+
`fetchFollowersByUsername(twitterUserName: string, page: number, limit: number)`
|
|
84
|
+
|
|
85
|
+
```js
|
|
86
|
+
const followers = await twitter.fetchFollowersByUsername("jack", 1, 10);
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
##### fetchFollowingByUsername
|
|
90
|
+
|
|
91
|
+
`fetchFollowingByUsername(twitterUserName: string, page: number, limit: number)`
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
const following = await twitter.fetchFollowingByUsername("jack", 1, 10);
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
##### fetchTweetById
|
|
98
|
+
|
|
99
|
+
`fetchTweetById(tweetId: string)`
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
const tweet = await twitter.fetchTweetById("1234567890");
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
##### fetchUserByWalletAddress
|
|
106
|
+
|
|
107
|
+
`fetchUserByWalletAddress(walletAddress: string, page: number, limit: number)`
|
|
108
|
+
|
|
109
|
+
```js
|
|
110
|
+
const user = await twitter.fetchUserByWalletAddress("0x1234567890", 1, 10);
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
##### fetchRepostedByUsername
|
|
114
|
+
|
|
115
|
+
`fetchRepostedByUsername(twitterUserName: string, page: number, limit: number)`
|
|
116
|
+
|
|
117
|
+
```js
|
|
118
|
+
const reposts = await twitter.fetchRepostedByUsername("jack", 1, 10);
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
##### fetchRepliesByUsername
|
|
122
|
+
|
|
123
|
+
`fetchRepliesByUsername(twitterUserName: string, page: number, limit: number)`
|
|
124
|
+
|
|
125
|
+
```js
|
|
126
|
+
const replies = await twitter.fetchRepliesByUsername("jack", 1, 10);
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
##### fetchLikesByUsername
|
|
130
|
+
|
|
131
|
+
`fetchLikesByUsername(twitterUserName: string, page: number, limit: number)`
|
|
132
|
+
|
|
133
|
+
```js
|
|
134
|
+
const likes = await twitter.fetchLikesByUsername("jack", 1, 10);
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
##### fetchFollowsByUsername
|
|
138
|
+
|
|
139
|
+
`fetchFollowsByUsername(twitterUserName: string, page: number, limit: number)`
|
|
140
|
+
|
|
141
|
+
```js
|
|
142
|
+
const follows = await twitter.fetchFollowsByUsername("jack", 1, 10);
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
##### fetchViewedTweetsByUsername
|
|
146
|
+
|
|
147
|
+
`fetchViewedTweetsByUsername(twitterUserName: string, page: number, limit: number)`
|
|
148
|
+
|
|
149
|
+
```js
|
|
150
|
+
const viewedTweets = await twitter.fetchViewedTweetsByUsername("jack", 1, 10);
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### SpotifyAPI
|
|
154
|
+
|
|
155
|
+
The SpotifyAPI class is the entry point for fetching user Spotify data from Origin. It requires an API key to be instantiated.
|
|
156
|
+
|
|
157
|
+
**Note: The methods for fetching data will only return data for users who have authenticated to your app via the Origin SDK.**
|
|
158
|
+
|
|
159
|
+
#### Constructor
|
|
160
|
+
|
|
161
|
+
`apiKey` - The API key of your app.
|
|
162
|
+
|
|
163
|
+
```js
|
|
164
|
+
const spotify = new SpotifyAPI({
|
|
165
|
+
apiKey: string,
|
|
166
|
+
});
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
#### Methods
|
|
170
|
+
|
|
171
|
+
##### fetchSavedTracksById
|
|
172
|
+
|
|
173
|
+
`fetchSavedTracksById(spotifyId: string)`
|
|
174
|
+
|
|
175
|
+
```js
|
|
176
|
+
const savedTracks = await spotify.fetchSavedTracksById("1234567890");
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
##### fetchPlayedTracksById
|
|
180
|
+
|
|
181
|
+
`fetchPlayedTracksById(spotifyId: string)`
|
|
182
|
+
|
|
183
|
+
```js
|
|
184
|
+
const playedTracks = await spotify.fetchPlayedTracksById("1234567890");
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
##### fetchSavedAlbumsById
|
|
188
|
+
|
|
189
|
+
`fetchSavedAlbumsById(spotifyId: string)`
|
|
190
|
+
|
|
191
|
+
```js
|
|
192
|
+
const savedAlbums = await spotify.fetchSavedAlbumsById("1234567890");
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
##### fetchSavedPlaylistsById
|
|
196
|
+
|
|
197
|
+
`fetchSavedPlaylistsById(spotifyId: string)`
|
|
198
|
+
|
|
199
|
+
```js
|
|
200
|
+
const savedPlaylists = await spotify.fetchSavedPlaylistsById("1234567890");
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
##### fetchTracksInAlbum
|
|
204
|
+
|
|
205
|
+
`fetchTracksInAlbum(spotifyId: string, albumId: string)`
|
|
206
|
+
|
|
207
|
+
```js
|
|
208
|
+
const tracks = await spotify.fetchTracksInAlbum("1234567890", "1234567890");
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
##### fetchTracksInPlaylist
|
|
212
|
+
|
|
213
|
+
`fetchTracksInPlaylist(spotifyId: string, playlistId: string)`
|
|
214
|
+
|
|
215
|
+
```js
|
|
216
|
+
const tracks = await spotify.fetchTracksInPlaylist("1234567890", "1234567890");
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
##### fetchUserByWalletAddress
|
|
220
|
+
|
|
221
|
+
`fetchUserByWalletAddress(walletAddress: string)`
|
|
222
|
+
|
|
223
|
+
```js
|
|
224
|
+
const user = await spotify.fetchUserByWalletAddress("0x1234567890");
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### TikTokAPI
|
|
228
|
+
|
|
229
|
+
The TikTokAPI class is the entry point for fetching user TikTok data from Origin. It requires an API key to be instantiated.
|
|
230
|
+
|
|
231
|
+
**Note: The methods for fetching data will only return data for users who have authenticated to your app via the Origin SDK.**
|
|
232
|
+
|
|
233
|
+
#### Constructor
|
|
234
|
+
|
|
235
|
+
`apiKey` - The API key of your app.
|
|
236
|
+
|
|
237
|
+
```js
|
|
238
|
+
const tiktok = new TikTokAPI({
|
|
239
|
+
apiKey: string,
|
|
240
|
+
});
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
#### Methods
|
|
244
|
+
|
|
245
|
+
##### fetchUserByUsername
|
|
246
|
+
|
|
247
|
+
`fetchUserByUsername(tiktokUserName: string)`
|
|
248
|
+
|
|
249
|
+
```js
|
|
250
|
+
const user = await tiktok.fetchUserByUsername("jack");
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
##### fetchVideoById
|
|
254
|
+
|
|
255
|
+
`fetchVideoById(userHandle: string, videoId: string)`
|
|
256
|
+
|
|
257
|
+
```js
|
|
258
|
+
const video = await tiktok.fetchVideo("jack", "1234567890");
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## Auth
|
|
262
|
+
|
|
263
|
+
The Auth class is the entry point for authenticating users with the Origin SDK. It requires a clientId to be instantiated.
|
|
264
|
+
|
|
265
|
+
**Note: The Auth class is only to be used on the client side.**
|
|
266
|
+
|
|
267
|
+
### Constructor
|
|
268
|
+
|
|
269
|
+
- `clientId` - The client ID of your app. This is required to authenticate users with the Origin SDK.
|
|
270
|
+
- `redirectUri` - The URI to redirect to after the user completes oauth for any of the socials. Defaults to `window.location.href`.
|
|
271
|
+
The `redirectUri` can also be an object with the following optional properties:
|
|
272
|
+
- `twitter` - The URI to redirect to after the user completes oauth for Twitter.
|
|
273
|
+
- `spotify` - The URI to redirect to after the user completes oauth for Spotify.
|
|
274
|
+
|
|
275
|
+
You may use the `redirectUri` object to redirect the user to different pages based on the social they are linking.
|
|
276
|
+
You may only define the URIs for the socials you are using, the rest will default to `window.location.href`.
|
|
277
|
+
|
|
278
|
+
```js
|
|
279
|
+
import { Auth } from "@campnetwork/origin";
|
|
280
|
+
|
|
281
|
+
const auth = new Auth({
|
|
282
|
+
clientId: string,
|
|
283
|
+
redirectUri: string | object,
|
|
284
|
+
allowAnalytics: boolean,
|
|
285
|
+
});
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
```js
|
|
289
|
+
const auth = new Auth({
|
|
290
|
+
clientId: "your-client-id",
|
|
291
|
+
redirectUri: {
|
|
292
|
+
twitter: "https://your-website.com/twitter",
|
|
293
|
+
spotify: "https://your-website.com/spotify",
|
|
294
|
+
},
|
|
295
|
+
});
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### Methods
|
|
299
|
+
|
|
300
|
+
#### connect
|
|
301
|
+
|
|
302
|
+
`connect() => void`
|
|
303
|
+
|
|
304
|
+
The `connect` method prompts the user to sign a message with their wallet in order to authenticate with the Origin SDK.
|
|
305
|
+
The wallet provider can be set by calling the `setProvider` method on the Auth instance beforehand. The default provider used is `window.ethereum`.
|
|
306
|
+
|
|
307
|
+
```js
|
|
308
|
+
auth.connect();
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
#### disconnect
|
|
312
|
+
|
|
313
|
+
`disconnect() => void`
|
|
314
|
+
|
|
315
|
+
The `disconnect` method logs the user out of the Origin SDK on the client side.
|
|
316
|
+
|
|
317
|
+
```js
|
|
318
|
+
auth.disconnect();
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
#### setProvider
|
|
322
|
+
|
|
323
|
+
`setProvider(provider: { provider: EIP1193Provider, info: EIP6963ProviderInfo, address?: string }) => void`
|
|
324
|
+
|
|
325
|
+
_Read more about the [EIP1193Provider](https://eips.ethereum.org/EIPS/eip-1193) and [EIP6963ProviderInfo](https://eips.ethereum.org/EIPS/eip-6963) interfaces._
|
|
326
|
+
|
|
327
|
+
The `setProvider` method sets the wallet provider to be used for authentication.
|
|
328
|
+
|
|
329
|
+
```js
|
|
330
|
+
auth.setProvider({
|
|
331
|
+
provider: window.ethereum,
|
|
332
|
+
info: { name: "MetaMask", icon: "https://..." },
|
|
333
|
+
});
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
#### setWalletAddress
|
|
337
|
+
|
|
338
|
+
`setWalletAddress(walletAddress: string) => void`
|
|
339
|
+
|
|
340
|
+
The `setWalletAddress` method sets the wallet address to be used for authentication (via the `connect` method).
|
|
341
|
+
|
|
342
|
+
**This is only needed if the provider does not support the `eth_requestAccounts` method. Only use this method if you are sure you need to set the wallet address manually.**
|
|
343
|
+
|
|
344
|
+
```js
|
|
345
|
+
auth.setWalletAddress("0x1234567890");
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
#### on
|
|
349
|
+
|
|
350
|
+
`on(event: string, callback: (data: any) => void) => void`
|
|
351
|
+
|
|
352
|
+
The `on` method listens for events emitted by the Auth module of the Origin SDK.
|
|
353
|
+
|
|
354
|
+
The following events are emitted:
|
|
355
|
+
|
|
356
|
+
##### "state"
|
|
357
|
+
|
|
358
|
+
Possible states:
|
|
359
|
+
|
|
360
|
+
- `authenticated` - The user has successfully authenticated.
|
|
361
|
+
- `unauthenticated` - The user has been logged out.
|
|
362
|
+
- `loading` - The user is in the process of authenticating.
|
|
363
|
+
|
|
364
|
+
```js
|
|
365
|
+
auth.on("state", (data) => {
|
|
366
|
+
console.log(data); // "authenticated" | "unauthenticated" | "loading"
|
|
367
|
+
});
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
##### "provider"
|
|
371
|
+
|
|
372
|
+
Returns the provider that has been set via the `setProvider` method.
|
|
373
|
+
If using the Origin SDK React components, this event is emitted when the user selects a provider in the Auth modal.
|
|
374
|
+
|
|
375
|
+
```js
|
|
376
|
+
auth.on("provider", (data) => {
|
|
377
|
+
console.log(data); // { provider: EIP1193Provider, info: EIP6963ProviderInfo }
|
|
378
|
+
});
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
##### "providers"
|
|
382
|
+
|
|
383
|
+
Returns the list of providers that have been injected via EIP6963 and that the user can select from.
|
|
384
|
+
|
|
385
|
+
```js
|
|
386
|
+
auth.on("providers", (data) => {
|
|
387
|
+
console.log(data); // [{ provider: EIP1193Provider, info: EIP6963ProviderInfo }]
|
|
388
|
+
});
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
You may use this event to update the UI with the available providers. The user can then select a provider to authenticate with, and the `setProvider` method can be called with the selected provider. The `connect` method can then be called to authenticate the user.
|
|
392
|
+
|
|
393
|
+
```js
|
|
394
|
+
auth.on("providers", (data) => {
|
|
395
|
+
// Update UI with providers
|
|
396
|
+
// User selects a provider
|
|
397
|
+
const selectedProvider = data[0];
|
|
398
|
+
|
|
399
|
+
auth.setProvider(selectedProvider);
|
|
400
|
+
|
|
401
|
+
auth.connect();
|
|
402
|
+
});
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
#### off
|
|
406
|
+
|
|
407
|
+
`off(event: string, callback: (data: any) => void) => void`
|
|
408
|
+
|
|
409
|
+
The `off` method unsubscribes from events emitted by the Auth module of the Origin SDK.
|
|
410
|
+
|
|
411
|
+
```js
|
|
412
|
+
auth.off("state", callback);
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
#### getLinkedSocials
|
|
416
|
+
|
|
417
|
+
`getLinkedSocials() => Promise<{ twitter: boolean, tiktok: boolean, spotify: boolean }>`
|
|
418
|
+
|
|
419
|
+
The `getLinkedSocials` method returns a promise that resolves to an object containing the possible socials that the user can link and whether they are linked or not.
|
|
420
|
+
|
|
421
|
+
```js
|
|
422
|
+
const linkedSocials = await auth.getLinkedSocials();
|
|
423
|
+
|
|
424
|
+
console.log(linkedSocials); // { twitter: true, tiktok: false, spotify: true }
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
---
|
|
428
|
+
|
|
429
|
+
After the user has authenticated, the following methods can be used to link and unlink social accounts.
|
|
430
|
+
When linking a social account, the user will be redirected to the OAuth flow for that social platform.
|
|
431
|
+
Afterwards, the user will be redirected back to the `redirectUri` specified in the Auth constructor.
|
|
432
|
+
|
|
433
|
+
#### linkTwitter
|
|
434
|
+
|
|
435
|
+
`linkTwitter() => void`
|
|
436
|
+
|
|
437
|
+
The `linkTwitter` method redirects the user to the Twitter OAuth flow to link their Twitter account to Origin.
|
|
438
|
+
|
|
439
|
+
```js
|
|
440
|
+
auth.linkTwitter();
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
#### linkSpotify
|
|
444
|
+
|
|
445
|
+
`linkSpotify() => void`
|
|
446
|
+
|
|
447
|
+
The `linkSpotify` method redirects the user to the Spotify OAuth flow to link their Spotify account to Origin.
|
|
448
|
+
|
|
449
|
+
```js
|
|
450
|
+
auth.linkSpotify();
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
#### linkTikTok
|
|
454
|
+
|
|
455
|
+
`linkTikTok(handle: string) => Promise<void>`
|
|
456
|
+
|
|
457
|
+
The `linkTikTok` method links the provided TikTok handle to Origin.
|
|
458
|
+
|
|
459
|
+
```js
|
|
460
|
+
auth.linkTikTok("tiktokhandle");
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
---
|
|
464
|
+
|
|
465
|
+
#### unlinkTwitter
|
|
466
|
+
|
|
467
|
+
`unlinkTwitter() => Promise<void>`
|
|
468
|
+
|
|
469
|
+
The `unlinkTwitter` method unlinks the user's Twitter account from Origin.
|
|
470
|
+
|
|
471
|
+
```js
|
|
472
|
+
await auth.unlinkTwitter();
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
#### unlinkSpotify
|
|
476
|
+
|
|
477
|
+
`unlinkSpotify() => Promise<void>`
|
|
478
|
+
|
|
479
|
+
The `unlinkSpotify` method unlinks the user's Spotify account from Origin.
|
|
480
|
+
|
|
481
|
+
```js
|
|
482
|
+
await auth.unlinkSpotify();
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
#### unlinkTikTok
|
|
486
|
+
|
|
487
|
+
`unlinkTikTok() => Promise<void>`
|
|
488
|
+
|
|
489
|
+
The `unlinkTikTok` method unlinks the user's TikTok account from Origin.
|
|
490
|
+
|
|
491
|
+
```js
|
|
492
|
+
await auth.unlinkTikTok();
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
# React
|
|
496
|
+
|
|
497
|
+
The React components and hooks can be imported as ES6 modules. The example below shows how to set up the `CampProvider` component and subsequently use the provided hooks and components.
|
|
498
|
+
|
|
499
|
+
```js
|
|
500
|
+
// main.jsx
|
|
501
|
+
import { StrictMode } from "react";
|
|
502
|
+
import { createRoot } from "react-dom/client";
|
|
503
|
+
import { CampProvider } from "@campnetwork/origin/react";
|
|
504
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
505
|
+
import App from "./App.jsx";
|
|
506
|
+
|
|
507
|
+
const queryClient = new QueryClient();
|
|
508
|
+
|
|
509
|
+
createRoot(document.getElementById("root")).render(
|
|
510
|
+
<StrictMode>
|
|
511
|
+
<QueryClientProvider client={queryClient}>
|
|
512
|
+
<CampProvider clientId="your-client-id">
|
|
513
|
+
<App />
|
|
514
|
+
</CampProvider>
|
|
515
|
+
</QueryClientProvider>
|
|
516
|
+
</StrictMode>
|
|
517
|
+
);
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
## CampProvider
|
|
521
|
+
|
|
522
|
+
The `CampProvider` component requires a `clientId` prop to be passed in order link the users to your app.
|
|
523
|
+
It can also take the following optional props:
|
|
524
|
+
|
|
525
|
+
- `redirectUri` - `string | object` - Either a string that will be used as the redirect URI for all socials, or an object with the following optional properties: `twitter`, `spotify`. This is used to redirect the user to different pages after they have completed the OAuth flow for a social.
|
|
526
|
+
- `environment` - `string` - The environment to use. Can be either `DEVELOPMENT` or `PRODUCTION`. Defaults to `DEVELOPMENT`.
|
|
527
|
+
- - the `DEVELOPMENT` environment uses the Camp Testnet while the `PRODUCTION` environment uses the Camp Mainnet.
|
|
528
|
+
|
|
529
|
+
```jsx
|
|
530
|
+
import { CampProvider } from "@campnetwork/origin/react";
|
|
531
|
+
// ...
|
|
532
|
+
function App() {
|
|
533
|
+
return (
|
|
534
|
+
<CampProvider
|
|
535
|
+
clientId="your-client-id"
|
|
536
|
+
redirectUri="https://your-website.com"
|
|
537
|
+
environment="DEVELOPMENT"
|
|
538
|
+
>
|
|
539
|
+
<div>Your app</div>
|
|
540
|
+
</CampProvider>
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
Or, with an object for the `redirectUri`:
|
|
546
|
+
|
|
547
|
+
```jsx
|
|
548
|
+
import { CampProvider } from "@campnetwork/origin/react";
|
|
549
|
+
// ...
|
|
550
|
+
function App() {
|
|
551
|
+
return (
|
|
552
|
+
<CampProvider
|
|
553
|
+
clientId="your-client-id"
|
|
554
|
+
redirectUri={{
|
|
555
|
+
twitter: "https://your-website.com/twitter",
|
|
556
|
+
spotify: "https://your-website.com/spotify",
|
|
557
|
+
}}
|
|
558
|
+
environment="DEVELOPMENT"
|
|
559
|
+
>
|
|
560
|
+
<div>Your app</div>
|
|
561
|
+
</CampProvider>
|
|
562
|
+
);
|
|
563
|
+
}
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
The `CampProvider` component sets up the context for the Origin SDK and provides the Auth instance to the rest of the app.
|
|
567
|
+
|
|
568
|
+
## CampModal
|
|
569
|
+
|
|
570
|
+

|
|
571
|
+
|
|
572
|
+
The **CampModal** is a one-line\* solution for authenticating users with the Origin SDK. It can be used to connect users to Origin, link and unlink social accounts, mint IPNFTs, and view the user's Origin stats.
|
|
573
|
+
|
|
574
|
+
It works as follows:
|
|
575
|
+
|
|
576
|
+
The **CampModal** component displays a button with the text "**Connect**" that the user can click on in order to summon the modal. The modal shows a list of available providers that the user can select from. After a provider has been selected, the `connect` method is called on the Auth instance to authenticate the user.
|
|
577
|
+
|
|
578
|
+
If the user is already authenticated, the button will instead say "**My Origin**" and the modal will display the user's Origin profile information and allow them to link and unlink social accounts.
|
|
579
|
+
|
|
580
|
+
The **CampModal** can take the following props:
|
|
581
|
+
|
|
582
|
+
- `wcProjectId` - `string` - The WalletConnect project ID to use for authentication. Allows the users to authenticate via WalletConnect.
|
|
583
|
+
- `injectButton` - `boolean` - Whether to inject the button into the DOM or not. Defaults to `true`. If set to `false`, the button will not be rendered and the modal can be opened programmatically via the `openModal` function returned by the `useModal` hook.
|
|
584
|
+
- `onlyWagmi` - `boolean` - Whether to only show the provider that the user is currently authenticated with. Defaults to `false`.
|
|
585
|
+
- `defaultProvider` - `{ provider: EIP1193Provider, info: EIP6963ProviderInfo, exclusive: boolean }` - Custom provider to set as the highlighted provider in the modal. If not set, the wagmi provider will be highlighted if it is available. The `exclusive` property can be set to `true` to only show this provider in the modal.
|
|
586
|
+
|
|
587
|
+
### Usage
|
|
588
|
+
|
|
589
|
+
Basic usage of the **CampModal** component:
|
|
590
|
+
|
|
591
|
+
```jsx
|
|
592
|
+
import { CampModal } from "@campnetwork/origin/react";
|
|
593
|
+
|
|
594
|
+
function App() {
|
|
595
|
+
return (
|
|
596
|
+
<div>
|
|
597
|
+
<CampModal />
|
|
598
|
+
</div>
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
With custom props:
|
|
604
|
+
|
|
605
|
+
```jsx
|
|
606
|
+
import { CampModal } from "@campnetwork/origin/react";
|
|
607
|
+
|
|
608
|
+
function App() {
|
|
609
|
+
return (
|
|
610
|
+
<div>
|
|
611
|
+
<CampModal
|
|
612
|
+
wcProjectId="your-wc-project-id"
|
|
613
|
+
defaultProvider={{
|
|
614
|
+
provider: window.ethereum,
|
|
615
|
+
info: { name: "MetaMask", icon: "https://..." },
|
|
616
|
+
exclusive: false,
|
|
617
|
+
}}
|
|
618
|
+
/>
|
|
619
|
+
</div>
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
```
|
|
623
|
+
|
|
624
|
+
You can find more [examples here](./examples/client-side/react/providers-configuration).
|
|
625
|
+
|
|
626
|
+
Only show the provider that the user is currently authenticated with (if using wagmi):
|
|
627
|
+
|
|
628
|
+
```jsx
|
|
629
|
+
import { CampModal } from "@campnetwork/origin/react";
|
|
630
|
+
|
|
631
|
+
function App() {
|
|
632
|
+
return (
|
|
633
|
+
<div>
|
|
634
|
+
<CampModal onlyWagmi />
|
|
635
|
+
</div>
|
|
636
|
+
);
|
|
637
|
+
}
|
|
638
|
+
```
|
|
639
|
+
|
|
640
|
+
Users can be authenticated either via the Camp Modal as outlined above or programmatically by calling the `connect` method on the Auth instance.
|
|
641
|
+
|
|
642
|
+
### Usage with third party providers (Privy, Appkit, Magic, etc.)
|
|
643
|
+
|
|
644
|
+
The Camp Modal can be used in conjunction with providers such as Privy and Appkit to create a seamless authentication experience for users. When using wagmi, it will automatically detect if the user is authenticated via a third party provider and give them the option to connect to Origin using that provider. Otherwise, you can set up the default provider to be whatever provider you are using.
|
|
645
|
+
|
|
646
|
+
[Example usage with Privy](./examples/client-side/react/privy-connector/)
|
|
647
|
+
|
|
648
|
+
[Example usage with Appkit](./examples/client-side/react/appkit-connector/)
|
|
649
|
+
|
|
650
|
+
[Example usage with magic.link](./examples/client-side/react/magic-link-connector/)
|
|
651
|
+
|
|
652
|
+
After the user has authenticated, you can use the provided hooks to fetch user data and listen for events.
|
|
653
|
+
|
|
654
|
+
## LinkButton
|
|
655
|
+
|
|
656
|
+
The **LinkButton** component is a button that can be used to link and unlink social accounts. Under the hood it uses the `useLinkModal` hook to open the Link Socials modal.
|
|
657
|
+
|
|
658
|
+
The **LinkButton** can take the following props:
|
|
659
|
+
|
|
660
|
+
- `social` - `string` - The social account to link or unlink. Can be one of: `twitter`, `tiktok`, `spotify`.
|
|
661
|
+
- `variant` - `string` - The variant of the button. Can be one of: `default`, `icon`. Defaults to `default`.
|
|
662
|
+
- `theme` - `string` - The theme of the button. Can be one of: `default`, `camp`. Defaults to `default`.
|
|
663
|
+
|
|
664
|
+
**Note: The `<CampModal/>` component must be rendered in the component tree for the buttons to work.**
|
|
665
|
+
|
|
666
|
+
### Usage
|
|
667
|
+
|
|
668
|
+
Basic usage of the **LinkButton** component:
|
|
669
|
+
|
|
670
|
+
```jsx
|
|
671
|
+
import { LinkButton, CampModal } from "@campnetwork/origin/react";
|
|
672
|
+
|
|
673
|
+
function App() {
|
|
674
|
+
return (
|
|
675
|
+
<div>
|
|
676
|
+
<CampModal />
|
|
677
|
+
<LinkButton social="twitter" />
|
|
678
|
+
<LinkButton social="spotify" theme="camp" />
|
|
679
|
+
<LinkButton social="tiktok" variant="icon" theme="camp" />
|
|
680
|
+
</div>
|
|
681
|
+
);
|
|
682
|
+
}
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
## CampButton
|
|
686
|
+
|
|
687
|
+
The **CampButton** component allows you to render a button that opens the Auth or My Origin modal when clicked. It can be used as an alternative to the button that is injected by the **CampModal** component. It allows you to have multiple buttons in your app that open the modal, or to have the button in a different location than where the **CampModal** component is rendered.
|
|
688
|
+
|
|
689
|
+
```jsx
|
|
690
|
+
import { CampButton, CampModal } from "@campnetwork/origin/react";
|
|
691
|
+
|
|
692
|
+
function App() {
|
|
693
|
+
return (
|
|
694
|
+
<div>
|
|
695
|
+
<CampModal injectButton={false} />
|
|
696
|
+
<CampButton />
|
|
697
|
+
</div>
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
```
|
|
701
|
+
|
|
702
|
+
## Hooks
|
|
703
|
+
|
|
704
|
+
### useAuth
|
|
705
|
+
|
|
706
|
+
The `useAuth` hook returns the instance of the Auth class that is provided by the CampProvider.
|
|
707
|
+
It can be used as outlined in the Core section in order to build custom authentication flows, listen for events, and fetch user data.
|
|
708
|
+
|
|
709
|
+
```jsx
|
|
710
|
+
import { useAuth } from "@campnetwork/origin/react";
|
|
711
|
+
|
|
712
|
+
function App() {
|
|
713
|
+
const auth = useAuth();
|
|
714
|
+
|
|
715
|
+
return (
|
|
716
|
+
<div>
|
|
717
|
+
<button onClick={auth.connect}>Connect</button>
|
|
718
|
+
</div>
|
|
719
|
+
);
|
|
720
|
+
}
|
|
721
|
+
```
|
|
722
|
+
|
|
723
|
+
### useAuthState
|
|
724
|
+
|
|
725
|
+
The `useAuthState` hook returns the current authentication state of the user.
|
|
726
|
+
|
|
727
|
+
```jsx
|
|
728
|
+
import { useAuthState } from "@campnetwork/origin/react";
|
|
729
|
+
|
|
730
|
+
function App() {
|
|
731
|
+
const { authenticated, loading } = useAuthState();
|
|
732
|
+
|
|
733
|
+
return (
|
|
734
|
+
<div>
|
|
735
|
+
{loading && <div>Loading...</div>}
|
|
736
|
+
{authenticated && <div>Authenticated</div>}
|
|
737
|
+
</div>
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
```
|
|
741
|
+
|
|
742
|
+
### useProvider
|
|
743
|
+
|
|
744
|
+
The `useProvider` hook returns the provider that has been set via the `setProvider` method, as well as a `setProvider` function that can be used to update the provider.
|
|
745
|
+
|
|
746
|
+
```jsx
|
|
747
|
+
import { useProvider } from "@campnetwork/origin/react";
|
|
748
|
+
|
|
749
|
+
function App() {
|
|
750
|
+
const { provider, setProvider } = useProvider();
|
|
751
|
+
|
|
752
|
+
return (
|
|
753
|
+
<div>
|
|
754
|
+
<div>Current provider: {provider.info.name}</div>
|
|
755
|
+
<button
|
|
756
|
+
onClick={() =>
|
|
757
|
+
setProvider({ provider: window.ethereum, info: { name: "Metamask" } })
|
|
758
|
+
}
|
|
759
|
+
>
|
|
760
|
+
Set Provider
|
|
761
|
+
</button>
|
|
762
|
+
</div>
|
|
763
|
+
);
|
|
764
|
+
}
|
|
765
|
+
```
|
|
766
|
+
|
|
767
|
+
### useProviders
|
|
768
|
+
|
|
769
|
+
The `useProviders` hook returns the list of providers that have been injected via EIP6963 and that the user or app can select from.
|
|
770
|
+
|
|
771
|
+
```jsx
|
|
772
|
+
import { useProviders, useProvider } from "@campnetwork/origin/react";
|
|
773
|
+
|
|
774
|
+
function App() {
|
|
775
|
+
const providers = useProviders();
|
|
776
|
+
const { setProvider } = useProvider();
|
|
777
|
+
|
|
778
|
+
return (
|
|
779
|
+
<div>
|
|
780
|
+
{providers.map((provider) => (
|
|
781
|
+
<button key={provider.info.name} onClick={() => setProvider(provider)}>
|
|
782
|
+
{provider.info.name}
|
|
783
|
+
</button>
|
|
784
|
+
))}
|
|
785
|
+
</div>
|
|
786
|
+
);
|
|
787
|
+
}
|
|
788
|
+
```
|
|
789
|
+
|
|
790
|
+
### useConnect
|
|
791
|
+
|
|
792
|
+
The `useConnect` hook returns functions that can be used to connect and disconnect the user.
|
|
793
|
+
|
|
794
|
+
```jsx
|
|
795
|
+
import { useConnect, useAuthState } from "@campnetwork/origin/react";
|
|
796
|
+
|
|
797
|
+
function App() {
|
|
798
|
+
const { connect, disconnect } = useConnect();
|
|
799
|
+
const { authenticated } = useAuthState();
|
|
800
|
+
|
|
801
|
+
return (
|
|
802
|
+
<div>
|
|
803
|
+
{authenticated ? (
|
|
804
|
+
<button onClick={disconnect}>Disconnect</button>
|
|
805
|
+
) : (
|
|
806
|
+
<button onClick={connect}>Connect</button>
|
|
807
|
+
)}
|
|
808
|
+
</div>
|
|
809
|
+
);
|
|
810
|
+
}
|
|
811
|
+
```
|
|
812
|
+
|
|
813
|
+
### useSocials
|
|
814
|
+
|
|
815
|
+
The `useSocials` hook returns the state of the user's linked social accounts.
|
|
816
|
+
|
|
817
|
+
```jsx
|
|
818
|
+
import { useSocials } from "@campnetwork/origin/react";
|
|
819
|
+
|
|
820
|
+
function App() {
|
|
821
|
+
const { data, error, isLoading } = useSocials();
|
|
822
|
+
|
|
823
|
+
if (loading) return <div>Loading...</div>;
|
|
824
|
+
if (error) return <div>Error: {error.message}</div>;
|
|
825
|
+
|
|
826
|
+
return (
|
|
827
|
+
<div>
|
|
828
|
+
<div>Twitter: {data.twitter ? "Linked" : "Not linked"}</div>
|
|
829
|
+
<div>Tiktok: {data.tiktok ? "Linked" : "Not linked"}</div>
|
|
830
|
+
<div>Spotify: {data.spotify ? "Linked" : "Not linked"}</div>
|
|
831
|
+
</div>
|
|
832
|
+
);
|
|
833
|
+
}
|
|
834
|
+
```
|
|
835
|
+
|
|
836
|
+
### useLinkSocials
|
|
837
|
+
|
|
838
|
+
The `useLinkSocials` hook returns functions that can be used to link and unlink social accounts.
|
|
839
|
+
|
|
840
|
+
```jsx
|
|
841
|
+
import { useLinkSocials } from "@campnetwork/origin/react";
|
|
842
|
+
|
|
843
|
+
function App() {
|
|
844
|
+
const {
|
|
845
|
+
linkTwitter,
|
|
846
|
+
linkSpotify,
|
|
847
|
+
linkTiktok,
|
|
848
|
+
unlinkTwitter,
|
|
849
|
+
unlinkSpotify,
|
|
850
|
+
unlinkTiktok,
|
|
851
|
+
} = useLinkSocials();
|
|
852
|
+
|
|
853
|
+
return (
|
|
854
|
+
<div>
|
|
855
|
+
<button onClick={linkTwitter}>Link Twitter</button>
|
|
856
|
+
<button onClick={linkSpotify}>Link Spotify</button>
|
|
857
|
+
<button onClick={() => linkTiktok("tiktokhandle")}>Link TikTok</button>
|
|
858
|
+
</button>
|
|
859
|
+
<button onClick={unlinkTwitter}>Unlink Twitter</button>
|
|
860
|
+
<button onClick={unlinkTiktok}>Unlink TikTok</button>
|
|
861
|
+
<button onClick={unlinkSpotify}>Unlink Spotify</button>
|
|
862
|
+
</div>
|
|
863
|
+
);
|
|
864
|
+
}
|
|
865
|
+
```
|
|
866
|
+
|
|
867
|
+
### useModal
|
|
868
|
+
|
|
869
|
+
The `useModal` hook returns the state of the Auth and My Origin modals, as well as functions to show and hide them.
|
|
870
|
+
|
|
871
|
+
**Note: The `<CampModal/>` component must be rendered in the component tree for the modals to be displayed.**
|
|
872
|
+
|
|
873
|
+
```jsx
|
|
874
|
+
import { useModal, CampModal } from "@campnetwork/origin/react";
|
|
875
|
+
|
|
876
|
+
function App() {
|
|
877
|
+
const { isOpen, openModal, closeModal } = useModal();
|
|
878
|
+
|
|
879
|
+
return (
|
|
880
|
+
<div>
|
|
881
|
+
<button onClick={openModal}>Open Modal</button>
|
|
882
|
+
<button onClick={closeModal}>Close Modal</button>
|
|
883
|
+
<CampModal injectButton={false} />
|
|
884
|
+
</div>
|
|
885
|
+
);
|
|
886
|
+
}
|
|
887
|
+
```
|
|
888
|
+
|
|
889
|
+
The state and functions returned by the `useModal` hook can be used to show and hide the Auth and My Origin modals, as well as to check if they are currently open. The modal being controlled is dictated by the user's authentication state.
|
|
890
|
+
|
|
891
|
+
### useLinkModal
|
|
892
|
+
|
|
893
|
+
The `useLinkModal` hook returns the state of the Link Socials modal, as well as functions to show and hide it.
|
|
894
|
+
|
|
895
|
+
**Note: The `<CampModal/>` component must be rendered in the component tree for the modal to be displayed.**
|
|
896
|
+
|
|
897
|
+
```jsx
|
|
898
|
+
import { useLinkModal, CampModal } from "@campnetwork/origin/react";
|
|
899
|
+
|
|
900
|
+
function App() {
|
|
901
|
+
const { isLinkingOpen, openTwitterModal } = useLinkModal();
|
|
902
|
+
|
|
903
|
+
return (
|
|
904
|
+
<div>
|
|
905
|
+
<CampModal />
|
|
906
|
+
<button onClick={openTwitterModal}>Link Twitter</button>
|
|
907
|
+
</div>
|
|
908
|
+
);
|
|
909
|
+
}
|
|
910
|
+
```
|
|
911
|
+
|
|
912
|
+
It returns the following properties and functions:
|
|
913
|
+
|
|
914
|
+
- `isLinkingOpen` - `boolean` - Whether the Link Socials modal is open or not.
|
|
915
|
+
- `openTwitterModal` - `() => void`
|
|
916
|
+
- `openSpotifyModal` - `() => void`
|
|
917
|
+
- `openTiktokModal` - `() => void`
|
|
918
|
+
- `linkTwitter` - `() => void`
|
|
919
|
+
- `linkSpotify` - `() => void`
|
|
920
|
+
- `linkTiktok` - `() => void`
|
|
921
|
+
- `linkTelegram` - `() => void`
|
|
922
|
+
- `unlinkTwitter` - `() => void`
|
|
923
|
+
- `unlinkSpotify` - `() => void`
|
|
924
|
+
- `unlinkTiktok` - `() => void`
|
|
925
|
+
- `closeModal` - `() => void`
|
|
926
|
+
|
|
927
|
+
The difference between the `openXModal` functions and the `linkX / unlinkX` functions is that the former opens the modal regardless of the user's linking state, allowing them to either link or unlink their account, while the latter only opens the specified modal if the user's linking state allows for it.
|
|
928
|
+
|
|
929
|
+
For example, if the user is linked to Twitter, calling `openTwitterModal` will open the modal to _unlink_ their Twitter account, while calling `linkTwitter` will not do anything, and calling `unlinkTwitter` will open the modal to unlink their Twitter account.
|
|
930
|
+
|
|
931
|
+
## Origin Methods (`auth.origin`)
|
|
932
|
+
|
|
933
|
+
The `Origin` class provides blockchain and API methods for interacting with Origin IpNFTs, uploading files, managing user stats, and more. Access these via `auth.origin` after authentication.
|
|
934
|
+
|
|
935
|
+
### Types
|
|
936
|
+
|
|
937
|
+
#### `LicenseTerms`
|
|
938
|
+
|
|
939
|
+
The license terms object used in minting and updating methods:
|
|
940
|
+
|
|
941
|
+
```typescript
|
|
942
|
+
type LicenseTerms = {
|
|
943
|
+
price: bigint; // Price in wei
|
|
944
|
+
duration: number; // Duration in seconds
|
|
945
|
+
royaltyBps: number; // Royalty in basis points (1-10000)
|
|
946
|
+
paymentToken: Address; // Payment token address (address(0) for native currency)
|
|
947
|
+
};
|
|
948
|
+
```
|
|
949
|
+
|
|
950
|
+
### Minting Constraints
|
|
951
|
+
|
|
952
|
+
When minting or updating an IpNFT, the following constraints apply to the `LicenseTerms`:
|
|
953
|
+
|
|
954
|
+
- The price must be at least `1000000000000000` wei (0.001 $CAMP).
|
|
955
|
+
- The royaltyBps must be between `1` and `10000` (0.01% to 100%).
|
|
956
|
+
- The duration must be at least `86400` seconds (1 day).
|
|
957
|
+
|
|
958
|
+
### File Upload & Minting
|
|
959
|
+
|
|
960
|
+
#### `mintFile(file, metadata, license, parents?, options?)`
|
|
961
|
+
|
|
962
|
+
Uploads a file and mints an IpNFT for it.
|
|
963
|
+
|
|
964
|
+
- `file`: File to upload and mint
|
|
965
|
+
- `metadata`: Additional metadata for the IpNFT
|
|
966
|
+
- `name`: Name of the IpNFT
|
|
967
|
+
- `description`: Description of the IpNFT
|
|
968
|
+
- `image`: Optional image URL for the IpNFT
|
|
969
|
+
- `attributes`: Optional array of attributes
|
|
970
|
+
- `license`: LicenseTerms object
|
|
971
|
+
- `parents`: Optional array of parent token IDs for derivatives
|
|
972
|
+
- `options.progressCallback`: Optional progress callback
|
|
973
|
+
- **Returns:** Minted token ID as a string, or throws on failure
|
|
974
|
+
|
|
975
|
+
#### `mintSocial(source, metadata, license)`
|
|
976
|
+
|
|
977
|
+
Mints an IpNFT for a connected social account.
|
|
978
|
+
|
|
979
|
+
- `source`: Social platform (`"spotify" | "twitter" | "tiktok"`)
|
|
980
|
+
- `metadata`: Additional metadata for the IpNFT
|
|
981
|
+
- `license`: LicenseTerms object
|
|
982
|
+
- **Returns:** Minted token ID as a string, or throws on failure
|
|
983
|
+
|
|
984
|
+
### IpNFT & Marketplace Methods
|
|
985
|
+
|
|
986
|
+
Most methods mirror smart contract functions and require appropriate permissions.
|
|
987
|
+
|
|
988
|
+
#### Core IpNFT Methods
|
|
989
|
+
|
|
990
|
+
- `mintWithSignature(account, tokenId, parents, creatorContentHash, uri, license, deadline, signature)`
|
|
991
|
+
- `registerIpNFT(source, deadline, license, metadata, fileKey?, parents?)`
|
|
992
|
+
- `updateTerms(tokenId, license)`
|
|
993
|
+
- `finalizeDelete(tokenId)`
|
|
994
|
+
- `getOrCreateRoyaltyVault(tokenId)`
|
|
995
|
+
- `getTerms(tokenId)`
|
|
996
|
+
- `ownerOf(tokenId)`
|
|
997
|
+
- `balanceOf(owner)`
|
|
998
|
+
- `tokenURI(tokenId)`
|
|
999
|
+
- `dataStatus(tokenId)`
|
|
1000
|
+
- `isApprovedForAll(owner, operator)`
|
|
1001
|
+
- `transferFrom(from, to, tokenId)`
|
|
1002
|
+
- `safeTransferFrom(from, to, tokenId)`
|
|
1003
|
+
- `approve(to, tokenId)`
|
|
1004
|
+
- `setApprovalForAll(operator, approved)`
|
|
1005
|
+
|
|
1006
|
+
#### Marketplace Methods
|
|
1007
|
+
|
|
1008
|
+
- `buyAccess(tokenId, periods, value?)`
|
|
1009
|
+
- `hasAccess(tokenId, user)`
|
|
1010
|
+
- `subscriptionExpiry(tokenId, user)`
|
|
1011
|
+
|
|
1012
|
+
#### Utility & Royalty Methods
|
|
1013
|
+
|
|
1014
|
+
- `getRoyalties(token?, owner?)` — Get royalty vault and balance
|
|
1015
|
+
- `claimRoyalties(token?, owner?)` — Claim royalties
|
|
1016
|
+
|
|
1017
|
+
#### Smart Access & Data
|
|
1018
|
+
|
|
1019
|
+
- `buyAccessSmart(tokenId)` — Buys access, handles payment approval and license details
|
|
1020
|
+
- `getData(tokenId)` — Fetches metadata for a given IpNFT
|
|
1021
|
+
|
|
1022
|
+
### User Data & Stats
|
|
1023
|
+
|
|
1024
|
+
- `getOriginUploads()` — Fetch user's Origin file uploads (returns array or null)
|
|
1025
|
+
- `getOriginUsage()` — Fetch user's Origin stats (returns object with multiplier, points, active, teams, dataSources)
|
|
1026
|
+
- `setOriginConsent(consent: boolean)` — Set user's consent for Origin usage
|
|
1027
|
+
|
|
1028
|
+
### Utility Methods
|
|
1029
|
+
|
|
1030
|
+
- `getJwt()` — Get current JWT token
|
|
1031
|
+
- `setViemClient(client)` — Set viem wallet client for blockchain interactions
|
|
1032
|
+
|
|
1033
|
+
---
|
|
1034
|
+
|
|
1035
|
+
Call these methods as `await auth.origin.methodName(...)` after authenticating. See inline code documentation for full details and parameter types.
|
|
1036
|
+
|
|
1037
|
+
---
|
|
1038
|
+
|
|
1039
|
+
# Contributing
|
|
1040
|
+
|
|
1041
|
+
Install the dependencies.
|
|
1042
|
+
|
|
1043
|
+
```bash
|
|
1044
|
+
npm install
|
|
1045
|
+
```
|
|
1046
|
+
|
|
1047
|
+
Build the SDK.
|
|
1048
|
+
|
|
1049
|
+
```bash
|
|
1050
|
+
npm run build
|
|
1051
|
+
```
|
|
1052
|
+
|
|
1053
|
+
This will generate the SDK in the `dist` folder.
|
|
1054
|
+
|
|
1055
|
+
You can also run the following command to watch for changes and rebuild the SDK automatically:
|
|
1056
|
+
|
|
1057
|
+
```bash
|
|
1058
|
+
npm run dev
|
|
1059
|
+
```
|
|
1060
|
+
|
|
1061
|
+
In order to use the sdk in a local project, you can link the sdk to the project.
|
|
1062
|
+
|
|
1063
|
+
```bash
|
|
1064
|
+
npm link .
|
|
1065
|
+
```
|
|
1066
|
+
|
|
1067
|
+
Then, in the project you want to use the sdk in, run:
|
|
1068
|
+
|
|
1069
|
+
```bash
|
|
1070
|
+
npm link @campnetwork/origin
|
|
1071
|
+
```
|
|
1072
|
+
|
|
1073
|
+
This will link the local sdk to the project.
|