@campnetwork/origin 1.0.0-alpha.12 → 1.0.0-alpha.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.
- package/LICENSE +21 -21
- package/README.md +1139 -1139
- package/dist/core.cjs +2 -2
- package/dist/core.esm.js +2 -2
- package/dist/react/index.esm.js +10 -10
- package/package.json +73 -73
package/README.md
CHANGED
|
@@ -1,1139 +1,1139 @@
|
|
|
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 the Auth Hub
|
|
19
|
-
- `SpotifyAPI` - For fetching user Spotify data from the Auth Hub
|
|
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 the Camp Auth Hub
|
|
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 the Auth Hub. 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 the Auth Hub. 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 the Auth Hub. 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
|
-
- `discord` - The URI to redirect to after the user completes oauth for Discord.
|
|
274
|
-
- `spotify` - The URI to redirect to after the user completes oauth for Spotify.
|
|
275
|
-
- `allowAnalytics` - Whether to allow analytics to be collected. Defaults to `true`.
|
|
276
|
-
|
|
277
|
-
You may use the `redirectUri` object to redirect the user to different pages based on the social they are linking.
|
|
278
|
-
You may only define the URIs for the socials you are using, the rest will default to `window.location.href`.
|
|
279
|
-
|
|
280
|
-
```js
|
|
281
|
-
import { Auth } from "@campnetwork/origin";
|
|
282
|
-
|
|
283
|
-
const auth = new Auth({
|
|
284
|
-
clientId: string,
|
|
285
|
-
redirectUri: string | object,
|
|
286
|
-
allowAnalytics: boolean,
|
|
287
|
-
});
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
```js
|
|
291
|
-
const auth = new Auth({
|
|
292
|
-
clientId: "your-client-id",
|
|
293
|
-
redirectUri: {
|
|
294
|
-
twitter: "https://your-website.com/twitter",
|
|
295
|
-
discord: "https://your-website.com/discord",
|
|
296
|
-
spotify: "https://your-website.com/spotify",
|
|
297
|
-
},
|
|
298
|
-
});
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
### Methods
|
|
302
|
-
|
|
303
|
-
#### connect
|
|
304
|
-
|
|
305
|
-
`connect() => void`
|
|
306
|
-
|
|
307
|
-
The `connect` method prompts the user to sign a message with their wallet in order to authenticate with the Origin SDK.
|
|
308
|
-
The wallet provider can be set by calling the `setProvider` method on the Auth instance beforehand. The default provider used is `window.ethereum`.
|
|
309
|
-
|
|
310
|
-
```js
|
|
311
|
-
auth.connect();
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
#### disconnect
|
|
315
|
-
|
|
316
|
-
`disconnect() => void`
|
|
317
|
-
|
|
318
|
-
The `disconnect` method logs the user out of the Origin SDK on the client side.
|
|
319
|
-
|
|
320
|
-
```js
|
|
321
|
-
auth.disconnect();
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
#### setProvider
|
|
325
|
-
|
|
326
|
-
`setProvider(provider: { provider: EIP1193Provider, info: EIP6963ProviderInfo }) => void`
|
|
327
|
-
|
|
328
|
-
_Read more about the [EIP1193Provider](https://eips.ethereum.org/EIPS/eip-1193) and [EIP6963ProviderInfo](https://eips.ethereum.org/EIPS/eip-6963) interfaces._
|
|
329
|
-
|
|
330
|
-
The `setProvider` method sets the wallet provider to be used for authentication.
|
|
331
|
-
|
|
332
|
-
```js
|
|
333
|
-
auth.setProvider({
|
|
334
|
-
provider: window.ethereum,
|
|
335
|
-
info: { name: "MetaMask", icon: "https://..." },
|
|
336
|
-
});
|
|
337
|
-
```
|
|
338
|
-
|
|
339
|
-
#### setWalletAddress
|
|
340
|
-
|
|
341
|
-
`setWalletAddress(walletAddress: string) => void`
|
|
342
|
-
|
|
343
|
-
The `setWalletAddress` method sets the wallet address to be used for authentication (via the `connect` method).
|
|
344
|
-
|
|
345
|
-
**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.**
|
|
346
|
-
|
|
347
|
-
```js
|
|
348
|
-
auth.setWalletAddress("0x1234567890");
|
|
349
|
-
```
|
|
350
|
-
|
|
351
|
-
#### on
|
|
352
|
-
|
|
353
|
-
`on(event: string, callback: (data: any) => void) => void`
|
|
354
|
-
|
|
355
|
-
The `on` method listens for events emitted by the Auth module of the Origin SDK.
|
|
356
|
-
|
|
357
|
-
The following events are emitted:
|
|
358
|
-
|
|
359
|
-
##### "state"
|
|
360
|
-
|
|
361
|
-
Possible states:
|
|
362
|
-
|
|
363
|
-
- `authenticated` - The user has successfully authenticated.
|
|
364
|
-
- `unauthenticated` - The user has been logged out.
|
|
365
|
-
- `loading` - The user is in the process of authenticating.
|
|
366
|
-
|
|
367
|
-
```js
|
|
368
|
-
auth.on("state", (data) => {
|
|
369
|
-
console.log(data); // "authenticated" | "unauthenticated" | "loading"
|
|
370
|
-
});
|
|
371
|
-
```
|
|
372
|
-
|
|
373
|
-
##### "provider"
|
|
374
|
-
|
|
375
|
-
Returns the provider that has been set via the `setProvider` method.
|
|
376
|
-
If using the Origin SDK React components, this event is emitted when the user selects a provider in the Auth modal.
|
|
377
|
-
|
|
378
|
-
```js
|
|
379
|
-
auth.on("provider", (data) => {
|
|
380
|
-
console.log(data); // { provider: EIP1193Provider, info: EIP6963ProviderInfo }
|
|
381
|
-
});
|
|
382
|
-
```
|
|
383
|
-
|
|
384
|
-
##### "providers"
|
|
385
|
-
|
|
386
|
-
Returns the list of providers that have been injected via EIP6963 and that the user can select from.
|
|
387
|
-
|
|
388
|
-
```js
|
|
389
|
-
auth.on("providers", (data) => {
|
|
390
|
-
console.log(data); // [{ provider: EIP1193Provider, info: EIP6963ProviderInfo }]
|
|
391
|
-
});
|
|
392
|
-
```
|
|
393
|
-
|
|
394
|
-
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.
|
|
395
|
-
|
|
396
|
-
```js
|
|
397
|
-
auth.on("providers", (data) => {
|
|
398
|
-
// Update UI with providers
|
|
399
|
-
// User selects a provider
|
|
400
|
-
const selectedProvider = data[0];
|
|
401
|
-
|
|
402
|
-
auth.setProvider(selectedProvider);
|
|
403
|
-
|
|
404
|
-
auth.connect();
|
|
405
|
-
});
|
|
406
|
-
```
|
|
407
|
-
|
|
408
|
-
#### getLinkedSocials
|
|
409
|
-
|
|
410
|
-
`getLinkedSocials() => Promise<{ twitter: boolean, discord: boolean, spotify: boolean }>`
|
|
411
|
-
|
|
412
|
-
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.
|
|
413
|
-
|
|
414
|
-
```js
|
|
415
|
-
const linkedSocials = await auth.getLinkedSocials();
|
|
416
|
-
|
|
417
|
-
console.log(linkedSocials); // { twitter: true, discord: false, spotify: true }
|
|
418
|
-
```
|
|
419
|
-
|
|
420
|
-
---
|
|
421
|
-
|
|
422
|
-
After the user has authenticated, the following methods can be used to link and unlink social accounts.
|
|
423
|
-
When linking a social account, the user will be redirected to the OAuth flow for that social platform.
|
|
424
|
-
Afterwards, the user will be redirected back to the `redirectUri` specified in the Auth constructor.
|
|
425
|
-
|
|
426
|
-
#### linkTwitter
|
|
427
|
-
|
|
428
|
-
`linkTwitter() => void`
|
|
429
|
-
|
|
430
|
-
The `linkTwitter` method redirects the user to the Twitter OAuth flow to link their Twitter account to the Auth Hub.
|
|
431
|
-
|
|
432
|
-
```js
|
|
433
|
-
auth.linkTwitter();
|
|
434
|
-
```
|
|
435
|
-
|
|
436
|
-
#### linkDiscord
|
|
437
|
-
|
|
438
|
-
`linkDiscord() => void`
|
|
439
|
-
|
|
440
|
-
The `linkDiscord` method redirects the user to the Discord OAuth flow to link their Discord account to the Auth Hub.
|
|
441
|
-
|
|
442
|
-
```js
|
|
443
|
-
auth.linkDiscord();
|
|
444
|
-
```
|
|
445
|
-
|
|
446
|
-
#### linkSpotify
|
|
447
|
-
|
|
448
|
-
`linkSpotify() => void`
|
|
449
|
-
|
|
450
|
-
The `linkSpotify` method redirects the user to the Spotify OAuth flow to link their Spotify account to the Auth Hub.
|
|
451
|
-
|
|
452
|
-
```js
|
|
453
|
-
auth.linkSpotify();
|
|
454
|
-
```
|
|
455
|
-
|
|
456
|
-
#### linkTikTok
|
|
457
|
-
|
|
458
|
-
`linkTikTok(handle: string) => Promise<void>`
|
|
459
|
-
|
|
460
|
-
The `linkTikTok` method links the provided TikTok handle to the Auth Hub.
|
|
461
|
-
|
|
462
|
-
```js
|
|
463
|
-
auth.linkTikTok("tiktokhandle");
|
|
464
|
-
```
|
|
465
|
-
|
|
466
|
-
#### sendTelegramOTP
|
|
467
|
-
|
|
468
|
-
`sendTelegramOTP(phoneNumber: string) => Promise<void>`
|
|
469
|
-
The `sendTelegramOTP` method sends an OTP to the provided phone number via Telegram. The OTP can be used via the `linkTelegram` method to link the user's Telegram account to the Auth Hub.
|
|
470
|
-
|
|
471
|
-
```js
|
|
472
|
-
const { phone_code_hash } = await auth.sendTelegramOTP("+1234567890");
|
|
473
|
-
```
|
|
474
|
-
|
|
475
|
-
#### linkTelegram
|
|
476
|
-
|
|
477
|
-
`linkTelegram(phoneNumber: string, otp: string, phoneCodeHash: string) => Promise<void>`
|
|
478
|
-
|
|
479
|
-
The `linkTelegram` method links the provided phone number to the Auth Hub using the OTP and phone code hash received from the `sendTelegramOTP` method.
|
|
480
|
-
|
|
481
|
-
```js
|
|
482
|
-
await auth.linkTelegram("+1234567890", "123456", "abc123");
|
|
483
|
-
```
|
|
484
|
-
|
|
485
|
-
---
|
|
486
|
-
|
|
487
|
-
#### unlinkTwitter
|
|
488
|
-
|
|
489
|
-
`unlinkTwitter() => Promise<void>`
|
|
490
|
-
|
|
491
|
-
The `unlinkTwitter` method unlinks the user's Twitter account from the Auth Hub.
|
|
492
|
-
|
|
493
|
-
```js
|
|
494
|
-
await auth.unlinkTwitter();
|
|
495
|
-
```
|
|
496
|
-
|
|
497
|
-
#### unlinkDiscord
|
|
498
|
-
|
|
499
|
-
`unlinkDiscord() => Promise<void>`
|
|
500
|
-
|
|
501
|
-
The `unlinkDiscord` method unlinks the user's Discord account from the Auth Hub.
|
|
502
|
-
|
|
503
|
-
```js
|
|
504
|
-
await auth.unlinkDiscord();
|
|
505
|
-
```
|
|
506
|
-
|
|
507
|
-
#### unlinkSpotify
|
|
508
|
-
|
|
509
|
-
`unlinkSpotify() => Promise<void>`
|
|
510
|
-
|
|
511
|
-
The `unlinkSpotify` method unlinks the user's Spotify account from the Auth Hub.
|
|
512
|
-
|
|
513
|
-
```js
|
|
514
|
-
await auth.unlinkSpotify();
|
|
515
|
-
```
|
|
516
|
-
|
|
517
|
-
#### unlinkTikTok
|
|
518
|
-
|
|
519
|
-
`unlinkTikTok() => Promise<void>`
|
|
520
|
-
|
|
521
|
-
The `unlinkTikTok` method unlinks the user's TikTok account from the Auth Hub.
|
|
522
|
-
|
|
523
|
-
```js
|
|
524
|
-
await auth.unlinkTikTok();
|
|
525
|
-
```
|
|
526
|
-
|
|
527
|
-
#### unlinkTelegram
|
|
528
|
-
|
|
529
|
-
`unlinkTelegram() => Promise<void>`
|
|
530
|
-
The `unlinkTelegram` method unlinks the user's Telegram account from the Auth Hub.
|
|
531
|
-
|
|
532
|
-
```js
|
|
533
|
-
await auth.unlinkTelegram();
|
|
534
|
-
```
|
|
535
|
-
|
|
536
|
-
# React
|
|
537
|
-
|
|
538
|
-
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.
|
|
539
|
-
|
|
540
|
-
```js
|
|
541
|
-
// main.jsx
|
|
542
|
-
import { StrictMode } from "react";
|
|
543
|
-
import { createRoot } from "react-dom/client";
|
|
544
|
-
import { CampProvider } from "@campnetwork/origin/react";
|
|
545
|
-
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
546
|
-
import App from "./App.jsx";
|
|
547
|
-
|
|
548
|
-
const queryClient = new QueryClient();
|
|
549
|
-
|
|
550
|
-
createRoot(document.getElementById("root")).render(
|
|
551
|
-
<StrictMode>
|
|
552
|
-
<QueryClientProvider client={queryClient}>
|
|
553
|
-
<CampProvider clientId="your-client-id">
|
|
554
|
-
<App />
|
|
555
|
-
</CampProvider>
|
|
556
|
-
</QueryClientProvider>
|
|
557
|
-
</StrictMode>
|
|
558
|
-
);
|
|
559
|
-
```
|
|
560
|
-
|
|
561
|
-
## CampProvider
|
|
562
|
-
|
|
563
|
-
The `CampProvider` component requires a `clientId` prop to be passed in order link the users to your app.
|
|
564
|
-
It can also take the following optional props:
|
|
565
|
-
|
|
566
|
-
- `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`, `discord`, `spotify`. This is used to redirect the user to different pages after they have completed the OAuth flow for a social.
|
|
567
|
-
|
|
568
|
-
```jsx
|
|
569
|
-
import { CampProvider } from "@campnetwork/origin/react";
|
|
570
|
-
// ...
|
|
571
|
-
function App() {
|
|
572
|
-
return (
|
|
573
|
-
<CampProvider
|
|
574
|
-
clientId="your-client-id"
|
|
575
|
-
redirectUri="https://your-website.com"
|
|
576
|
-
>
|
|
577
|
-
<div>Your app</div>
|
|
578
|
-
</CampProvider>
|
|
579
|
-
);
|
|
580
|
-
}
|
|
581
|
-
```
|
|
582
|
-
|
|
583
|
-
Or, with an object for the `redirectUri`:
|
|
584
|
-
|
|
585
|
-
```jsx
|
|
586
|
-
import { CampProvider } from "@campnetwork/origin/react";
|
|
587
|
-
// ...
|
|
588
|
-
function App() {
|
|
589
|
-
return (
|
|
590
|
-
<CampProvider
|
|
591
|
-
clientId="your-client-id"
|
|
592
|
-
redirectUri={{
|
|
593
|
-
twitter: "https://your-website.com/twitter",
|
|
594
|
-
discord: "https://your-website.com/discord",
|
|
595
|
-
spotify: "https://your-website.com/spotify",
|
|
596
|
-
}}
|
|
597
|
-
>
|
|
598
|
-
<div>Your app</div>
|
|
599
|
-
</CampProvider>
|
|
600
|
-
);
|
|
601
|
-
}
|
|
602
|
-
```
|
|
603
|
-
|
|
604
|
-
The `CampProvider` component sets up the context for the Origin SDK and provides the Auth instance to the rest of the app.
|
|
605
|
-
|
|
606
|
-
## CampModal
|
|
607
|
-
|
|
608
|
-

|
|
609
|
-
|
|
610
|
-
The **CampModal** is a one-line\* solution for authenticating users with the Origin SDK. It can be used to connect users to the Auth Hub and link and unlink social accounts.
|
|
611
|
-
|
|
612
|
-
It works as follows:
|
|
613
|
-
|
|
614
|
-
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.
|
|
615
|
-
|
|
616
|
-
If the user is already authenticated, the button will instead say "**My Camp**" and the modal will display the user's Camp profile information and allow them to link and unlink social accounts.
|
|
617
|
-
|
|
618
|
-
The **CampModal** can take the following props:
|
|
619
|
-
|
|
620
|
-
- `wcProjectId` - `string` - The WalletConnect project ID to use for authentication. Allows the users to authenticate via WalletConnect.
|
|
621
|
-
- `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.
|
|
622
|
-
- `onlyWagmi` - `boolean` - Whether to only show the provider that the user is currently authenticated with. Defaults to `false`.
|
|
623
|
-
- `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.
|
|
624
|
-
- `allowAnalytics` - `boolean` - Whether to allow analytics to be collected. Defaults to `true`.
|
|
625
|
-
|
|
626
|
-
### Usage
|
|
627
|
-
|
|
628
|
-
Basic usage of the **CampModal** component:
|
|
629
|
-
|
|
630
|
-
```jsx
|
|
631
|
-
import { CampModal } from "@campnetwork/origin/react";
|
|
632
|
-
|
|
633
|
-
function App() {
|
|
634
|
-
return (
|
|
635
|
-
<div>
|
|
636
|
-
<CampModal />
|
|
637
|
-
</div>
|
|
638
|
-
);
|
|
639
|
-
}
|
|
640
|
-
```
|
|
641
|
-
|
|
642
|
-
With custom props:
|
|
643
|
-
|
|
644
|
-
```jsx
|
|
645
|
-
import { CampModal } from "@campnetwork/origin/react";
|
|
646
|
-
|
|
647
|
-
function App() {
|
|
648
|
-
return (
|
|
649
|
-
<div>
|
|
650
|
-
<CampModal
|
|
651
|
-
wcProjectId="your-wc-project-id"
|
|
652
|
-
defaultProvider={{
|
|
653
|
-
provider: window.ethereum,
|
|
654
|
-
info: { name: "MetaMask", icon: "https://..." },
|
|
655
|
-
exclusive: false,
|
|
656
|
-
}}
|
|
657
|
-
/>
|
|
658
|
-
</div>
|
|
659
|
-
);
|
|
660
|
-
}
|
|
661
|
-
```
|
|
662
|
-
|
|
663
|
-
You can find more [examples here](./examples/client-side/react/providers-configuration).
|
|
664
|
-
|
|
665
|
-
Only show the provider that the user is currently authenticated with (if using wagmi):
|
|
666
|
-
|
|
667
|
-
```jsx
|
|
668
|
-
import { CampModal } from "@campnetwork/origin/react";
|
|
669
|
-
|
|
670
|
-
function App() {
|
|
671
|
-
return (
|
|
672
|
-
<div>
|
|
673
|
-
<CampModal onlyWagmi />
|
|
674
|
-
</div>
|
|
675
|
-
);
|
|
676
|
-
}
|
|
677
|
-
```
|
|
678
|
-
|
|
679
|
-
Users can be authenticated either via the Camp Modal as outlined above or programmatically by calling the `connect` method on the Auth instance.
|
|
680
|
-
|
|
681
|
-
### Usage with third party providers (Privy, Appkit, Magic, etc.)
|
|
682
|
-
|
|
683
|
-
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 the Auth Hub using that provider. Otherwise, you can set up the default provider to be whatever provider you are using.
|
|
684
|
-
|
|
685
|
-
[Example usage with Privy](./examples/client-side/react/privy-connector/)
|
|
686
|
-
|
|
687
|
-
[Example usage with Appkit](./examples/client-side/react/appkit-connector/)
|
|
688
|
-
|
|
689
|
-
[Example usage with magic.link](./examples/client-side/react/magic-link-connector/)
|
|
690
|
-
|
|
691
|
-
After the user has authenticated, you can use the provided hooks to fetch user data and listen for events.
|
|
692
|
-
|
|
693
|
-
## LinkButton
|
|
694
|
-
|
|
695
|
-
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.
|
|
696
|
-
|
|
697
|
-
The **LinkButton** can take the following props:
|
|
698
|
-
|
|
699
|
-
- `social` - `string` - The social account to link or unlink. Can be one of: `twitter`, `discord`, `spotify`.
|
|
700
|
-
- `variant` - `string` - The variant of the button. Can be one of: `default`, `icon`. Defaults to `default`.
|
|
701
|
-
- `theme` - `string` - The theme of the button. Can be one of: `default`, `camp`. Defaults to `default`.
|
|
702
|
-
|
|
703
|
-
**Note: The `<CampModal/>` component must be rendered in the component tree for the buttons to work.**
|
|
704
|
-
|
|
705
|
-
### Usage
|
|
706
|
-
|
|
707
|
-
Basic usage of the **LinkButton** component:
|
|
708
|
-
|
|
709
|
-
```jsx
|
|
710
|
-
import { LinkButton, CampModal } from "@campnetwork/origin/react";
|
|
711
|
-
|
|
712
|
-
function App() {
|
|
713
|
-
return (
|
|
714
|
-
<div>
|
|
715
|
-
<CampModal />
|
|
716
|
-
<LinkButton social="twitter" />
|
|
717
|
-
<LinkButton social="discord" variant="icon" />
|
|
718
|
-
<LinkButton social="spotify" theme="camp" />
|
|
719
|
-
<LinkButton social="tiktok" variant="icon" theme="camp" />
|
|
720
|
-
<LinkButton social="telegram" />
|
|
721
|
-
</div>
|
|
722
|
-
);
|
|
723
|
-
}
|
|
724
|
-
```
|
|
725
|
-
|
|
726
|
-
## Hooks
|
|
727
|
-
|
|
728
|
-
### useAuth
|
|
729
|
-
|
|
730
|
-
The `useAuth` hook returns the instance of the Auth class that is provided by the CampProvider.
|
|
731
|
-
It can be used as outlined in the Core section in order to build custom authentication flows, listen for events, and fetch user data.
|
|
732
|
-
|
|
733
|
-
```jsx
|
|
734
|
-
import { useAuth } from "@campnetwork/origin/react";
|
|
735
|
-
|
|
736
|
-
function App() {
|
|
737
|
-
const auth = useAuth();
|
|
738
|
-
|
|
739
|
-
return (
|
|
740
|
-
<div>
|
|
741
|
-
<button onClick={auth.connect}>Connect</button>
|
|
742
|
-
</div>
|
|
743
|
-
);
|
|
744
|
-
}
|
|
745
|
-
```
|
|
746
|
-
|
|
747
|
-
### useAuthState
|
|
748
|
-
|
|
749
|
-
The `useAuthState` hook returns the current authentication state of the user.
|
|
750
|
-
|
|
751
|
-
```jsx
|
|
752
|
-
import { useAuthState } from "@campnetwork/origin/react";
|
|
753
|
-
|
|
754
|
-
function App() {
|
|
755
|
-
const { authenticated, loading } = useAuthState();
|
|
756
|
-
|
|
757
|
-
return (
|
|
758
|
-
<div>
|
|
759
|
-
{loading && <div>Loading...</div>}
|
|
760
|
-
{authenticated && <div>Authenticated</div>}
|
|
761
|
-
</div>
|
|
762
|
-
);
|
|
763
|
-
}
|
|
764
|
-
```
|
|
765
|
-
|
|
766
|
-
### useProvider
|
|
767
|
-
|
|
768
|
-
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.
|
|
769
|
-
|
|
770
|
-
```jsx
|
|
771
|
-
import { useProvider } from "@campnetwork/origin/react";
|
|
772
|
-
|
|
773
|
-
function App() {
|
|
774
|
-
const { provider, setProvider } = useProvider();
|
|
775
|
-
|
|
776
|
-
return (
|
|
777
|
-
<div>
|
|
778
|
-
<div>Current provider: {provider.info.name}</div>
|
|
779
|
-
<button
|
|
780
|
-
onClick={() =>
|
|
781
|
-
setProvider({ provider: window.ethereum, info: { name: "Metamask" } })
|
|
782
|
-
}
|
|
783
|
-
>
|
|
784
|
-
Set Provider
|
|
785
|
-
</button>
|
|
786
|
-
</div>
|
|
787
|
-
);
|
|
788
|
-
}
|
|
789
|
-
```
|
|
790
|
-
|
|
791
|
-
### useProviders
|
|
792
|
-
|
|
793
|
-
The `useProviders` hook returns the list of providers that have been injected via EIP6963 and that the user or app can select from.
|
|
794
|
-
|
|
795
|
-
```jsx
|
|
796
|
-
import { useProviders, useProvider } from "@campnetwork/origin/react";
|
|
797
|
-
|
|
798
|
-
function App() {
|
|
799
|
-
const providers = useProviders();
|
|
800
|
-
const { setProvider } = useProvider();
|
|
801
|
-
|
|
802
|
-
return (
|
|
803
|
-
<div>
|
|
804
|
-
{providers.map((provider) => (
|
|
805
|
-
<button key={provider.info.name} onClick={() => setProvider(provider)}>
|
|
806
|
-
{provider.info.name}
|
|
807
|
-
</button>
|
|
808
|
-
))}
|
|
809
|
-
</div>
|
|
810
|
-
);
|
|
811
|
-
}
|
|
812
|
-
```
|
|
813
|
-
|
|
814
|
-
### useConnect
|
|
815
|
-
|
|
816
|
-
The `useConnect` hook returns functions that can be used to connect and disconnect the user.
|
|
817
|
-
|
|
818
|
-
```jsx
|
|
819
|
-
import { useConnect, useAuthState } from "@campnetwork/origin/react";
|
|
820
|
-
|
|
821
|
-
function App() {
|
|
822
|
-
const { connect, disconnect } = useConnect();
|
|
823
|
-
const { authenticated } = useAuthState();
|
|
824
|
-
|
|
825
|
-
return (
|
|
826
|
-
<div>
|
|
827
|
-
{authenticated ? (
|
|
828
|
-
<button onClick={disconnect}>Disconnect</button>
|
|
829
|
-
) : (
|
|
830
|
-
<button onClick={connect}>Connect</button>
|
|
831
|
-
)}
|
|
832
|
-
</div>
|
|
833
|
-
);
|
|
834
|
-
}
|
|
835
|
-
```
|
|
836
|
-
|
|
837
|
-
### useSocials
|
|
838
|
-
|
|
839
|
-
The `useSocials` hook returns the state of the user's linked social accounts.
|
|
840
|
-
|
|
841
|
-
```jsx
|
|
842
|
-
import { useSocials } from "@campnetwork/origin/react";
|
|
843
|
-
|
|
844
|
-
function App() {
|
|
845
|
-
const { data, error, isLoading } = useSocials();
|
|
846
|
-
|
|
847
|
-
if (loading) return <div>Loading...</div>;
|
|
848
|
-
if (error) return <div>Error: {error.message}</div>;
|
|
849
|
-
|
|
850
|
-
return (
|
|
851
|
-
<div>
|
|
852
|
-
<div>Twitter: {data.twitter ? "Linked" : "Not linked"}</div>
|
|
853
|
-
<div>Discord: {data.discord ? "Linked" : "Not linked"}</div>
|
|
854
|
-
<div>Spotify: {data.spotify ? "Linked" : "Not linked"}</div>
|
|
855
|
-
</div>
|
|
856
|
-
);
|
|
857
|
-
}
|
|
858
|
-
```
|
|
859
|
-
|
|
860
|
-
### useLinkSocials
|
|
861
|
-
|
|
862
|
-
The `useLinkSocials` hook returns functions that can be used to link and unlink social accounts.
|
|
863
|
-
|
|
864
|
-
```jsx
|
|
865
|
-
import { useLinkSocials } from "@campnetwork/origin/react";
|
|
866
|
-
|
|
867
|
-
function App() {
|
|
868
|
-
const {
|
|
869
|
-
linkTwitter,
|
|
870
|
-
linkDiscord,
|
|
871
|
-
linkSpotify,
|
|
872
|
-
linkTiktok,
|
|
873
|
-
linkTelegram,
|
|
874
|
-
sendTelegramOTP,
|
|
875
|
-
unlinkTwitter,
|
|
876
|
-
unlinkDiscord,
|
|
877
|
-
unlinkSpotify,
|
|
878
|
-
unlinkTiktok,
|
|
879
|
-
unlinkTelegram,
|
|
880
|
-
} = useLinkSocials();
|
|
881
|
-
|
|
882
|
-
return (
|
|
883
|
-
<div>
|
|
884
|
-
<button onClick={linkTwitter}>Link Twitter</button>
|
|
885
|
-
<button onClick={linkDiscord}>Link Discord</button>
|
|
886
|
-
<button onClick={linkSpotify}>Link Spotify</button>
|
|
887
|
-
<button onClick={() => linkTiktok("tiktokhandle")}>Link TikTok</button>
|
|
888
|
-
<button onClick={() => sendTelegramOTP("+1234567890")}>
|
|
889
|
-
Send Telegram OTP
|
|
890
|
-
</button>
|
|
891
|
-
<button onClick={() => linkTelegram("+1234567890", "123456", "abc123")}>
|
|
892
|
-
Link Telegram
|
|
893
|
-
</button>
|
|
894
|
-
<button onClick={unlinkTwitter}>Unlink Twitter</button>
|
|
895
|
-
<button onClick={unlinkDiscord}>Unlink Discord</button>
|
|
896
|
-
<button onClick={unlinkSpotify}>Unlink Spotify</button>
|
|
897
|
-
<button onClick={unlinkTiktok}>Unlink TikTok</button>
|
|
898
|
-
<button onClick={unlinkTelegram}>Unlink Telegram</button>
|
|
899
|
-
</div>
|
|
900
|
-
);
|
|
901
|
-
}
|
|
902
|
-
```
|
|
903
|
-
|
|
904
|
-
### useModal
|
|
905
|
-
|
|
906
|
-
The `useModal` hook returns the state of the Auth and My Camp modals, as well as functions to show and hide them.
|
|
907
|
-
|
|
908
|
-
**Note: The `<CampModal/>` component must be rendered in the component tree for the modals to be displayed.**
|
|
909
|
-
|
|
910
|
-
```jsx
|
|
911
|
-
import { useModal, CampModal } from "@campnetwork/origin/react";
|
|
912
|
-
|
|
913
|
-
function App() {
|
|
914
|
-
const { isOpen, openModal, closeModal } = useModal();
|
|
915
|
-
|
|
916
|
-
return (
|
|
917
|
-
<div>
|
|
918
|
-
<button onClick={openModal}>Open Modal</button>
|
|
919
|
-
<button onClick={closeModal}>Close Modal</button>
|
|
920
|
-
<CampModal injectButton={false} />
|
|
921
|
-
</div>
|
|
922
|
-
);
|
|
923
|
-
}
|
|
924
|
-
```
|
|
925
|
-
|
|
926
|
-
The state and functions returned by the `useModal` hook can be used to show and hide the Auth and My Camp modals, as well as to check if they are currently open. The modal being controlled is dictated by the user's authentication state.
|
|
927
|
-
|
|
928
|
-
### useLinkModal
|
|
929
|
-
|
|
930
|
-
The `useLinkModal` hook returns the state of the Link Socials modal, as well as functions to show and hide it.
|
|
931
|
-
|
|
932
|
-
**Note: The `<CampModal/>` component must be rendered in the component tree for the modal to be displayed.**
|
|
933
|
-
|
|
934
|
-
```jsx
|
|
935
|
-
import { useLinkModal, CampModal } from "@campnetwork/origin/react";
|
|
936
|
-
|
|
937
|
-
function App() {
|
|
938
|
-
const { isLinkingOpen, openTwitterModal } = useLinkModal();
|
|
939
|
-
|
|
940
|
-
return (
|
|
941
|
-
<div>
|
|
942
|
-
<CampModal />
|
|
943
|
-
<button onClick={openTwitterModal}>Link Twitter</button>
|
|
944
|
-
</div>
|
|
945
|
-
);
|
|
946
|
-
}
|
|
947
|
-
```
|
|
948
|
-
|
|
949
|
-
It returns the following properties and functions:
|
|
950
|
-
|
|
951
|
-
- `isLinkingOpen` - `boolean` - Whether the Link Socials modal is open or not.
|
|
952
|
-
- `openTwitterModal` - `() => void`
|
|
953
|
-
- `openDiscordModal` - `() => void`
|
|
954
|
-
- `openSpotifyModal` - `() => void`
|
|
955
|
-
- `openTiktokModal` - `() => void`
|
|
956
|
-
- `openTelegramModal` - `() => void`
|
|
957
|
-
- `linkTwitter` - `() => void`
|
|
958
|
-
- `linkDiscord` - `() => void`
|
|
959
|
-
- `linkSpotify` - `() => void`
|
|
960
|
-
- `linkTiktok` - `() => void`
|
|
961
|
-
- `linkTelegram` - `() => void`
|
|
962
|
-
- `unlinkTwitter` - `() => void`
|
|
963
|
-
- `unlinkDiscord` - `() => void`
|
|
964
|
-
- `unlinkSpotify` - `() => void`
|
|
965
|
-
- `unlinkTiktok` - `() => void`
|
|
966
|
-
- `unlinkTelegram` - `() => void`
|
|
967
|
-
- `closeModal` - `() => void`
|
|
968
|
-
|
|
969
|
-
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.
|
|
970
|
-
|
|
971
|
-
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.
|
|
972
|
-
|
|
973
|
-
## Origin Methods (`auth.origin`)
|
|
974
|
-
|
|
975
|
-
The `Origin` class provides methods for interacting with Origin IpNFTs, uploading files, managing user stats, and more. You can access these methods via `auth.origin` after authentication.
|
|
976
|
-
|
|
977
|
-
### Types
|
|
978
|
-
|
|
979
|
-
#### `LicenseTerms`
|
|
980
|
-
|
|
981
|
-
The license terms object used in minting and updating methods:
|
|
982
|
-
|
|
983
|
-
```typescript
|
|
984
|
-
type LicenseTerms = {
|
|
985
|
-
price: bigint; // Price in wei
|
|
986
|
-
duration: number; // Duration in seconds
|
|
987
|
-
royaltyBps: number; // Royalty in basis points (0-10000)
|
|
988
|
-
paymentToken: Address; // Payment token address (address(0) for native currency)
|
|
989
|
-
};
|
|
990
|
-
```
|
|
991
|
-
|
|
992
|
-
### File Upload & Minting
|
|
993
|
-
|
|
994
|
-
#### `mintFile(file: File, metadata: Record<string, unknown>, license: LicenseTerms, parentId?: bigint, options?: { progressCallback?: (percent: number) => void })`
|
|
995
|
-
|
|
996
|
-
Uploads a file and mints an IpNFT for it.
|
|
997
|
-
|
|
998
|
-
- `file`: The file to upload and mint.
|
|
999
|
-
- `metadata`: Additional metadata for the IpNFT.
|
|
1000
|
-
- `license`: License terms for the IpNFT (price, duration, royalty, payment token).
|
|
1001
|
-
- `parentId`: Optional parent token ID for derivative works.
|
|
1002
|
-
- `options.progressCallback`: Optional progress callback.
|
|
1003
|
-
- **Returns:** The minted token ID as a string, or throws an error on failure.
|
|
1004
|
-
|
|
1005
|
-
#### `mintSocial(source: "spotify" | "twitter" | "tiktok", license: LicenseTerms)`
|
|
1006
|
-
|
|
1007
|
-
Mints an IpNFT for a connected social account.
|
|
1008
|
-
|
|
1009
|
-
- `source`: The social platform.
|
|
1010
|
-
- `license`: License terms for the IpNFT.
|
|
1011
|
-
- **Returns:** The minted token ID as a string, or throws an error on failure.
|
|
1012
|
-
|
|
1013
|
-
### IpNFT & Marketplace Methods
|
|
1014
|
-
|
|
1015
|
-
The following methods are available for interacting with IpNFTs and the marketplace. All methods mirror the smart contract functions and require appropriate permissions.
|
|
1016
|
-
|
|
1017
|
-
#### Core IpNFT Methods
|
|
1018
|
-
|
|
1019
|
-
- `mintWithSignature(account: string, tokenId: bigint, parentId: bigint, creatorContentHash: string, uri: string, license: LicenseTerms, deadline: bigint, signature: string)` - Mint an IpNFT with a signature
|
|
1020
|
-
- `registerIpNFT(source: string, deadline: bigint, license: LicenseTerms, metadata: Record<string, unknown>, fileKey?: string, parentId?: bigint)` - Register an IpNFT for minting
|
|
1021
|
-
- `updateTerms(tokenId: bigint, license: LicenseTerms)` - Update license terms for an IpNFT
|
|
1022
|
-
- `requestDelete(tokenId: bigint)` - Request deletion of an IpNFT
|
|
1023
|
-
- `getTerms(tokenId: bigint)` - Get license terms for an IpNFT
|
|
1024
|
-
- `ownerOf(tokenId: bigint)` - Get the owner of an IpNFT
|
|
1025
|
-
- `balanceOf(owner: string)` - Get the balance of IpNFTs for an owner
|
|
1026
|
-
- `contentHash(tokenId: bigint)` - Get the content hash of an IpNFT
|
|
1027
|
-
- `tokenURI(tokenId: bigint)` - Get the metadata URI of an IpNFT
|
|
1028
|
-
- `dataStatus(tokenId: bigint)` - Get the data status of an IpNFT
|
|
1029
|
-
- `royaltyInfo(tokenId: bigint, value: bigint)` - Get royalty information
|
|
1030
|
-
- `getApproved(tokenId: bigint)` - Get the approved address for an IpNFT
|
|
1031
|
-
- `isApprovedForAll(owner: string, operator: string)` - Check if operator is approved for all tokens
|
|
1032
|
-
- `transferFrom(from: string, to: string, tokenId: bigint)` - Transfer an IpNFT
|
|
1033
|
-
- `safeTransferFrom(from: string, to: string, tokenId: bigint)` - Safely transfer an IpNFT
|
|
1034
|
-
- `approve(to: string, tokenId: bigint)` - Approve an address for a specific IpNFT
|
|
1035
|
-
- `setApprovalForAll(operator: string, approved: boolean)` - Set approval for all tokens
|
|
1036
|
-
|
|
1037
|
-
#### Marketplace Methods
|
|
1038
|
-
|
|
1039
|
-
- `buyAccess(tokenId: bigint, periods: number, value?: bigint)` - Buy access to an IpNFT
|
|
1040
|
-
- `renewAccess(tokenId: bigint, periods: number)` - Renew access to an IpNFT
|
|
1041
|
-
- `hasAccess(tokenId: bigint, user: string)` - Check if user has access to an IpNFT
|
|
1042
|
-
- `subscriptionExpiry(tokenId: bigint, user: string)` - Get subscription expiry for a user
|
|
1043
|
-
|
|
1044
|
-
> See the SDK source or contract ABI for full parameter details.
|
|
1045
|
-
|
|
1046
|
-
#### `buyAccessSmart(tokenId: bigint, periods: number)`
|
|
1047
|
-
|
|
1048
|
-
Buys access to an asset, handling payment approval if needed.
|
|
1049
|
-
|
|
1050
|
-
- `tokenId`: The IpNFT token ID.
|
|
1051
|
-
- `periods`: Number of periods to buy.
|
|
1052
|
-
- **Returns:** Result of the buy access transaction.
|
|
1053
|
-
|
|
1054
|
-
#### `getData(tokenId: bigint)`
|
|
1055
|
-
|
|
1056
|
-
Fetches metadata for a given IpNFT.
|
|
1057
|
-
|
|
1058
|
-
- `tokenId`: The IpNFT token ID.
|
|
1059
|
-
- **Returns:** Data object for the token.
|
|
1060
|
-
|
|
1061
|
-
### User Data & Stats
|
|
1062
|
-
|
|
1063
|
-
#### `getOriginUploads()`
|
|
1064
|
-
|
|
1065
|
-
Fetches the user's Origin file uploads.
|
|
1066
|
-
|
|
1067
|
-
- **Returns:** Array of upload data, or `null` on failure.
|
|
1068
|
-
|
|
1069
|
-
#### `getOriginUsage()`
|
|
1070
|
-
|
|
1071
|
-
Fetches the user's Origin stats (multiplier, points, usage, etc).
|
|
1072
|
-
|
|
1073
|
-
- **Returns:** Object with user stats including:
|
|
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 the Auth Hub
|
|
19
|
+
- `SpotifyAPI` - For fetching user Spotify data from the Auth Hub
|
|
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 the Camp Auth Hub
|
|
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 the Auth Hub. 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 the Auth Hub. 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 the Auth Hub. 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
|
+
- `discord` - The URI to redirect to after the user completes oauth for Discord.
|
|
274
|
+
- `spotify` - The URI to redirect to after the user completes oauth for Spotify.
|
|
275
|
+
- `allowAnalytics` - Whether to allow analytics to be collected. Defaults to `true`.
|
|
276
|
+
|
|
277
|
+
You may use the `redirectUri` object to redirect the user to different pages based on the social they are linking.
|
|
278
|
+
You may only define the URIs for the socials you are using, the rest will default to `window.location.href`.
|
|
279
|
+
|
|
280
|
+
```js
|
|
281
|
+
import { Auth } from "@campnetwork/origin";
|
|
282
|
+
|
|
283
|
+
const auth = new Auth({
|
|
284
|
+
clientId: string,
|
|
285
|
+
redirectUri: string | object,
|
|
286
|
+
allowAnalytics: boolean,
|
|
287
|
+
});
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
```js
|
|
291
|
+
const auth = new Auth({
|
|
292
|
+
clientId: "your-client-id",
|
|
293
|
+
redirectUri: {
|
|
294
|
+
twitter: "https://your-website.com/twitter",
|
|
295
|
+
discord: "https://your-website.com/discord",
|
|
296
|
+
spotify: "https://your-website.com/spotify",
|
|
297
|
+
},
|
|
298
|
+
});
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### Methods
|
|
302
|
+
|
|
303
|
+
#### connect
|
|
304
|
+
|
|
305
|
+
`connect() => void`
|
|
306
|
+
|
|
307
|
+
The `connect` method prompts the user to sign a message with their wallet in order to authenticate with the Origin SDK.
|
|
308
|
+
The wallet provider can be set by calling the `setProvider` method on the Auth instance beforehand. The default provider used is `window.ethereum`.
|
|
309
|
+
|
|
310
|
+
```js
|
|
311
|
+
auth.connect();
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
#### disconnect
|
|
315
|
+
|
|
316
|
+
`disconnect() => void`
|
|
317
|
+
|
|
318
|
+
The `disconnect` method logs the user out of the Origin SDK on the client side.
|
|
319
|
+
|
|
320
|
+
```js
|
|
321
|
+
auth.disconnect();
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
#### setProvider
|
|
325
|
+
|
|
326
|
+
`setProvider(provider: { provider: EIP1193Provider, info: EIP6963ProviderInfo }) => void`
|
|
327
|
+
|
|
328
|
+
_Read more about the [EIP1193Provider](https://eips.ethereum.org/EIPS/eip-1193) and [EIP6963ProviderInfo](https://eips.ethereum.org/EIPS/eip-6963) interfaces._
|
|
329
|
+
|
|
330
|
+
The `setProvider` method sets the wallet provider to be used for authentication.
|
|
331
|
+
|
|
332
|
+
```js
|
|
333
|
+
auth.setProvider({
|
|
334
|
+
provider: window.ethereum,
|
|
335
|
+
info: { name: "MetaMask", icon: "https://..." },
|
|
336
|
+
});
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
#### setWalletAddress
|
|
340
|
+
|
|
341
|
+
`setWalletAddress(walletAddress: string) => void`
|
|
342
|
+
|
|
343
|
+
The `setWalletAddress` method sets the wallet address to be used for authentication (via the `connect` method).
|
|
344
|
+
|
|
345
|
+
**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.**
|
|
346
|
+
|
|
347
|
+
```js
|
|
348
|
+
auth.setWalletAddress("0x1234567890");
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
#### on
|
|
352
|
+
|
|
353
|
+
`on(event: string, callback: (data: any) => void) => void`
|
|
354
|
+
|
|
355
|
+
The `on` method listens for events emitted by the Auth module of the Origin SDK.
|
|
356
|
+
|
|
357
|
+
The following events are emitted:
|
|
358
|
+
|
|
359
|
+
##### "state"
|
|
360
|
+
|
|
361
|
+
Possible states:
|
|
362
|
+
|
|
363
|
+
- `authenticated` - The user has successfully authenticated.
|
|
364
|
+
- `unauthenticated` - The user has been logged out.
|
|
365
|
+
- `loading` - The user is in the process of authenticating.
|
|
366
|
+
|
|
367
|
+
```js
|
|
368
|
+
auth.on("state", (data) => {
|
|
369
|
+
console.log(data); // "authenticated" | "unauthenticated" | "loading"
|
|
370
|
+
});
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
##### "provider"
|
|
374
|
+
|
|
375
|
+
Returns the provider that has been set via the `setProvider` method.
|
|
376
|
+
If using the Origin SDK React components, this event is emitted when the user selects a provider in the Auth modal.
|
|
377
|
+
|
|
378
|
+
```js
|
|
379
|
+
auth.on("provider", (data) => {
|
|
380
|
+
console.log(data); // { provider: EIP1193Provider, info: EIP6963ProviderInfo }
|
|
381
|
+
});
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
##### "providers"
|
|
385
|
+
|
|
386
|
+
Returns the list of providers that have been injected via EIP6963 and that the user can select from.
|
|
387
|
+
|
|
388
|
+
```js
|
|
389
|
+
auth.on("providers", (data) => {
|
|
390
|
+
console.log(data); // [{ provider: EIP1193Provider, info: EIP6963ProviderInfo }]
|
|
391
|
+
});
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
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.
|
|
395
|
+
|
|
396
|
+
```js
|
|
397
|
+
auth.on("providers", (data) => {
|
|
398
|
+
// Update UI with providers
|
|
399
|
+
// User selects a provider
|
|
400
|
+
const selectedProvider = data[0];
|
|
401
|
+
|
|
402
|
+
auth.setProvider(selectedProvider);
|
|
403
|
+
|
|
404
|
+
auth.connect();
|
|
405
|
+
});
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
#### getLinkedSocials
|
|
409
|
+
|
|
410
|
+
`getLinkedSocials() => Promise<{ twitter: boolean, discord: boolean, spotify: boolean }>`
|
|
411
|
+
|
|
412
|
+
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.
|
|
413
|
+
|
|
414
|
+
```js
|
|
415
|
+
const linkedSocials = await auth.getLinkedSocials();
|
|
416
|
+
|
|
417
|
+
console.log(linkedSocials); // { twitter: true, discord: false, spotify: true }
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
---
|
|
421
|
+
|
|
422
|
+
After the user has authenticated, the following methods can be used to link and unlink social accounts.
|
|
423
|
+
When linking a social account, the user will be redirected to the OAuth flow for that social platform.
|
|
424
|
+
Afterwards, the user will be redirected back to the `redirectUri` specified in the Auth constructor.
|
|
425
|
+
|
|
426
|
+
#### linkTwitter
|
|
427
|
+
|
|
428
|
+
`linkTwitter() => void`
|
|
429
|
+
|
|
430
|
+
The `linkTwitter` method redirects the user to the Twitter OAuth flow to link their Twitter account to the Auth Hub.
|
|
431
|
+
|
|
432
|
+
```js
|
|
433
|
+
auth.linkTwitter();
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
#### linkDiscord
|
|
437
|
+
|
|
438
|
+
`linkDiscord() => void`
|
|
439
|
+
|
|
440
|
+
The `linkDiscord` method redirects the user to the Discord OAuth flow to link their Discord account to the Auth Hub.
|
|
441
|
+
|
|
442
|
+
```js
|
|
443
|
+
auth.linkDiscord();
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
#### linkSpotify
|
|
447
|
+
|
|
448
|
+
`linkSpotify() => void`
|
|
449
|
+
|
|
450
|
+
The `linkSpotify` method redirects the user to the Spotify OAuth flow to link their Spotify account to the Auth Hub.
|
|
451
|
+
|
|
452
|
+
```js
|
|
453
|
+
auth.linkSpotify();
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
#### linkTikTok
|
|
457
|
+
|
|
458
|
+
`linkTikTok(handle: string) => Promise<void>`
|
|
459
|
+
|
|
460
|
+
The `linkTikTok` method links the provided TikTok handle to the Auth Hub.
|
|
461
|
+
|
|
462
|
+
```js
|
|
463
|
+
auth.linkTikTok("tiktokhandle");
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
#### sendTelegramOTP
|
|
467
|
+
|
|
468
|
+
`sendTelegramOTP(phoneNumber: string) => Promise<void>`
|
|
469
|
+
The `sendTelegramOTP` method sends an OTP to the provided phone number via Telegram. The OTP can be used via the `linkTelegram` method to link the user's Telegram account to the Auth Hub.
|
|
470
|
+
|
|
471
|
+
```js
|
|
472
|
+
const { phone_code_hash } = await auth.sendTelegramOTP("+1234567890");
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
#### linkTelegram
|
|
476
|
+
|
|
477
|
+
`linkTelegram(phoneNumber: string, otp: string, phoneCodeHash: string) => Promise<void>`
|
|
478
|
+
|
|
479
|
+
The `linkTelegram` method links the provided phone number to the Auth Hub using the OTP and phone code hash received from the `sendTelegramOTP` method.
|
|
480
|
+
|
|
481
|
+
```js
|
|
482
|
+
await auth.linkTelegram("+1234567890", "123456", "abc123");
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
---
|
|
486
|
+
|
|
487
|
+
#### unlinkTwitter
|
|
488
|
+
|
|
489
|
+
`unlinkTwitter() => Promise<void>`
|
|
490
|
+
|
|
491
|
+
The `unlinkTwitter` method unlinks the user's Twitter account from the Auth Hub.
|
|
492
|
+
|
|
493
|
+
```js
|
|
494
|
+
await auth.unlinkTwitter();
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
#### unlinkDiscord
|
|
498
|
+
|
|
499
|
+
`unlinkDiscord() => Promise<void>`
|
|
500
|
+
|
|
501
|
+
The `unlinkDiscord` method unlinks the user's Discord account from the Auth Hub.
|
|
502
|
+
|
|
503
|
+
```js
|
|
504
|
+
await auth.unlinkDiscord();
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
#### unlinkSpotify
|
|
508
|
+
|
|
509
|
+
`unlinkSpotify() => Promise<void>`
|
|
510
|
+
|
|
511
|
+
The `unlinkSpotify` method unlinks the user's Spotify account from the Auth Hub.
|
|
512
|
+
|
|
513
|
+
```js
|
|
514
|
+
await auth.unlinkSpotify();
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
#### unlinkTikTok
|
|
518
|
+
|
|
519
|
+
`unlinkTikTok() => Promise<void>`
|
|
520
|
+
|
|
521
|
+
The `unlinkTikTok` method unlinks the user's TikTok account from the Auth Hub.
|
|
522
|
+
|
|
523
|
+
```js
|
|
524
|
+
await auth.unlinkTikTok();
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
#### unlinkTelegram
|
|
528
|
+
|
|
529
|
+
`unlinkTelegram() => Promise<void>`
|
|
530
|
+
The `unlinkTelegram` method unlinks the user's Telegram account from the Auth Hub.
|
|
531
|
+
|
|
532
|
+
```js
|
|
533
|
+
await auth.unlinkTelegram();
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
# React
|
|
537
|
+
|
|
538
|
+
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.
|
|
539
|
+
|
|
540
|
+
```js
|
|
541
|
+
// main.jsx
|
|
542
|
+
import { StrictMode } from "react";
|
|
543
|
+
import { createRoot } from "react-dom/client";
|
|
544
|
+
import { CampProvider } from "@campnetwork/origin/react";
|
|
545
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
546
|
+
import App from "./App.jsx";
|
|
547
|
+
|
|
548
|
+
const queryClient = new QueryClient();
|
|
549
|
+
|
|
550
|
+
createRoot(document.getElementById("root")).render(
|
|
551
|
+
<StrictMode>
|
|
552
|
+
<QueryClientProvider client={queryClient}>
|
|
553
|
+
<CampProvider clientId="your-client-id">
|
|
554
|
+
<App />
|
|
555
|
+
</CampProvider>
|
|
556
|
+
</QueryClientProvider>
|
|
557
|
+
</StrictMode>
|
|
558
|
+
);
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
## CampProvider
|
|
562
|
+
|
|
563
|
+
The `CampProvider` component requires a `clientId` prop to be passed in order link the users to your app.
|
|
564
|
+
It can also take the following optional props:
|
|
565
|
+
|
|
566
|
+
- `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`, `discord`, `spotify`. This is used to redirect the user to different pages after they have completed the OAuth flow for a social.
|
|
567
|
+
|
|
568
|
+
```jsx
|
|
569
|
+
import { CampProvider } from "@campnetwork/origin/react";
|
|
570
|
+
// ...
|
|
571
|
+
function App() {
|
|
572
|
+
return (
|
|
573
|
+
<CampProvider
|
|
574
|
+
clientId="your-client-id"
|
|
575
|
+
redirectUri="https://your-website.com"
|
|
576
|
+
>
|
|
577
|
+
<div>Your app</div>
|
|
578
|
+
</CampProvider>
|
|
579
|
+
);
|
|
580
|
+
}
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
Or, with an object for the `redirectUri`:
|
|
584
|
+
|
|
585
|
+
```jsx
|
|
586
|
+
import { CampProvider } from "@campnetwork/origin/react";
|
|
587
|
+
// ...
|
|
588
|
+
function App() {
|
|
589
|
+
return (
|
|
590
|
+
<CampProvider
|
|
591
|
+
clientId="your-client-id"
|
|
592
|
+
redirectUri={{
|
|
593
|
+
twitter: "https://your-website.com/twitter",
|
|
594
|
+
discord: "https://your-website.com/discord",
|
|
595
|
+
spotify: "https://your-website.com/spotify",
|
|
596
|
+
}}
|
|
597
|
+
>
|
|
598
|
+
<div>Your app</div>
|
|
599
|
+
</CampProvider>
|
|
600
|
+
);
|
|
601
|
+
}
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
The `CampProvider` component sets up the context for the Origin SDK and provides the Auth instance to the rest of the app.
|
|
605
|
+
|
|
606
|
+
## CampModal
|
|
607
|
+
|
|
608
|
+

|
|
609
|
+
|
|
610
|
+
The **CampModal** is a one-line\* solution for authenticating users with the Origin SDK. It can be used to connect users to the Auth Hub and link and unlink social accounts.
|
|
611
|
+
|
|
612
|
+
It works as follows:
|
|
613
|
+
|
|
614
|
+
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.
|
|
615
|
+
|
|
616
|
+
If the user is already authenticated, the button will instead say "**My Camp**" and the modal will display the user's Camp profile information and allow them to link and unlink social accounts.
|
|
617
|
+
|
|
618
|
+
The **CampModal** can take the following props:
|
|
619
|
+
|
|
620
|
+
- `wcProjectId` - `string` - The WalletConnect project ID to use for authentication. Allows the users to authenticate via WalletConnect.
|
|
621
|
+
- `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.
|
|
622
|
+
- `onlyWagmi` - `boolean` - Whether to only show the provider that the user is currently authenticated with. Defaults to `false`.
|
|
623
|
+
- `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.
|
|
624
|
+
- `allowAnalytics` - `boolean` - Whether to allow analytics to be collected. Defaults to `true`.
|
|
625
|
+
|
|
626
|
+
### Usage
|
|
627
|
+
|
|
628
|
+
Basic usage of the **CampModal** component:
|
|
629
|
+
|
|
630
|
+
```jsx
|
|
631
|
+
import { CampModal } from "@campnetwork/origin/react";
|
|
632
|
+
|
|
633
|
+
function App() {
|
|
634
|
+
return (
|
|
635
|
+
<div>
|
|
636
|
+
<CampModal />
|
|
637
|
+
</div>
|
|
638
|
+
);
|
|
639
|
+
}
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
With custom props:
|
|
643
|
+
|
|
644
|
+
```jsx
|
|
645
|
+
import { CampModal } from "@campnetwork/origin/react";
|
|
646
|
+
|
|
647
|
+
function App() {
|
|
648
|
+
return (
|
|
649
|
+
<div>
|
|
650
|
+
<CampModal
|
|
651
|
+
wcProjectId="your-wc-project-id"
|
|
652
|
+
defaultProvider={{
|
|
653
|
+
provider: window.ethereum,
|
|
654
|
+
info: { name: "MetaMask", icon: "https://..." },
|
|
655
|
+
exclusive: false,
|
|
656
|
+
}}
|
|
657
|
+
/>
|
|
658
|
+
</div>
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
```
|
|
662
|
+
|
|
663
|
+
You can find more [examples here](./examples/client-side/react/providers-configuration).
|
|
664
|
+
|
|
665
|
+
Only show the provider that the user is currently authenticated with (if using wagmi):
|
|
666
|
+
|
|
667
|
+
```jsx
|
|
668
|
+
import { CampModal } from "@campnetwork/origin/react";
|
|
669
|
+
|
|
670
|
+
function App() {
|
|
671
|
+
return (
|
|
672
|
+
<div>
|
|
673
|
+
<CampModal onlyWagmi />
|
|
674
|
+
</div>
|
|
675
|
+
);
|
|
676
|
+
}
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
Users can be authenticated either via the Camp Modal as outlined above or programmatically by calling the `connect` method on the Auth instance.
|
|
680
|
+
|
|
681
|
+
### Usage with third party providers (Privy, Appkit, Magic, etc.)
|
|
682
|
+
|
|
683
|
+
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 the Auth Hub using that provider. Otherwise, you can set up the default provider to be whatever provider you are using.
|
|
684
|
+
|
|
685
|
+
[Example usage with Privy](./examples/client-side/react/privy-connector/)
|
|
686
|
+
|
|
687
|
+
[Example usage with Appkit](./examples/client-side/react/appkit-connector/)
|
|
688
|
+
|
|
689
|
+
[Example usage with magic.link](./examples/client-side/react/magic-link-connector/)
|
|
690
|
+
|
|
691
|
+
After the user has authenticated, you can use the provided hooks to fetch user data and listen for events.
|
|
692
|
+
|
|
693
|
+
## LinkButton
|
|
694
|
+
|
|
695
|
+
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.
|
|
696
|
+
|
|
697
|
+
The **LinkButton** can take the following props:
|
|
698
|
+
|
|
699
|
+
- `social` - `string` - The social account to link or unlink. Can be one of: `twitter`, `discord`, `spotify`.
|
|
700
|
+
- `variant` - `string` - The variant of the button. Can be one of: `default`, `icon`. Defaults to `default`.
|
|
701
|
+
- `theme` - `string` - The theme of the button. Can be one of: `default`, `camp`. Defaults to `default`.
|
|
702
|
+
|
|
703
|
+
**Note: The `<CampModal/>` component must be rendered in the component tree for the buttons to work.**
|
|
704
|
+
|
|
705
|
+
### Usage
|
|
706
|
+
|
|
707
|
+
Basic usage of the **LinkButton** component:
|
|
708
|
+
|
|
709
|
+
```jsx
|
|
710
|
+
import { LinkButton, CampModal } from "@campnetwork/origin/react";
|
|
711
|
+
|
|
712
|
+
function App() {
|
|
713
|
+
return (
|
|
714
|
+
<div>
|
|
715
|
+
<CampModal />
|
|
716
|
+
<LinkButton social="twitter" />
|
|
717
|
+
<LinkButton social="discord" variant="icon" />
|
|
718
|
+
<LinkButton social="spotify" theme="camp" />
|
|
719
|
+
<LinkButton social="tiktok" variant="icon" theme="camp" />
|
|
720
|
+
<LinkButton social="telegram" />
|
|
721
|
+
</div>
|
|
722
|
+
);
|
|
723
|
+
}
|
|
724
|
+
```
|
|
725
|
+
|
|
726
|
+
## Hooks
|
|
727
|
+
|
|
728
|
+
### useAuth
|
|
729
|
+
|
|
730
|
+
The `useAuth` hook returns the instance of the Auth class that is provided by the CampProvider.
|
|
731
|
+
It can be used as outlined in the Core section in order to build custom authentication flows, listen for events, and fetch user data.
|
|
732
|
+
|
|
733
|
+
```jsx
|
|
734
|
+
import { useAuth } from "@campnetwork/origin/react";
|
|
735
|
+
|
|
736
|
+
function App() {
|
|
737
|
+
const auth = useAuth();
|
|
738
|
+
|
|
739
|
+
return (
|
|
740
|
+
<div>
|
|
741
|
+
<button onClick={auth.connect}>Connect</button>
|
|
742
|
+
</div>
|
|
743
|
+
);
|
|
744
|
+
}
|
|
745
|
+
```
|
|
746
|
+
|
|
747
|
+
### useAuthState
|
|
748
|
+
|
|
749
|
+
The `useAuthState` hook returns the current authentication state of the user.
|
|
750
|
+
|
|
751
|
+
```jsx
|
|
752
|
+
import { useAuthState } from "@campnetwork/origin/react";
|
|
753
|
+
|
|
754
|
+
function App() {
|
|
755
|
+
const { authenticated, loading } = useAuthState();
|
|
756
|
+
|
|
757
|
+
return (
|
|
758
|
+
<div>
|
|
759
|
+
{loading && <div>Loading...</div>}
|
|
760
|
+
{authenticated && <div>Authenticated</div>}
|
|
761
|
+
</div>
|
|
762
|
+
);
|
|
763
|
+
}
|
|
764
|
+
```
|
|
765
|
+
|
|
766
|
+
### useProvider
|
|
767
|
+
|
|
768
|
+
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.
|
|
769
|
+
|
|
770
|
+
```jsx
|
|
771
|
+
import { useProvider } from "@campnetwork/origin/react";
|
|
772
|
+
|
|
773
|
+
function App() {
|
|
774
|
+
const { provider, setProvider } = useProvider();
|
|
775
|
+
|
|
776
|
+
return (
|
|
777
|
+
<div>
|
|
778
|
+
<div>Current provider: {provider.info.name}</div>
|
|
779
|
+
<button
|
|
780
|
+
onClick={() =>
|
|
781
|
+
setProvider({ provider: window.ethereum, info: { name: "Metamask" } })
|
|
782
|
+
}
|
|
783
|
+
>
|
|
784
|
+
Set Provider
|
|
785
|
+
</button>
|
|
786
|
+
</div>
|
|
787
|
+
);
|
|
788
|
+
}
|
|
789
|
+
```
|
|
790
|
+
|
|
791
|
+
### useProviders
|
|
792
|
+
|
|
793
|
+
The `useProviders` hook returns the list of providers that have been injected via EIP6963 and that the user or app can select from.
|
|
794
|
+
|
|
795
|
+
```jsx
|
|
796
|
+
import { useProviders, useProvider } from "@campnetwork/origin/react";
|
|
797
|
+
|
|
798
|
+
function App() {
|
|
799
|
+
const providers = useProviders();
|
|
800
|
+
const { setProvider } = useProvider();
|
|
801
|
+
|
|
802
|
+
return (
|
|
803
|
+
<div>
|
|
804
|
+
{providers.map((provider) => (
|
|
805
|
+
<button key={provider.info.name} onClick={() => setProvider(provider)}>
|
|
806
|
+
{provider.info.name}
|
|
807
|
+
</button>
|
|
808
|
+
))}
|
|
809
|
+
</div>
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
```
|
|
813
|
+
|
|
814
|
+
### useConnect
|
|
815
|
+
|
|
816
|
+
The `useConnect` hook returns functions that can be used to connect and disconnect the user.
|
|
817
|
+
|
|
818
|
+
```jsx
|
|
819
|
+
import { useConnect, useAuthState } from "@campnetwork/origin/react";
|
|
820
|
+
|
|
821
|
+
function App() {
|
|
822
|
+
const { connect, disconnect } = useConnect();
|
|
823
|
+
const { authenticated } = useAuthState();
|
|
824
|
+
|
|
825
|
+
return (
|
|
826
|
+
<div>
|
|
827
|
+
{authenticated ? (
|
|
828
|
+
<button onClick={disconnect}>Disconnect</button>
|
|
829
|
+
) : (
|
|
830
|
+
<button onClick={connect}>Connect</button>
|
|
831
|
+
)}
|
|
832
|
+
</div>
|
|
833
|
+
);
|
|
834
|
+
}
|
|
835
|
+
```
|
|
836
|
+
|
|
837
|
+
### useSocials
|
|
838
|
+
|
|
839
|
+
The `useSocials` hook returns the state of the user's linked social accounts.
|
|
840
|
+
|
|
841
|
+
```jsx
|
|
842
|
+
import { useSocials } from "@campnetwork/origin/react";
|
|
843
|
+
|
|
844
|
+
function App() {
|
|
845
|
+
const { data, error, isLoading } = useSocials();
|
|
846
|
+
|
|
847
|
+
if (loading) return <div>Loading...</div>;
|
|
848
|
+
if (error) return <div>Error: {error.message}</div>;
|
|
849
|
+
|
|
850
|
+
return (
|
|
851
|
+
<div>
|
|
852
|
+
<div>Twitter: {data.twitter ? "Linked" : "Not linked"}</div>
|
|
853
|
+
<div>Discord: {data.discord ? "Linked" : "Not linked"}</div>
|
|
854
|
+
<div>Spotify: {data.spotify ? "Linked" : "Not linked"}</div>
|
|
855
|
+
</div>
|
|
856
|
+
);
|
|
857
|
+
}
|
|
858
|
+
```
|
|
859
|
+
|
|
860
|
+
### useLinkSocials
|
|
861
|
+
|
|
862
|
+
The `useLinkSocials` hook returns functions that can be used to link and unlink social accounts.
|
|
863
|
+
|
|
864
|
+
```jsx
|
|
865
|
+
import { useLinkSocials } from "@campnetwork/origin/react";
|
|
866
|
+
|
|
867
|
+
function App() {
|
|
868
|
+
const {
|
|
869
|
+
linkTwitter,
|
|
870
|
+
linkDiscord,
|
|
871
|
+
linkSpotify,
|
|
872
|
+
linkTiktok,
|
|
873
|
+
linkTelegram,
|
|
874
|
+
sendTelegramOTP,
|
|
875
|
+
unlinkTwitter,
|
|
876
|
+
unlinkDiscord,
|
|
877
|
+
unlinkSpotify,
|
|
878
|
+
unlinkTiktok,
|
|
879
|
+
unlinkTelegram,
|
|
880
|
+
} = useLinkSocials();
|
|
881
|
+
|
|
882
|
+
return (
|
|
883
|
+
<div>
|
|
884
|
+
<button onClick={linkTwitter}>Link Twitter</button>
|
|
885
|
+
<button onClick={linkDiscord}>Link Discord</button>
|
|
886
|
+
<button onClick={linkSpotify}>Link Spotify</button>
|
|
887
|
+
<button onClick={() => linkTiktok("tiktokhandle")}>Link TikTok</button>
|
|
888
|
+
<button onClick={() => sendTelegramOTP("+1234567890")}>
|
|
889
|
+
Send Telegram OTP
|
|
890
|
+
</button>
|
|
891
|
+
<button onClick={() => linkTelegram("+1234567890", "123456", "abc123")}>
|
|
892
|
+
Link Telegram
|
|
893
|
+
</button>
|
|
894
|
+
<button onClick={unlinkTwitter}>Unlink Twitter</button>
|
|
895
|
+
<button onClick={unlinkDiscord}>Unlink Discord</button>
|
|
896
|
+
<button onClick={unlinkSpotify}>Unlink Spotify</button>
|
|
897
|
+
<button onClick={unlinkTiktok}>Unlink TikTok</button>
|
|
898
|
+
<button onClick={unlinkTelegram}>Unlink Telegram</button>
|
|
899
|
+
</div>
|
|
900
|
+
);
|
|
901
|
+
}
|
|
902
|
+
```
|
|
903
|
+
|
|
904
|
+
### useModal
|
|
905
|
+
|
|
906
|
+
The `useModal` hook returns the state of the Auth and My Camp modals, as well as functions to show and hide them.
|
|
907
|
+
|
|
908
|
+
**Note: The `<CampModal/>` component must be rendered in the component tree for the modals to be displayed.**
|
|
909
|
+
|
|
910
|
+
```jsx
|
|
911
|
+
import { useModal, CampModal } from "@campnetwork/origin/react";
|
|
912
|
+
|
|
913
|
+
function App() {
|
|
914
|
+
const { isOpen, openModal, closeModal } = useModal();
|
|
915
|
+
|
|
916
|
+
return (
|
|
917
|
+
<div>
|
|
918
|
+
<button onClick={openModal}>Open Modal</button>
|
|
919
|
+
<button onClick={closeModal}>Close Modal</button>
|
|
920
|
+
<CampModal injectButton={false} />
|
|
921
|
+
</div>
|
|
922
|
+
);
|
|
923
|
+
}
|
|
924
|
+
```
|
|
925
|
+
|
|
926
|
+
The state and functions returned by the `useModal` hook can be used to show and hide the Auth and My Camp modals, as well as to check if they are currently open. The modal being controlled is dictated by the user's authentication state.
|
|
927
|
+
|
|
928
|
+
### useLinkModal
|
|
929
|
+
|
|
930
|
+
The `useLinkModal` hook returns the state of the Link Socials modal, as well as functions to show and hide it.
|
|
931
|
+
|
|
932
|
+
**Note: The `<CampModal/>` component must be rendered in the component tree for the modal to be displayed.**
|
|
933
|
+
|
|
934
|
+
```jsx
|
|
935
|
+
import { useLinkModal, CampModal } from "@campnetwork/origin/react";
|
|
936
|
+
|
|
937
|
+
function App() {
|
|
938
|
+
const { isLinkingOpen, openTwitterModal } = useLinkModal();
|
|
939
|
+
|
|
940
|
+
return (
|
|
941
|
+
<div>
|
|
942
|
+
<CampModal />
|
|
943
|
+
<button onClick={openTwitterModal}>Link Twitter</button>
|
|
944
|
+
</div>
|
|
945
|
+
);
|
|
946
|
+
}
|
|
947
|
+
```
|
|
948
|
+
|
|
949
|
+
It returns the following properties and functions:
|
|
950
|
+
|
|
951
|
+
- `isLinkingOpen` - `boolean` - Whether the Link Socials modal is open or not.
|
|
952
|
+
- `openTwitterModal` - `() => void`
|
|
953
|
+
- `openDiscordModal` - `() => void`
|
|
954
|
+
- `openSpotifyModal` - `() => void`
|
|
955
|
+
- `openTiktokModal` - `() => void`
|
|
956
|
+
- `openTelegramModal` - `() => void`
|
|
957
|
+
- `linkTwitter` - `() => void`
|
|
958
|
+
- `linkDiscord` - `() => void`
|
|
959
|
+
- `linkSpotify` - `() => void`
|
|
960
|
+
- `linkTiktok` - `() => void`
|
|
961
|
+
- `linkTelegram` - `() => void`
|
|
962
|
+
- `unlinkTwitter` - `() => void`
|
|
963
|
+
- `unlinkDiscord` - `() => void`
|
|
964
|
+
- `unlinkSpotify` - `() => void`
|
|
965
|
+
- `unlinkTiktok` - `() => void`
|
|
966
|
+
- `unlinkTelegram` - `() => void`
|
|
967
|
+
- `closeModal` - `() => void`
|
|
968
|
+
|
|
969
|
+
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.
|
|
970
|
+
|
|
971
|
+
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.
|
|
972
|
+
|
|
973
|
+
## Origin Methods (`auth.origin`)
|
|
974
|
+
|
|
975
|
+
The `Origin` class provides methods for interacting with Origin IpNFTs, uploading files, managing user stats, and more. You can access these methods via `auth.origin` after authentication.
|
|
976
|
+
|
|
977
|
+
### Types
|
|
978
|
+
|
|
979
|
+
#### `LicenseTerms`
|
|
980
|
+
|
|
981
|
+
The license terms object used in minting and updating methods:
|
|
982
|
+
|
|
983
|
+
```typescript
|
|
984
|
+
type LicenseTerms = {
|
|
985
|
+
price: bigint; // Price in wei
|
|
986
|
+
duration: number; // Duration in seconds
|
|
987
|
+
royaltyBps: number; // Royalty in basis points (0-10000)
|
|
988
|
+
paymentToken: Address; // Payment token address (address(0) for native currency)
|
|
989
|
+
};
|
|
990
|
+
```
|
|
991
|
+
|
|
992
|
+
### File Upload & Minting
|
|
993
|
+
|
|
994
|
+
#### `mintFile(file: File, metadata: Record<string, unknown>, license: LicenseTerms, parentId?: bigint, options?: { progressCallback?: (percent: number) => void })`
|
|
995
|
+
|
|
996
|
+
Uploads a file and mints an IpNFT for it.
|
|
997
|
+
|
|
998
|
+
- `file`: The file to upload and mint.
|
|
999
|
+
- `metadata`: Additional metadata for the IpNFT.
|
|
1000
|
+
- `license`: License terms for the IpNFT (price, duration, royalty, payment token).
|
|
1001
|
+
- `parentId`: Optional parent token ID for derivative works.
|
|
1002
|
+
- `options.progressCallback`: Optional progress callback.
|
|
1003
|
+
- **Returns:** The minted token ID as a string, or throws an error on failure.
|
|
1004
|
+
|
|
1005
|
+
#### `mintSocial(source: "spotify" | "twitter" | "tiktok", license: LicenseTerms)`
|
|
1006
|
+
|
|
1007
|
+
Mints an IpNFT for a connected social account.
|
|
1008
|
+
|
|
1009
|
+
- `source`: The social platform.
|
|
1010
|
+
- `license`: License terms for the IpNFT.
|
|
1011
|
+
- **Returns:** The minted token ID as a string, or throws an error on failure.
|
|
1012
|
+
|
|
1013
|
+
### IpNFT & Marketplace Methods
|
|
1014
|
+
|
|
1015
|
+
The following methods are available for interacting with IpNFTs and the marketplace. All methods mirror the smart contract functions and require appropriate permissions.
|
|
1016
|
+
|
|
1017
|
+
#### Core IpNFT Methods
|
|
1018
|
+
|
|
1019
|
+
- `mintWithSignature(account: string, tokenId: bigint, parentId: bigint, creatorContentHash: string, uri: string, license: LicenseTerms, deadline: bigint, signature: string)` - Mint an IpNFT with a signature
|
|
1020
|
+
- `registerIpNFT(source: string, deadline: bigint, license: LicenseTerms, metadata: Record<string, unknown>, fileKey?: string, parentId?: bigint)` - Register an IpNFT for minting
|
|
1021
|
+
- `updateTerms(tokenId: bigint, license: LicenseTerms)` - Update license terms for an IpNFT
|
|
1022
|
+
- `requestDelete(tokenId: bigint)` - Request deletion of an IpNFT
|
|
1023
|
+
- `getTerms(tokenId: bigint)` - Get license terms for an IpNFT
|
|
1024
|
+
- `ownerOf(tokenId: bigint)` - Get the owner of an IpNFT
|
|
1025
|
+
- `balanceOf(owner: string)` - Get the balance of IpNFTs for an owner
|
|
1026
|
+
- `contentHash(tokenId: bigint)` - Get the content hash of an IpNFT
|
|
1027
|
+
- `tokenURI(tokenId: bigint)` - Get the metadata URI of an IpNFT
|
|
1028
|
+
- `dataStatus(tokenId: bigint)` - Get the data status of an IpNFT
|
|
1029
|
+
- `royaltyInfo(tokenId: bigint, value: bigint)` - Get royalty information
|
|
1030
|
+
- `getApproved(tokenId: bigint)` - Get the approved address for an IpNFT
|
|
1031
|
+
- `isApprovedForAll(owner: string, operator: string)` - Check if operator is approved for all tokens
|
|
1032
|
+
- `transferFrom(from: string, to: string, tokenId: bigint)` - Transfer an IpNFT
|
|
1033
|
+
- `safeTransferFrom(from: string, to: string, tokenId: bigint)` - Safely transfer an IpNFT
|
|
1034
|
+
- `approve(to: string, tokenId: bigint)` - Approve an address for a specific IpNFT
|
|
1035
|
+
- `setApprovalForAll(operator: string, approved: boolean)` - Set approval for all tokens
|
|
1036
|
+
|
|
1037
|
+
#### Marketplace Methods
|
|
1038
|
+
|
|
1039
|
+
- `buyAccess(tokenId: bigint, periods: number, value?: bigint)` - Buy access to an IpNFT
|
|
1040
|
+
- `renewAccess(tokenId: bigint, periods: number)` - Renew access to an IpNFT
|
|
1041
|
+
- `hasAccess(tokenId: bigint, user: string)` - Check if user has access to an IpNFT
|
|
1042
|
+
- `subscriptionExpiry(tokenId: bigint, user: string)` - Get subscription expiry for a user
|
|
1043
|
+
|
|
1044
|
+
> See the SDK source or contract ABI for full parameter details.
|
|
1045
|
+
|
|
1046
|
+
#### `buyAccessSmart(tokenId: bigint, periods: number)`
|
|
1047
|
+
|
|
1048
|
+
Buys access to an asset, handling payment approval if needed.
|
|
1049
|
+
|
|
1050
|
+
- `tokenId`: The IpNFT token ID.
|
|
1051
|
+
- `periods`: Number of periods to buy.
|
|
1052
|
+
- **Returns:** Result of the buy access transaction.
|
|
1053
|
+
|
|
1054
|
+
#### `getData(tokenId: bigint)`
|
|
1055
|
+
|
|
1056
|
+
Fetches metadata for a given IpNFT.
|
|
1057
|
+
|
|
1058
|
+
- `tokenId`: The IpNFT token ID.
|
|
1059
|
+
- **Returns:** Data object for the token.
|
|
1060
|
+
|
|
1061
|
+
### User Data & Stats
|
|
1062
|
+
|
|
1063
|
+
#### `getOriginUploads()`
|
|
1064
|
+
|
|
1065
|
+
Fetches the user's Origin file uploads.
|
|
1066
|
+
|
|
1067
|
+
- **Returns:** Array of upload data, or `null` on failure.
|
|
1068
|
+
|
|
1069
|
+
#### `getOriginUsage()`
|
|
1070
|
+
|
|
1071
|
+
Fetches the user's Origin stats (multiplier, points, usage, etc).
|
|
1072
|
+
|
|
1073
|
+
- **Returns:** Object with user stats including:
|
|
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.
|