@campnetwork/origin 0.0.6 → 0.0.8
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/README.md +83 -0
- package/dist/core.cjs +18 -8
- package/dist/core.d.ts +5 -5
- package/dist/core.esm.d.ts +5 -5
- package/dist/core.esm.js +79 -69
- package/dist/react/index.esm.d.ts +5 -5
- package/dist/react/index.esm.js +49 -47
- package/package.json +1 -1
|
@@ -27,10 +27,10 @@ declare enum DataStatus {
|
|
|
27
27
|
DELETED = 2
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
* Represents the source of
|
|
30
|
+
* Represents the source of an IpNFT.
|
|
31
31
|
* This can be one of the supported social media platforms or a file upload.
|
|
32
32
|
*/
|
|
33
|
-
type
|
|
33
|
+
type IpNFTSource = "spotify" | "twitter" | "tiktok" | "file";
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* Mints a Data NFT with a signature.
|
|
@@ -51,7 +51,7 @@ declare function mintWithSignature(this: Origin, to: Address, tokenId: bigint, h
|
|
|
51
51
|
* @param fileKey Optional file key for file uploads.
|
|
52
52
|
* @return A promise that resolves with the registration data.
|
|
53
53
|
*/
|
|
54
|
-
declare function
|
|
54
|
+
declare function registerIpNFT(this: Origin, source: IpNFTSource, deadline: bigint, licenseTerms: LicenseTerms, fileKey?: string | string[]): Promise<any>;
|
|
55
55
|
|
|
56
56
|
declare function updateTerms(this: Origin, tokenId: bigint, newTerms: LicenseTerms): Promise<any>;
|
|
57
57
|
|
|
@@ -112,7 +112,7 @@ type CallOptions = {
|
|
|
112
112
|
declare class Origin {
|
|
113
113
|
#private;
|
|
114
114
|
mintWithSignature: typeof mintWithSignature;
|
|
115
|
-
|
|
115
|
+
registerIpNFT: typeof registerIpNFT;
|
|
116
116
|
updateTerms: typeof updateTerms;
|
|
117
117
|
requestDelete: typeof requestDelete;
|
|
118
118
|
getTerms: typeof getTerms;
|
|
@@ -143,7 +143,7 @@ declare class Origin {
|
|
|
143
143
|
mintFile: (file: File, license: LicenseTerms, options?: {
|
|
144
144
|
progressCallback?: (percent: number) => void;
|
|
145
145
|
}) => Promise<string | null>;
|
|
146
|
-
mintSocial: (source: "spotify" | "twitter" | "tiktok") => Promise<string | null>;
|
|
146
|
+
mintSocial: (source: "spotify" | "twitter" | "tiktok", license: LicenseTerms) => Promise<string | null>;
|
|
147
147
|
getOriginUploads: () => Promise<any>;
|
|
148
148
|
/**
|
|
149
149
|
* Get the user's Origin stats (multiplier, consent, usage, etc.).
|
package/dist/react/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import React, { createContext, useState, useContext, useEffect, useLayoutEffect, useRef, useSyncExternalStore } from 'react';
|
|
3
|
-
import { custom, createWalletClient, createPublicClient, http, erc20Abi, getAbiItem, encodeFunctionData, zeroAddress } from 'viem';
|
|
3
|
+
import { custom, createWalletClient, createPublicClient, http, erc20Abi, getAbiItem, encodeFunctionData, zeroAddress, checksumAddress } from 'viem';
|
|
4
4
|
import { toAccount } from 'viem/accounts';
|
|
5
5
|
import { createSiweMessage } from 'viem/siwe';
|
|
6
6
|
import axios from 'axios';
|
|
@@ -164,8 +164,8 @@ var constants = {
|
|
|
164
164
|
TIKTOK_LINKED: "4a2ffdd3-f0e9-4784-8b49-ff76ec1c0a6a",
|
|
165
165
|
TELEGRAM_LINKED: "9006bc5d-bcc9-4d01-a860-4f1a201e8e47",
|
|
166
166
|
},
|
|
167
|
-
DATANFT_CONTRACT_ADDRESS: "
|
|
168
|
-
MARKETPLACE_CONTRACT_ADDRESS: "
|
|
167
|
+
DATANFT_CONTRACT_ADDRESS: "0xb55066f2793773B3784f8c57c415a8b5932B33Cd",
|
|
168
|
+
MARKETPLACE_CONTRACT_ADDRESS: "0x977fdEF62CE095Ae8750Fd3496730F24F60dea7a",
|
|
169
169
|
};
|
|
170
170
|
|
|
171
171
|
let providers = [];
|
|
@@ -1423,11 +1423,17 @@ function mintWithSignature(to, tokenId, hash, uri, licenseTerms, deadline, signa
|
|
|
1423
1423
|
* @param fileKey Optional file key for file uploads.
|
|
1424
1424
|
* @return A promise that resolves with the registration data.
|
|
1425
1425
|
*/
|
|
1426
|
-
function
|
|
1426
|
+
function registerIpNFT(source, deadline, licenseTerms, fileKey) {
|
|
1427
1427
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1428
1428
|
const body = {
|
|
1429
1429
|
source,
|
|
1430
|
-
deadline: deadline
|
|
1430
|
+
deadline: Number(deadline),
|
|
1431
|
+
licenseTerms: {
|
|
1432
|
+
price: licenseTerms.price.toString(),
|
|
1433
|
+
duration: licenseTerms.duration,
|
|
1434
|
+
royaltyBps: licenseTerms.royaltyBps,
|
|
1435
|
+
paymentToken: licenseTerms.paymentToken,
|
|
1436
|
+
},
|
|
1431
1437
|
};
|
|
1432
1438
|
if (fileKey !== undefined) {
|
|
1433
1439
|
body.fileKey = fileKey;
|
|
@@ -2185,45 +2191,44 @@ class Origin {
|
|
|
2185
2191
|
if (!this.viemClient) {
|
|
2186
2192
|
throw new Error("WalletClient not connected.");
|
|
2187
2193
|
}
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
console.error("Invalid upload info:", info);
|
|
2192
|
-
return null;
|
|
2193
|
-
}
|
|
2194
|
-
const deadline = BigInt(Math.floor(Date.now() / 1000) + 600); // 10 minutes from now
|
|
2195
|
-
const registration = yield this.registerDataNFT("file", deadline, info.key);
|
|
2196
|
-
const { tokenId, signerAddress, hash, signature } = registration;
|
|
2197
|
-
if (!tokenId || !signerAddress || !hash || signature === undefined) {
|
|
2198
|
-
console.error("Invalid registration data:", registration);
|
|
2199
|
-
return null;
|
|
2200
|
-
}
|
|
2201
|
-
const [account] = yield this.viemClient.request({
|
|
2202
|
-
method: "eth_requestAccounts",
|
|
2203
|
-
params: [],
|
|
2204
|
-
});
|
|
2205
|
-
const mintResult = yield this.mintWithSignature(account, tokenId, hash, info.url, license, deadline, signature);
|
|
2206
|
-
return tokenId.toString();
|
|
2194
|
+
const info = yield this.uploadFile(file, options);
|
|
2195
|
+
if (!info || !info.key) {
|
|
2196
|
+
throw new Error("Failed to upload file or get upload info.");
|
|
2207
2197
|
}
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2198
|
+
const deadline = BigInt(Math.floor(Date.now()) + 600); // 10 minutes from now
|
|
2199
|
+
const registration = yield this.registerIpNFT("file", deadline, license, info.key);
|
|
2200
|
+
const { tokenId, signerAddress, creatorContentHash, signature, uri } = registration;
|
|
2201
|
+
if (!tokenId ||
|
|
2202
|
+
!signerAddress ||
|
|
2203
|
+
!creatorContentHash ||
|
|
2204
|
+
signature === undefined ||
|
|
2205
|
+
!uri) {
|
|
2206
|
+
throw new Error("Failed to register IpNFT: Missing required fields in registration response.");
|
|
2211
2207
|
}
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
return null;
|
|
2220
|
-
}
|
|
2221
|
-
return registration.tokenId.toString();
|
|
2208
|
+
const [account] = yield this.viemClient.request({
|
|
2209
|
+
method: "eth_requestAccounts",
|
|
2210
|
+
params: [],
|
|
2211
|
+
});
|
|
2212
|
+
const mintResult = yield this.mintWithSignature(account, tokenId, creatorContentHash, uri, license, deadline, signature);
|
|
2213
|
+
if (mintResult.status !== "0x1") {
|
|
2214
|
+
throw new Error(`Minting failed with status: ${mintResult.status}`);
|
|
2222
2215
|
}
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2216
|
+
return tokenId.toString();
|
|
2217
|
+
});
|
|
2218
|
+
this.mintSocial = (source, license) => __awaiter(this, void 0, void 0, function* () {
|
|
2219
|
+
// try {
|
|
2220
|
+
const deadline = BigInt(Math.floor(Date.now()) + 600); // 10 minutes from now (temp)
|
|
2221
|
+
const registration = yield this.registerIpNFT(source, deadline, license);
|
|
2222
|
+
if (!registration) {
|
|
2223
|
+
// console.error("Failed to register IpNFT");
|
|
2224
|
+
// return null;
|
|
2225
|
+
throw new Error("Failed to register Social IpNFT");
|
|
2226
2226
|
}
|
|
2227
|
+
return registration.tokenId.toString();
|
|
2228
|
+
// } catch (error) {
|
|
2229
|
+
// console.error("Failed to mint social IpNFT:", error);
|
|
2230
|
+
// return null;
|
|
2231
|
+
// }
|
|
2227
2232
|
});
|
|
2228
2233
|
this.getOriginUploads = () => __awaiter(this, void 0, void 0, function* () {
|
|
2229
2234
|
const res = yield fetch(`${constants.AUTH_HUB_BASE_API}/auth/origin/files`, {
|
|
@@ -2243,7 +2248,7 @@ class Origin {
|
|
|
2243
2248
|
this.viemClient = viemClient;
|
|
2244
2249
|
// DataNFT methods
|
|
2245
2250
|
this.mintWithSignature = mintWithSignature.bind(this);
|
|
2246
|
-
this.
|
|
2251
|
+
this.registerIpNFT = registerIpNFT.bind(this);
|
|
2247
2252
|
this.updateTerms = updateTerms.bind(this);
|
|
2248
2253
|
this.requestDelete = requestDelete.bind(this);
|
|
2249
2254
|
this.getTerms = getTerms.bind(this);
|
|
@@ -2729,6 +2734,7 @@ class Auth {
|
|
|
2729
2734
|
if (!this.walletAddress) {
|
|
2730
2735
|
yield __classPrivateFieldGet(this, _Auth_instances, "m", _Auth_requestAccount).call(this);
|
|
2731
2736
|
}
|
|
2737
|
+
this.walletAddress = checksumAddress(this.walletAddress);
|
|
2732
2738
|
const nonce = yield __classPrivateFieldGet(this, _Auth_instances, "m", _Auth_fetchNonce).call(this);
|
|
2733
2739
|
const message = __classPrivateFieldGet(this, _Auth_instances, "m", _Auth_createMessage).call(this, nonce);
|
|
2734
2740
|
const signature = yield this.viem.signMessage({
|
|
@@ -3163,10 +3169,6 @@ _Auth_triggers = new WeakMap(), _Auth_ackeeInstance = new WeakMap(), _Auth_insta
|
|
|
3163
3169
|
address: walletAddress,
|
|
3164
3170
|
});
|
|
3165
3171
|
}
|
|
3166
|
-
else {
|
|
3167
|
-
console.warn("No matching provider was given for the stored wallet address. Trying to recover provider.");
|
|
3168
|
-
yield this.recoverProvider();
|
|
3169
|
-
}
|
|
3170
3172
|
}
|
|
3171
3173
|
else {
|
|
3172
3174
|
this.isAuthenticated = false;
|
|
@@ -3176,8 +3178,8 @@ _Auth_triggers = new WeakMap(), _Auth_ackeeInstance = new WeakMap(), _Auth_insta
|
|
|
3176
3178
|
return __awaiter(this, void 0, void 0, function* () {
|
|
3177
3179
|
try {
|
|
3178
3180
|
const [account] = yield this.viem.requestAddresses();
|
|
3179
|
-
this.walletAddress = account;
|
|
3180
|
-
return
|
|
3181
|
+
this.walletAddress = checksumAddress(account);
|
|
3182
|
+
return this.walletAddress;
|
|
3181
3183
|
}
|
|
3182
3184
|
catch (e) {
|
|
3183
3185
|
throw new APIError(e);
|