@campnetwork/origin 0.0.7 → 0.0.9

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.
@@ -36,6 +36,7 @@ type IpNFTSource = "spotify" | "twitter" | "tiktok" | "file";
36
36
  * Mints a Data NFT with a signature.
37
37
  * @param to The address to mint the NFT to.
38
38
  * @param tokenId The ID of the token to mint.
39
+ * @param parentId The ID of the parent NFT, if applicable.
39
40
  * @param hash The hash of the data associated with the NFT.
40
41
  * @param uri The URI of the NFT metadata.
41
42
  * @param licenseTerms The terms of the license for the NFT.
@@ -43,7 +44,7 @@ type IpNFTSource = "spotify" | "twitter" | "tiktok" | "file";
43
44
  * @param signature The signature for the minting operation.
44
45
  * @returns A promise that resolves when the minting is complete.
45
46
  */
46
- declare function mintWithSignature(this: Origin, to: Address, tokenId: bigint, hash: Hex, uri: string, licenseTerms: LicenseTerms, deadline: bigint, signature: Hex): Promise<any>;
47
+ declare function mintWithSignature(this: Origin, to: Address, tokenId: bigint, parentId: bigint, hash: Hex, uri: string, licenseTerms: LicenseTerms, deadline: bigint, signature: Hex): Promise<any>;
47
48
  /**
48
49
  * Registers a Data NFT with the Origin service in order to obtain a signature for minting.
49
50
  * @param source The source of the Data NFT (e.g., "spotify", "twitter", "tiktok", or "file").
@@ -51,7 +52,7 @@ declare function mintWithSignature(this: Origin, to: Address, tokenId: bigint, h
51
52
  * @param fileKey Optional file key for file uploads.
52
53
  * @return A promise that resolves with the registration data.
53
54
  */
54
- declare function registerIpNFT(this: Origin, source: IpNFTSource, deadline: bigint, licenseTerms: LicenseTerms, fileKey?: string | string[]): Promise<any>;
55
+ declare function registerIpNFT(this: Origin, source: IpNFTSource, deadline: bigint, licenseTerms: LicenseTerms, metadata: Record<string, unknown>, fileKey?: string | string[], parentId?: bigint): Promise<any>;
55
56
 
56
57
  declare function updateTerms(this: Origin, tokenId: bigint, newTerms: LicenseTerms): Promise<any>;
57
58
 
@@ -140,7 +141,7 @@ declare class Origin {
140
141
  uploadFile: (file: File, options?: {
141
142
  progressCallback?: (percent: number) => void;
142
143
  }) => Promise<any>;
143
- mintFile: (file: File, license: LicenseTerms, options?: {
144
+ mintFile: (file: File, metadata: Record<string, unknown>, license: LicenseTerms, parentId?: bigint, options?: {
144
145
  progressCallback?: (percent: number) => void;
145
146
  }) => Promise<string | null>;
146
147
  mintSocial: (source: "spotify" | "twitter" | "tiktok", license: LicenseTerms) => Promise<string | null>;
@@ -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: "0xb55066f2793773B3784f8c57c415a8b5932B33Cd",
168
- MARKETPLACE_CONTRACT_ADDRESS: "0x977fdEF62CE095Ae8750Fd3496730F24F60dea7a",
167
+ DATANFT_CONTRACT_ADDRESS: "0xF90733b9eCDa3b49C250B2C3E3E42c96fC93324E",
168
+ MARKETPLACE_CONTRACT_ADDRESS: "0x5c5e6b458b2e3924E7688b8Dee1Bb49088F6Fef5",
169
169
  };
170
170
 
171
171
  let providers = [];
@@ -256,13 +256,23 @@ var abi$1 = [
256
256
  inputs: [
257
257
  {
258
258
  internalType: "string",
259
- name: "_name",
259
+ name: "name_",
260
260
  type: "string"
261
261
  },
262
262
  {
263
263
  internalType: "string",
264
- name: "_symbol",
264
+ name: "symbol_",
265
265
  type: "string"
266
+ },
267
+ {
268
+ internalType: "uint256",
269
+ name: "maxTermDuration_",
270
+ type: "uint256"
271
+ },
272
+ {
273
+ internalType: "address",
274
+ name: "signer_",
275
+ type: "address"
266
276
  }
267
277
  ],
268
278
  stateMutability: "nonpayable",
@@ -395,6 +405,12 @@ var abi$1 = [
395
405
  name: "InvalidDeadline",
396
406
  type: "error"
397
407
  },
408
+ {
409
+ inputs: [
410
+ ],
411
+ name: "InvalidDuration",
412
+ type: "error"
413
+ },
398
414
  {
399
415
  inputs: [
400
416
  {
@@ -916,6 +932,20 @@ var abi$1 = [
916
932
  stateMutability: "view",
917
933
  type: "function"
918
934
  },
935
+ {
936
+ inputs: [
937
+ ],
938
+ name: "maxTermDuration",
939
+ outputs: [
940
+ {
941
+ internalType: "uint256",
942
+ name: "",
943
+ type: "uint256"
944
+ }
945
+ ],
946
+ stateMutability: "view",
947
+ type: "function"
948
+ },
919
949
  {
920
950
  inputs: [
921
951
  {
@@ -928,6 +958,11 @@ var abi$1 = [
928
958
  name: "tokenId",
929
959
  type: "uint256"
930
960
  },
961
+ {
962
+ internalType: "uint256",
963
+ name: "parentId",
964
+ type: "uint256"
965
+ },
931
966
  {
932
967
  internalType: "bytes32",
933
968
  name: "creatorContentHash",
@@ -1029,6 +1064,25 @@ var abi$1 = [
1029
1064
  stateMutability: "view",
1030
1065
  type: "function"
1031
1066
  },
1067
+ {
1068
+ inputs: [
1069
+ {
1070
+ internalType: "uint256",
1071
+ name: "",
1072
+ type: "uint256"
1073
+ }
1074
+ ],
1075
+ name: "parentIpOf",
1076
+ outputs: [
1077
+ {
1078
+ internalType: "uint256",
1079
+ name: "",
1080
+ type: "uint256"
1081
+ }
1082
+ ],
1083
+ stateMutability: "view",
1084
+ type: "function"
1085
+ },
1032
1086
  {
1033
1087
  inputs: [
1034
1088
  ],
@@ -1200,6 +1254,34 @@ var abi$1 = [
1200
1254
  stateMutability: "nonpayable",
1201
1255
  type: "function"
1202
1256
  },
1257
+ {
1258
+ inputs: [
1259
+ {
1260
+ internalType: "address",
1261
+ name: "_signer",
1262
+ type: "address"
1263
+ }
1264
+ ],
1265
+ name: "setSigner",
1266
+ outputs: [
1267
+ ],
1268
+ stateMutability: "nonpayable",
1269
+ type: "function"
1270
+ },
1271
+ {
1272
+ inputs: [
1273
+ ],
1274
+ name: "signer",
1275
+ outputs: [
1276
+ {
1277
+ internalType: "address",
1278
+ name: "",
1279
+ type: "address"
1280
+ }
1281
+ ],
1282
+ stateMutability: "view",
1283
+ type: "function"
1284
+ },
1203
1285
  {
1204
1286
  inputs: [
1205
1287
  {
@@ -1404,6 +1486,7 @@ var abi$1 = [
1404
1486
  * Mints a Data NFT with a signature.
1405
1487
  * @param to The address to mint the NFT to.
1406
1488
  * @param tokenId The ID of the token to mint.
1489
+ * @param parentId The ID of the parent NFT, if applicable.
1407
1490
  * @param hash The hash of the data associated with the NFT.
1408
1491
  * @param uri The URI of the NFT metadata.
1409
1492
  * @param licenseTerms The terms of the license for the NFT.
@@ -1411,9 +1494,9 @@ var abi$1 = [
1411
1494
  * @param signature The signature for the minting operation.
1412
1495
  * @returns A promise that resolves when the minting is complete.
1413
1496
  */
1414
- function mintWithSignature(to, tokenId, hash, uri, licenseTerms, deadline, signature) {
1497
+ function mintWithSignature(to, tokenId, parentId, hash, uri, licenseTerms, deadline, signature) {
1415
1498
  return __awaiter(this, void 0, void 0, function* () {
1416
- return yield this.callContractMethod(constants.DATANFT_CONTRACT_ADDRESS, abi$1, "mintWithSignature", [to, tokenId, hash, uri, licenseTerms, deadline, signature], { waitForReceipt: true });
1499
+ return yield this.callContractMethod(constants.DATANFT_CONTRACT_ADDRESS, abi$1, "mintWithSignature", [to, tokenId, parentId, hash, uri, licenseTerms, deadline, signature], { waitForReceipt: true });
1417
1500
  });
1418
1501
  }
1419
1502
  /**
@@ -1423,7 +1506,7 @@ function mintWithSignature(to, tokenId, hash, uri, licenseTerms, deadline, signa
1423
1506
  * @param fileKey Optional file key for file uploads.
1424
1507
  * @return A promise that resolves with the registration data.
1425
1508
  */
1426
- function registerIpNFT(source, deadline, licenseTerms, fileKey) {
1509
+ function registerIpNFT(source, deadline, licenseTerms, metadata, fileKey, parentId) {
1427
1510
  return __awaiter(this, void 0, void 0, function* () {
1428
1511
  const body = {
1429
1512
  source,
@@ -1434,6 +1517,8 @@ function registerIpNFT(source, deadline, licenseTerms, fileKey) {
1434
1517
  royaltyBps: licenseTerms.royaltyBps,
1435
1518
  paymentToken: licenseTerms.paymentToken,
1436
1519
  },
1520
+ metadata,
1521
+ parentId: Number(parentId) || 0,
1437
1522
  };
1438
1523
  if (fileKey !== undefined) {
1439
1524
  body.fileKey = fileKey;
@@ -2187,7 +2272,7 @@ class Origin {
2187
2272
  yield __classPrivateFieldGet(this, _Origin_setOriginStatus, "f").call(this, uploadInfo.key, "success");
2188
2273
  return uploadInfo;
2189
2274
  });
2190
- this.mintFile = (file, license, options) => __awaiter(this, void 0, void 0, function* () {
2275
+ this.mintFile = (file, metadata, license, parentId, options) => __awaiter(this, void 0, void 0, function* () {
2191
2276
  if (!this.viemClient) {
2192
2277
  throw new Error("WalletClient not connected.");
2193
2278
  }
@@ -2196,7 +2281,7 @@ class Origin {
2196
2281
  throw new Error("Failed to upload file or get upload info.");
2197
2282
  }
2198
2283
  const deadline = BigInt(Math.floor(Date.now()) + 600); // 10 minutes from now
2199
- const registration = yield this.registerIpNFT("file", deadline, license, info.key);
2284
+ const registration = yield this.registerIpNFT("file", deadline, license, metadata, info.key, parentId);
2200
2285
  const { tokenId, signerAddress, creatorContentHash, signature, uri } = registration;
2201
2286
  if (!tokenId ||
2202
2287
  !signerAddress ||
@@ -2209,7 +2294,7 @@ class Origin {
2209
2294
  method: "eth_requestAccounts",
2210
2295
  params: [],
2211
2296
  });
2212
- const mintResult = yield this.mintWithSignature(account, tokenId, creatorContentHash, uri, license, deadline, signature);
2297
+ const mintResult = yield this.mintWithSignature(account, tokenId, parentId || BigInt(0), creatorContentHash, uri, license, deadline, signature);
2213
2298
  if (mintResult.status !== "0x1") {
2214
2299
  throw new Error(`Minting failed with status: ${mintResult.status}`);
2215
2300
  }
@@ -2218,7 +2303,11 @@ class Origin {
2218
2303
  this.mintSocial = (source, license) => __awaiter(this, void 0, void 0, function* () {
2219
2304
  // try {
2220
2305
  const deadline = BigInt(Math.floor(Date.now()) + 600); // 10 minutes from now (temp)
2221
- const registration = yield this.registerIpNFT(source, deadline, license);
2306
+ const metadata = {
2307
+ name: `${source} IpNFT`,
2308
+ description: `This is a ${source} IpNFT`,
2309
+ };
2310
+ const registration = yield this.registerIpNFT(source, deadline, license, metadata);
2222
2311
  if (!registration) {
2223
2312
  // console.error("Failed to register IpNFT");
2224
2313
  // return null;
@@ -2734,6 +2823,7 @@ class Auth {
2734
2823
  if (!this.walletAddress) {
2735
2824
  yield __classPrivateFieldGet(this, _Auth_instances, "m", _Auth_requestAccount).call(this);
2736
2825
  }
2826
+ this.walletAddress = checksumAddress(this.walletAddress);
2737
2827
  const nonce = yield __classPrivateFieldGet(this, _Auth_instances, "m", _Auth_fetchNonce).call(this);
2738
2828
  const message = __classPrivateFieldGet(this, _Auth_instances, "m", _Auth_createMessage).call(this, nonce);
2739
2829
  const signature = yield this.viem.signMessage({
@@ -3168,10 +3258,6 @@ _Auth_triggers = new WeakMap(), _Auth_ackeeInstance = new WeakMap(), _Auth_insta
3168
3258
  address: walletAddress,
3169
3259
  });
3170
3260
  }
3171
- else {
3172
- console.warn("No matching provider was given for the stored wallet address. Trying to recover provider.");
3173
- yield this.recoverProvider();
3174
- }
3175
3261
  }
3176
3262
  else {
3177
3263
  this.isAuthenticated = false;
@@ -3181,8 +3267,8 @@ _Auth_triggers = new WeakMap(), _Auth_ackeeInstance = new WeakMap(), _Auth_insta
3181
3267
  return __awaiter(this, void 0, void 0, function* () {
3182
3268
  try {
3183
3269
  const [account] = yield this.viem.requestAddresses();
3184
- this.walletAddress = account;
3185
- return account;
3270
+ this.walletAddress = checksumAddress(account);
3271
+ return this.walletAddress;
3186
3272
  }
3187
3273
  catch (e) {
3188
3274
  throw new APIError(e);
@@ -3936,7 +4022,11 @@ const FileUpload = ({ onFileUpload, accept, maxFileSize, }) => {
3936
4022
  royaltyBps, // royalty basis points
3937
4023
  zeroAddress // payment token
3938
4024
  );
3939
- const res = yield ((_a = auth === null || auth === void 0 ? void 0 : auth.origin) === null || _a === void 0 ? void 0 : _a.mintFile(selectedFile, license, {
4025
+ const metadata = {
4026
+ name: selectedFile.name,
4027
+ description: `This is a file uploaded by ${auth === null || auth === void 0 ? void 0 : auth.walletAddress}`,
4028
+ };
4029
+ const res = yield ((_a = auth === null || auth === void 0 ? void 0 : auth.origin) === null || _a === void 0 ? void 0 : _a.mintFile(selectedFile, metadata, license, BigInt(0), {
3940
4030
  progressCallback(percent) {
3941
4031
  setUploadProgress(percent);
3942
4032
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@campnetwork/origin",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "main": "dist/core.cjs",
5
5
  "exports": {
6
6
  ".": {