@campnetwork/origin 1.0.0-alpha.5 → 1.0.0-alpha.7

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/dist/core.cjs CHANGED
@@ -73,7 +73,7 @@ let y=null,c=null;const h=()=>(c||(c=t.createPublicClient({chain:l,transport:t.h
73
73
  * Calls the getOrCreateRoyaltyVault method on the IPNFT contract.
74
74
  * @param tokenOwner The address of the token owner for whom to get or create the royalty vault.
75
75
  * @returns The address of the royalty vault associated with the specified token owner.
76
- */function S(e){return a(this,void 0,void 0,(function*(){const t=yield this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"getOrCreateRoyaltyVault",[e],{waitForReceipt:!0,simulate:!0});return console.log("Royalty Vault Tx:",t),t.simulatedResult}))}
76
+ */function S(e){return a(this,void 0,void 0,(function*(){const t=yield this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"getOrCreateRoyaltyVault",[e],{waitForReceipt:!0,simulate:!1});return console.log("Royalty Vault Tx:",t),t.simulatedResult}))}
77
77
  /**
78
78
  * Returns the license terms associated with a specific token ID.
79
79
  * @param tokenId The token ID to query.
@@ -134,8 +134,8 @@ let y=null,c=null;const h=()=>(c||(c=t.createPublicClient({chain:l,transport:t.h
134
134
  this.mintWithSignature=E.bind(this),this.registerIpNFT=_.bind(this),this.updateTerms=C.bind(this),this.finalizeDelete=k.bind(this),this.getOrCreateRoyaltyVault=S.bind(this),this.getTerms=N.bind(this),this.ownerOf=D.bind(this),this.balanceOf=P.bind(this),this.tokenURI=x.bind(this),this.dataStatus=O.bind(this),this.isApprovedForAll=U.bind(this),this.transferFrom=M.bind(this),this.safeTransferFrom=B.bind(this),this.approve=R.bind(this),this.setApprovalForAll=F.bind(this),
135
135
  // Marketplace methods
136
136
  this.buyAccess=$.bind(this),this.hasAccess=H.bind(this),this.subscriptionExpiry=j.bind(this)}getJwt(){return this.jwt}setViemClient(e){this.viemClient=e}uploadFile(t,n){return a(this,void 0,void 0,(function*(){let i;try{i=yield r(this,L,"m",q).call(this,t)}catch(e){throw console.error("Failed to generate upload URL:",e),new Error(`Failed to generate upload URL: ${e instanceof Error?e.message:String(e)}`)}if(!i)throw new Error("Failed to generate upload URL: No upload info returned");try{yield((t,n,i)=>new Promise(((a,r)=>{e.put(n,t,Object.assign({headers:{"Content-Type":t.type}},"undefined"!=typeof window&&"function"==typeof i?{onUploadProgress:e=>{if(e.total){const t=e.loaded/e.total*100;i(t)}}}:{})).then((e=>{a(e.data)})).catch((e=>{var t;const n=(null===(t=null==e?void 0:e.response)||void 0===t?void 0:t.data)||(null==e?void 0:e.message)||"Upload failed";r(n)}))})))(t,i.url,(null==n?void 0:n.progressCallback)||(()=>{}))}catch(e){try{yield r(this,L,"m",W).call(this,i.key,"failed")}catch(e){console.error("Failed to update status to failed:",e)}const t=e instanceof Error?e.message:String(e);throw new Error(`Failed to upload file: ${t}`)}try{yield r(this,L,"m",W).call(this,i.key,"success")}catch(e){console.error("Failed to update status to success:",e)}return i}))}mintFile(e,t,n,i,r){return a(this,void 0,void 0,(function*(){if(!this.viemClient)throw new Error("WalletClient not connected.");const a=yield this.uploadFile(e,r);if(!a||!a.key)throw new Error("Failed to upload file or get upload info.");const s=BigInt(Date.now()+6e5),o=yield this.registerIpNFT("file",s,n,t,a.key,i),{tokenId:d,signerAddress:u,creatorContentHash:p,signature:l,uri:y}=o;// 10 minutes from now
137
- if(!(d&&u&&p&&void 0!==l&&y))throw new Error("Failed to register IpNFT: Missing required fields in registration response.");const[c]=yield this.viemClient.request({method:"eth_requestAccounts",params:[]}),h=yield this.mintWithSignature(c,d,i||[],p,y,n,s,l);if("0x1"!==h.status)throw console.error("Minting failed:",h),new Error(`Minting failed with status: ${h.status}`);return d.toString()}))}mintSocial(e,t,n){return a(this,void 0,void 0,(function*(){if(!this.viemClient)throw new Error("WalletClient not connected.");const i=BigInt(Math.floor(Date.now()/1e3)+600),a=yield this.registerIpNFT(e,i,n,t),{tokenId:r,signerAddress:s,creatorContentHash:o,signature:d,uri:u}=a;// 10 minutes from now
138
- if(!(r&&s&&o&&void 0!==d&&u))throw new Error("Failed to register Social IpNFT: Missing required fields in registration response.");const[p]=yield this.viemClient.request({method:"eth_requestAccounts",params:[]}),l=yield this.mintWithSignature(p,r,[],o,u,n,i,d);if("0x1"!==l.status)throw new Error(`Minting Social IpNFT failed with status: ${l.status}`);return r.toString()}))}getOriginUploads(){return a(this,void 0,void 0,(function*(){const e=yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/files`,{method:"GET",headers:{Authorization:`Bearer ${this.jwt}`}});if(!e.ok)return console.error("Failed to get origin uploads"),null;return(yield e.json()).data}))}
137
+ if(!(d&&u&&p&&void 0!==l&&y))throw new Error("Failed to register IpNFT: Missing required fields in registration response.");const c=(yield this.viemClient.request({method:"eth_requestAccounts",params:[]}))[0],h=yield this.mintWithSignature(c,d,i||[],p,y,n,s,l);if("0x1"!==h.status)throw console.error("Minting failed:",h),new Error(`Minting failed with status: ${h.status}`);return d.toString()}))}mintSocial(e,t,n){return a(this,void 0,void 0,(function*(){if(!this.viemClient)throw new Error("WalletClient not connected.");const i=BigInt(Math.floor(Date.now()/1e3)+600),a=yield this.registerIpNFT(e,i,n,t),{tokenId:r,signerAddress:s,creatorContentHash:o,signature:d,uri:u}=a;// 10 minutes from now
138
+ if(!(r&&s&&o&&void 0!==d&&u))throw new Error("Failed to register Social IpNFT: Missing required fields in registration response.");const p=(yield this.viemClient.request({method:"eth_requestAccounts",params:[]}))[0],l=yield this.mintWithSignature(p,r,[],o,u,n,i,d);if("0x1"!==l.status)throw new Error(`Minting Social IpNFT failed with status: ${l.status}`);return r.toString()}))}getOriginUploads(){return a(this,void 0,void 0,(function*(){const e=yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/files`,{method:"GET",headers:{Authorization:`Bearer ${this.jwt}`}});if(!e.ok)return console.error("Failed to get origin uploads"),null;return(yield e.json()).data}))}
139
139
  /**
140
140
  * Get the user's Origin stats (multiplier, consent, usage, etc.).
141
141
  * @returns {Promise<OriginUsageReturnType>} A promise that resolves with the user's Origin stats.
@@ -155,14 +155,14 @@ if(!(r&&s&&o&&void 0!==d&&u))throw new Error("Failed to register Social IpNFT: M
155
155
  * @param {CallOptions} [options] The call options.
156
156
  * @returns {Promise<any>} A promise that resolves with the result of the contract call or transaction hash.
157
157
  * @throws {Error} - Throws an error if the wallet client is not connected and the method is not a view function.
158
- */callContractMethod(e,n,i,s){return a(this,arguments,void 0,(function*(e,n,i,a,s={}){const o=t.getAbiItem({abi:n,name:i}),d=o&&"stateMutability"in o&&("view"===o.stateMutability||"pure"===o.stateMutability);if(!d&&!this.viemClient)throw new Error("WalletClient not connected.");if(d){const t=h();return(yield t.readContract({address:e,abi:n,functionName:i,args:a}))||null}{const[t]=yield this.viemClient.request({method:"eth_requestAccounts",params:[]});yield r(this,L,"m",K).call(this,this.environment.CHAIN);const o=h(),{result:d,request:u}=yield o.simulateContract({account:t,address:e,abi:n,functionName:i,args:a,value:s.value});
158
+ */callContractMethod(e,n,i,s){return a(this,arguments,void 0,(function*(e,n,i,a,s={}){const o=t.getAbiItem({abi:n,name:i});if(o&&"stateMutability"in o&&("view"===o.stateMutability||"pure"===o.stateMutability)){const t=h();return(yield t.readContract({address:e,abi:n,functionName:i,args:a}))||null}if(!this.viemClient)throw new Error("WalletClient not connected.");const[d]=yield this.viemClient.request({method:"eth_requestAccounts",params:[]});yield r(this,L,"m",K).call(this,this.environment.CHAIN);const u=h(),{result:p,request:l}=yield u.simulateContract({account:d,address:e,abi:n,functionName:i,args:a,value:s.value});
159
159
  // simulate
160
- if(s.simulate)return d;try{const e=yield this.viemClient.sendTransaction(u);if("string"!=typeof e)throw new Error("Transaction failed to send.");if(!s.waitForReceipt)return{txHash:e,simulatedResult:d};return{txHash:e,receipt:yield r(this,L,"m",z).call(this,e),simulatedResult:d}}catch(e){throw console.error("Transaction failed:",e),new Error("Transaction failed: "+e)}}}))}
160
+ if(s.simulate)return p;try{const e=yield this.viemClient.writeContract(l);if("string"!=typeof e)throw new Error("Transaction failed to send.");if(!s.waitForReceipt)return{txHash:e,simulatedResult:p};return{txHash:e,receipt:yield r(this,L,"m",z).call(this,e),simulatedResult:p}}catch(e){throw console.error("Transaction failed:",e),new Error("Transaction failed: "+e)}}))}
161
161
  /**
162
162
  * Buy access to an asset by first checking its price via getTerms, then calling buyAccess.
163
163
  * @param {bigint} tokenId The token ID of the asset.
164
164
  * @returns {Promise<any>} The result of the buyAccess call.
165
- */buyAccessSmart(e){return a(this,void 0,void 0,(function*(){if(!this.viemClient)throw new Error("WalletClient not connected.");const n=yield this.getTerms(e);if(!n)throw new Error("Failed to fetch terms for asset");const{price:i,paymentToken:r,duration:s}=n;if(void 0===i||void 0===r||void 0===s)throw new Error("Terms missing price, paymentToken, or duration");const[o]=yield this.viemClient.request({method:"eth_requestAccounts",params:[]}),d=i;return r===t.zeroAddress?this.buyAccess(o,e,d,s,r,d):(yield function(e){return a(this,arguments,void 0,(function*({walletClient:e,publicClient:n,tokenAddress:i,owner:a,spender:r,amount:s}){(yield n.readContract({address:i,abi:t.erc20Abi,functionName:"allowance",args:[a,r]}))<s&&(yield e.writeContract({address:i,account:a,abi:t.erc20Abi,functionName:"approve",args:[r,s],chain:l}))}))}({walletClient:this.viemClient,publicClient:h(),tokenAddress:r,owner:o,spender:this.environment.MARKETPLACE_CONTRACT_ADDRESS,amount:d}),this.buyAccess(o,e,d,s,r))}))}getData(e){return a(this,void 0,void 0,(function*(){const t=yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/data/${e}`,{method:"GET",headers:{Authorization:`Bearer ${this.jwt}`,"Content-Type":"application/json"}});if(!t.ok)throw new Error("Failed to fetch data");return t.json()}))}
165
+ */buyAccessSmart(e){return a(this,void 0,void 0,(function*(){if(!this.viemClient)throw new Error("WalletClient not connected.");const n=yield this.getTerms(e);if(!n)throw new Error("Failed to fetch terms for asset");const{price:i,paymentToken:r,duration:s}=n;if(void 0===i||void 0===r||void 0===s)throw new Error("Terms missing price, paymentToken, or duration");const o=(yield this.viemClient.request({method:"eth_requestAccounts",params:[]}))[0],d=i;return r===t.zeroAddress?this.buyAccess(o,e,d,s,r,d):(yield function(e){return a(this,arguments,void 0,(function*({walletClient:e,publicClient:n,tokenAddress:i,owner:a,spender:r,amount:s}){(yield n.readContract({address:i,abi:t.erc20Abi,functionName:"allowance",args:[a,r]}))<s&&(yield e.writeContract({address:i,account:a,abi:t.erc20Abi,functionName:"approve",args:[r,s],chain:l}))}))}({walletClient:this.viemClient,publicClient:h(),tokenAddress:r,owner:o,spender:this.environment.MARKETPLACE_CONTRACT_ADDRESS,amount:d}),this.buyAccess(o,e,d,s,r))}))}getData(e){return a(this,void 0,void 0,(function*(){const t=yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/data/${e}`,{method:"GET",headers:{Authorization:`Bearer ${this.jwt}`,"Content-Type":"application/json"}});if(!t.ok)throw new Error("Failed to fetch data");return t.json()}))}
166
166
  /**
167
167
  * Get royalty information for a wallet address, including the royalty vault address and its balance.
168
168
  * @param {Address} [owner] - Optional wallet address to check royalties for. If not provided, uses the connected wallet.
@@ -185,7 +185,7 @@ const i=[{inputs:[{name:"owner",type:"address"}],name:"balanceOf",outputs:[{name
185
185
  * @param {Address} [owner] - Optional wallet address to claim royalties for. If not provided, uses the connected wallet.
186
186
  * @returns {Promise<any>} A promise that resolves when the claim transaction is confirmed.
187
187
  * @throws {Error} Throws an error if no wallet is connected and no owner address is provided.
188
- */claimRoyalties(e,n){return a(this,void 0,void 0,(function*(){const i=yield r(this,L,"m",J).call(this,n),a=yield this.getOrCreateRoyaltyVault(i);return this.callContractMethod(a,this.environment.ROYALTY_VAULT_ABI,"claimRoyalties",[null!=e?e:t.zeroAddress],{waitForReceipt:!0})}))}}L=new WeakSet,q=function(e){return a(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/upload-url`,{method:"POST",body:JSON.stringify({name:e.name,type:e.type}),headers:{Authorization:`Bearer ${this.jwt}`,"Content-Type":"application/json"}});if(!t.ok)throw new Error(`HTTP ${t.status}: ${t.statusText}`);const n=yield t.json();if(n.isError)throw new Error(n.message||"Failed to generate upload URL");return n.data}catch(e){throw console.error("Failed to generate upload URL:",e),e}}))},W=function(e,t){return a(this,void 0,void 0,(function*(){try{const n=yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/update-status`,{method:"PATCH",body:JSON.stringify({status:t,fileKey:e}),headers:{Authorization:`Bearer ${this.jwt}`,"Content-Type":"application/json"}});if(!n.ok){const e=yield n.text().catch((()=>"Unknown error"));throw new Error(`HTTP ${n.status}: ${e}`)}return!0}catch(e){throw console.error("Failed to update origin status:",e),e}}))},z=function(e){return a(this,void 0,void 0,(function*(){if(!this.viemClient)throw new Error("WalletClient not connected.");for(;;){const t=yield this.viemClient.request({method:"eth_getTransactionReceipt",params:[e]});if(t&&t.blockNumber)return t;yield new Promise((e=>setTimeout(e,1e3)))}}))},K=function(e){return a(this,void 0,void 0,(function*(){
188
+ */claimRoyalties(e,n){return a(this,void 0,void 0,(function*(){const i=yield r(this,L,"m",J).call(this,n),a=yield this.getOrCreateRoyaltyVault(i);return this.callContractMethod(a,this.environment.ROYALTY_VAULT_ABI,"claimRoyalties",[null!=e?e:t.zeroAddress],{waitForReceipt:!0})}))}}L=new WeakSet,q=function(e){return a(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/upload-url`,{method:"POST",body:JSON.stringify({name:e.name,type:e.type}),headers:{Authorization:`Bearer ${this.jwt}`,"Content-Type":"application/json"}});if(!t.ok)throw new Error(`HTTP ${t.status}: ${t.statusText}`);const n=yield t.json();if(n.isError)throw new Error(n.message||"Failed to generate upload URL");return n.data}catch(e){throw console.error("Failed to generate upload URL:",e),e}}))},W=function(e,t){return a(this,void 0,void 0,(function*(){try{const n=yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/update-status`,{method:"PATCH",body:JSON.stringify({status:t,fileKey:e}),headers:{Authorization:`Bearer ${this.jwt}`,"Content-Type":"application/json"}});if(!n.ok){const e=yield n.text().catch((()=>"Unknown error"));throw new Error(`HTTP ${n.status}: ${e}`)}return!0}catch(e){throw console.error("Failed to update origin status:",e),e}}))},z=function(e){return a(this,void 0,void 0,(function*(){const t=h();for(;;){const n=yield t.getTransactionReceipt({hash:e});if(n&&n.blockNumber)return n;yield new Promise((e=>setTimeout(e,1e3)))}}))},K=function(e){return a(this,void 0,void 0,(function*(){
189
189
  // return;
190
190
  if(!this.viemClient)throw new Error("WalletClient not connected.");let t=yield this.viemClient.request({method:"eth_chainId",params:[]});if("string"==typeof t&&(t=parseInt(t,16)),t!==e.id)try{yield this.viemClient.request({method:"wallet_switchEthereumChain",params:[{chainId:"0x"+BigInt(e.id).toString(16)}]})}catch(t){
191
191
  // Unrecognized chain
package/dist/core.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Address, Hex, Abi } from 'viem';
1
+ import { Address, Hex, WalletClient, Abi } from 'viem';
2
2
 
3
3
  /**
4
4
  * The TwitterAPI class.
@@ -403,9 +403,9 @@ declare class Origin {
403
403
  private jwt;
404
404
  environment: Environment;
405
405
  private viemClient?;
406
- constructor(jwt: string, environment: Environment, viemClient?: any);
406
+ constructor(jwt: string, environment: Environment, viemClient?: WalletClient);
407
407
  getJwt(): string;
408
- setViemClient(client: any): void;
408
+ setViemClient(client: WalletClient): void;
409
409
  uploadFile(file: File, options?: {
410
410
  progressCallback?: (percent: number) => void;
411
411
  }): Promise<any>;
@@ -1,4 +1,4 @@
1
- import { Address, Hex, Abi } from 'viem';
1
+ import { Address, Hex, WalletClient, Abi } from 'viem';
2
2
 
3
3
  /**
4
4
  * The TwitterAPI class.
@@ -403,9 +403,9 @@ declare class Origin {
403
403
  private jwt;
404
404
  environment: Environment;
405
405
  private viemClient?;
406
- constructor(jwt: string, environment: Environment, viemClient?: any);
406
+ constructor(jwt: string, environment: Environment, viemClient?: WalletClient);
407
407
  getJwt(): string;
408
- setViemClient(client: any): void;
408
+ setViemClient(client: WalletClient): void;
409
409
  uploadFile(file: File, options?: {
410
410
  progressCallback?: (percent: number) => void;
411
411
  }): Promise<any>;
package/dist/core.esm.js CHANGED
@@ -236,7 +236,7 @@ let g=null,E=null;const _=()=>(E||(E=i({chain:b,transport:a()})),E);var C=[{inpu
236
236
  * Calls the getOrCreateRoyaltyVault method on the IPNFT contract.
237
237
  * @param tokenOwner The address of the token owner for whom to get or create the royalty vault.
238
238
  * @returns The address of the royalty vault associated with the specified token owner.
239
- */function $(e){return c(this,void 0,void 0,(function*(){const t=yield this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"getOrCreateRoyaltyVault",[e],{waitForReceipt:!0,simulate:!0});return console.log("Royalty Vault Tx:",t),t.simulatedResult}))}
239
+ */function $(e){return c(this,void 0,void 0,(function*(){const t=yield this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"getOrCreateRoyaltyVault",[e],{waitForReceipt:!0,simulate:!1});return console.log("Royalty Vault Tx:",t),t.simulatedResult}))}
240
240
  /**
241
241
  * Returns the license terms associated with a specific token ID.
242
242
  * @param tokenId The token ID to query.
@@ -297,8 +297,8 @@ let g=null,E=null;const _=()=>(E||(E=i({chain:b,transport:a()})),E);var C=[{inpu
297
297
  this.mintWithSignature=M.bind(this),this.registerIpNFT=B.bind(this),this.updateTerms=R.bind(this),this.finalizeDelete=F.bind(this),this.getOrCreateRoyaltyVault=$.bind(this),this.getTerms=H.bind(this),this.ownerOf=j.bind(this),this.balanceOf=L.bind(this),this.tokenURI=W.bind(this),this.dataStatus=q.bind(this),this.isApprovedForAll=z.bind(this),this.transferFrom=K.bind(this),this.safeTransferFrom=J.bind(this),this.approve=V.bind(this),this.setApprovalForAll=G.bind(this),
298
298
  // Marketplace methods
299
299
  this.buyAccess=Y.bind(this),this.hasAccess=X.bind(this),this.subscriptionExpiry=Z.bind(this)}getJwt(){return this.jwt}setViemClient(e){this.viemClient=e}uploadFile(t,n){return c(this,void 0,void 0,(function*(){let i;try{i=yield h(this,Q,"m",ee).call(this,t)}catch(e){throw console.error("Failed to generate upload URL:",e),new Error(`Failed to generate upload URL: ${e instanceof Error?e.message:String(e)}`)}if(!i)throw new Error("Failed to generate upload URL: No upload info returned");try{yield((t,n,i)=>new Promise(((a,r)=>{e.put(n,t,Object.assign({headers:{"Content-Type":t.type}},"undefined"!=typeof window&&"function"==typeof i?{onUploadProgress:e=>{if(e.total){const t=e.loaded/e.total*100;i(t)}}}:{})).then((e=>{a(e.data)})).catch((e=>{var t;const n=(null===(t=null==e?void 0:e.response)||void 0===t?void 0:t.data)||(null==e?void 0:e.message)||"Upload failed";r(n)}))})))(t,i.url,(null==n?void 0:n.progressCallback)||(()=>{}))}catch(e){try{yield h(this,Q,"m",te).call(this,i.key,"failed")}catch(e){console.error("Failed to update status to failed:",e)}const t=e instanceof Error?e.message:String(e);throw new Error(`Failed to upload file: ${t}`)}try{yield h(this,Q,"m",te).call(this,i.key,"success")}catch(e){console.error("Failed to update status to success:",e)}return i}))}mintFile(e,t,n,i,a){return c(this,void 0,void 0,(function*(){if(!this.viemClient)throw new Error("WalletClient not connected.");const r=yield this.uploadFile(e,a);if(!r||!r.key)throw new Error("Failed to upload file or get upload info.");const s=BigInt(Date.now()+6e5),o=yield this.registerIpNFT("file",s,n,t,r.key,i),{tokenId:d,signerAddress:u,creatorContentHash:p,signature:l,uri:y}=o;// 10 minutes from now
300
- if(!(d&&u&&p&&void 0!==l&&y))throw new Error("Failed to register IpNFT: Missing required fields in registration response.");const[c]=yield this.viemClient.request({method:"eth_requestAccounts",params:[]}),h=yield this.mintWithSignature(c,d,i||[],p,y,n,s,l);if("0x1"!==h.status)throw console.error("Minting failed:",h),new Error(`Minting failed with status: ${h.status}`);return d.toString()}))}mintSocial(e,t,n){return c(this,void 0,void 0,(function*(){if(!this.viemClient)throw new Error("WalletClient not connected.");const i=BigInt(Math.floor(Date.now()/1e3)+600),a=yield this.registerIpNFT(e,i,n,t),{tokenId:r,signerAddress:s,creatorContentHash:o,signature:d,uri:u}=a;// 10 minutes from now
301
- if(!(r&&s&&o&&void 0!==d&&u))throw new Error("Failed to register Social IpNFT: Missing required fields in registration response.");const[p]=yield this.viemClient.request({method:"eth_requestAccounts",params:[]}),l=yield this.mintWithSignature(p,r,[],o,u,n,i,d);if("0x1"!==l.status)throw new Error(`Minting Social IpNFT failed with status: ${l.status}`);return r.toString()}))}getOriginUploads(){return c(this,void 0,void 0,(function*(){const e=yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/files`,{method:"GET",headers:{Authorization:`Bearer ${this.jwt}`}});if(!e.ok)return console.error("Failed to get origin uploads"),null;return(yield e.json()).data}))}
300
+ if(!(d&&u&&p&&void 0!==l&&y))throw new Error("Failed to register IpNFT: Missing required fields in registration response.");const c=(yield this.viemClient.request({method:"eth_requestAccounts",params:[]}))[0],h=yield this.mintWithSignature(c,d,i||[],p,y,n,s,l);if("0x1"!==h.status)throw console.error("Minting failed:",h),new Error(`Minting failed with status: ${h.status}`);return d.toString()}))}mintSocial(e,t,n){return c(this,void 0,void 0,(function*(){if(!this.viemClient)throw new Error("WalletClient not connected.");const i=BigInt(Math.floor(Date.now()/1e3)+600),a=yield this.registerIpNFT(e,i,n,t),{tokenId:r,signerAddress:s,creatorContentHash:o,signature:d,uri:u}=a;// 10 minutes from now
301
+ if(!(r&&s&&o&&void 0!==d&&u))throw new Error("Failed to register Social IpNFT: Missing required fields in registration response.");const p=(yield this.viemClient.request({method:"eth_requestAccounts",params:[]}))[0],l=yield this.mintWithSignature(p,r,[],o,u,n,i,d);if("0x1"!==l.status)throw new Error(`Minting Social IpNFT failed with status: ${l.status}`);return r.toString()}))}getOriginUploads(){return c(this,void 0,void 0,(function*(){const e=yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/files`,{method:"GET",headers:{Authorization:`Bearer ${this.jwt}`}});if(!e.ok)return console.error("Failed to get origin uploads"),null;return(yield e.json()).data}))}
302
302
  /**
303
303
  * Get the user's Origin stats (multiplier, consent, usage, etc.).
304
304
  * @returns {Promise<OriginUsageReturnType>} A promise that resolves with the user's Origin stats.
@@ -318,14 +318,14 @@ if(!(r&&s&&o&&void 0!==d&&u))throw new Error("Failed to register Social IpNFT: M
318
318
  * @param {CallOptions} [options] The call options.
319
319
  * @returns {Promise<any>} A promise that resolves with the result of the contract call or transaction hash.
320
320
  * @throws {Error} - Throws an error if the wallet client is not connected and the method is not a view function.
321
- */callContractMethod(e,t,n,i){return c(this,arguments,void 0,(function*(e,t,n,i,a={}){const r=s({abi:t,name:n}),o=r&&"stateMutability"in r&&("view"===r.stateMutability||"pure"===r.stateMutability);if(!o&&!this.viemClient)throw new Error("WalletClient not connected.");if(o){const a=_();return(yield a.readContract({address:e,abi:t,functionName:n,args:i}))||null}{const[r]=yield this.viemClient.request({method:"eth_requestAccounts",params:[]});yield h(this,Q,"m",ie).call(this,this.environment.CHAIN);const s=_(),{result:o,request:d}=yield s.simulateContract({account:r,address:e,abi:t,functionName:n,args:i,value:a.value});
321
+ */callContractMethod(e,t,n,i){return c(this,arguments,void 0,(function*(e,t,n,i,a={}){const r=s({abi:t,name:n});if(r&&"stateMutability"in r&&("view"===r.stateMutability||"pure"===r.stateMutability)){const a=_();return(yield a.readContract({address:e,abi:t,functionName:n,args:i}))||null}if(!this.viemClient)throw new Error("WalletClient not connected.");const[o]=yield this.viemClient.request({method:"eth_requestAccounts",params:[]});yield h(this,Q,"m",ie).call(this,this.environment.CHAIN);const d=_(),{result:u,request:p}=yield d.simulateContract({account:o,address:e,abi:t,functionName:n,args:i,value:a.value});
322
322
  // simulate
323
- if(a.simulate)return o;try{const e=yield this.viemClient.sendTransaction(d);if("string"!=typeof e)throw new Error("Transaction failed to send.");if(!a.waitForReceipt)return{txHash:e,simulatedResult:o};return{txHash:e,receipt:yield h(this,Q,"m",ne).call(this,e),simulatedResult:o}}catch(e){throw console.error("Transaction failed:",e),new Error("Transaction failed: "+e)}}}))}
323
+ if(a.simulate)return u;try{const e=yield this.viemClient.writeContract(p);if("string"!=typeof e)throw new Error("Transaction failed to send.");if(!a.waitForReceipt)return{txHash:e,simulatedResult:u};return{txHash:e,receipt:yield h(this,Q,"m",ne).call(this,e),simulatedResult:u}}catch(e){throw console.error("Transaction failed:",e),new Error("Transaction failed: "+e)}}))}
324
324
  /**
325
325
  * Buy access to an asset by first checking its price via getTerms, then calling buyAccess.
326
326
  * @param {bigint} tokenId The token ID of the asset.
327
327
  * @returns {Promise<any>} The result of the buyAccess call.
328
- */buyAccessSmart(e){return c(this,void 0,void 0,(function*(){if(!this.viemClient)throw new Error("WalletClient not connected.");const t=yield this.getTerms(e);if(!t)throw new Error("Failed to fetch terms for asset");const{price:n,paymentToken:i,duration:a}=t;if(void 0===n||void 0===i||void 0===a)throw new Error("Terms missing price, paymentToken, or duration");const[s]=yield this.viemClient.request({method:"eth_requestAccounts",params:[]}),d=n;return i===o?this.buyAccess(s,e,d,a,i,d):(yield function(e){return c(this,arguments,void 0,(function*({walletClient:e,publicClient:t,tokenAddress:n,owner:i,spender:a,amount:s}){(yield t.readContract({address:n,abi:r,functionName:"allowance",args:[i,a]}))<s&&(yield e.writeContract({address:n,account:i,abi:r,functionName:"approve",args:[a,s],chain:b}))}))}({walletClient:this.viemClient,publicClient:_(),tokenAddress:i,owner:s,spender:this.environment.MARKETPLACE_CONTRACT_ADDRESS,amount:d}),this.buyAccess(s,e,d,a,i))}))}getData(e){return c(this,void 0,void 0,(function*(){const t=yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/data/${e}`,{method:"GET",headers:{Authorization:`Bearer ${this.jwt}`,"Content-Type":"application/json"}});if(!t.ok)throw new Error("Failed to fetch data");return t.json()}))}
328
+ */buyAccessSmart(e){return c(this,void 0,void 0,(function*(){if(!this.viemClient)throw new Error("WalletClient not connected.");const t=yield this.getTerms(e);if(!t)throw new Error("Failed to fetch terms for asset");const{price:n,paymentToken:i,duration:a}=t;if(void 0===n||void 0===i||void 0===a)throw new Error("Terms missing price, paymentToken, or duration");const s=(yield this.viemClient.request({method:"eth_requestAccounts",params:[]}))[0],d=n;return i===o?this.buyAccess(s,e,d,a,i,d):(yield function(e){return c(this,arguments,void 0,(function*({walletClient:e,publicClient:t,tokenAddress:n,owner:i,spender:a,amount:s}){(yield t.readContract({address:n,abi:r,functionName:"allowance",args:[i,a]}))<s&&(yield e.writeContract({address:n,account:i,abi:r,functionName:"approve",args:[a,s],chain:b}))}))}({walletClient:this.viemClient,publicClient:_(),tokenAddress:i,owner:s,spender:this.environment.MARKETPLACE_CONTRACT_ADDRESS,amount:d}),this.buyAccess(s,e,d,a,i))}))}getData(e){return c(this,void 0,void 0,(function*(){const t=yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/data/${e}`,{method:"GET",headers:{Authorization:`Bearer ${this.jwt}`,"Content-Type":"application/json"}});if(!t.ok)throw new Error("Failed to fetch data");return t.json()}))}
329
329
  /**
330
330
  * Get royalty information for a wallet address, including the royalty vault address and its balance.
331
331
  * @param {Address} [owner] - Optional wallet address to check royalties for. If not provided, uses the connected wallet.
@@ -348,7 +348,7 @@ const n=[{inputs:[{name:"owner",type:"address"}],name:"balanceOf",outputs:[{name
348
348
  * @param {Address} [owner] - Optional wallet address to claim royalties for. If not provided, uses the connected wallet.
349
349
  * @returns {Promise<any>} A promise that resolves when the claim transaction is confirmed.
350
350
  * @throws {Error} Throws an error if no wallet is connected and no owner address is provided.
351
- */claimRoyalties(e,t){return c(this,void 0,void 0,(function*(){const n=yield h(this,Q,"m",ae).call(this,t),i=yield this.getOrCreateRoyaltyVault(n);return this.callContractMethod(i,this.environment.ROYALTY_VAULT_ABI,"claimRoyalties",[null!=e?e:o],{waitForReceipt:!0})}))}}Q=new WeakSet,ee=function(e){return c(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/upload-url`,{method:"POST",body:JSON.stringify({name:e.name,type:e.type}),headers:{Authorization:`Bearer ${this.jwt}`,"Content-Type":"application/json"}});if(!t.ok)throw new Error(`HTTP ${t.status}: ${t.statusText}`);const n=yield t.json();if(n.isError)throw new Error(n.message||"Failed to generate upload URL");return n.data}catch(e){throw console.error("Failed to generate upload URL:",e),e}}))},te=function(e,t){return c(this,void 0,void 0,(function*(){try{const n=yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/update-status`,{method:"PATCH",body:JSON.stringify({status:t,fileKey:e}),headers:{Authorization:`Bearer ${this.jwt}`,"Content-Type":"application/json"}});if(!n.ok){const e=yield n.text().catch((()=>"Unknown error"));throw new Error(`HTTP ${n.status}: ${e}`)}return!0}catch(e){throw console.error("Failed to update origin status:",e),e}}))},ne=function(e){return c(this,void 0,void 0,(function*(){if(!this.viemClient)throw new Error("WalletClient not connected.");for(;;){const t=yield this.viemClient.request({method:"eth_getTransactionReceipt",params:[e]});if(t&&t.blockNumber)return t;yield new Promise((e=>setTimeout(e,1e3)))}}))},ie=function(e){return c(this,void 0,void 0,(function*(){
351
+ */claimRoyalties(e,t){return c(this,void 0,void 0,(function*(){const n=yield h(this,Q,"m",ae).call(this,t),i=yield this.getOrCreateRoyaltyVault(n);return this.callContractMethod(i,this.environment.ROYALTY_VAULT_ABI,"claimRoyalties",[null!=e?e:o],{waitForReceipt:!0})}))}}Q=new WeakSet,ee=function(e){return c(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/upload-url`,{method:"POST",body:JSON.stringify({name:e.name,type:e.type}),headers:{Authorization:`Bearer ${this.jwt}`,"Content-Type":"application/json"}});if(!t.ok)throw new Error(`HTTP ${t.status}: ${t.statusText}`);const n=yield t.json();if(n.isError)throw new Error(n.message||"Failed to generate upload URL");return n.data}catch(e){throw console.error("Failed to generate upload URL:",e),e}}))},te=function(e,t){return c(this,void 0,void 0,(function*(){try{const n=yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/update-status`,{method:"PATCH",body:JSON.stringify({status:t,fileKey:e}),headers:{Authorization:`Bearer ${this.jwt}`,"Content-Type":"application/json"}});if(!n.ok){const e=yield n.text().catch((()=>"Unknown error"));throw new Error(`HTTP ${n.status}: ${e}`)}return!0}catch(e){throw console.error("Failed to update origin status:",e),e}}))},ne=function(e){return c(this,void 0,void 0,(function*(){const t=_();for(;;){const n=yield t.getTransactionReceipt({hash:e});if(n&&n.blockNumber)return n;yield new Promise((e=>setTimeout(e,1e3)))}}))},ie=function(e){return c(this,void 0,void 0,(function*(){
352
352
  // return;
353
353
  if(!this.viemClient)throw new Error("WalletClient not connected.");let t=yield this.viemClient.request({method:"eth_chainId",params:[]});if("string"==typeof t&&(t=parseInt(t,16)),t!==e.id)try{yield this.viemClient.request({method:"wallet_switchEthereumChain",params:[{chainId:"0x"+BigInt(e.id).toString(16)}]})}catch(t){
354
354
  // Unrecognized chain
@@ -1,5 +1,5 @@
1
1
  import React, { JSX } from 'react';
2
- import { Address, Hex, Abi } from 'viem';
2
+ import { Address, Hex, WalletClient, Abi } from 'viem';
3
3
  import { UseQueryResult } from '@tanstack/react-query';
4
4
 
5
5
  interface Environment {
@@ -209,9 +209,9 @@ declare class Origin {
209
209
  private jwt;
210
210
  environment: Environment;
211
211
  private viemClient?;
212
- constructor(jwt: string, environment: Environment, viemClient?: any);
212
+ constructor(jwt: string, environment: Environment, viemClient?: WalletClient);
213
213
  getJwt(): string;
214
- setViemClient(client: any): void;
214
+ setViemClient(client: WalletClient): void;
215
215
  uploadFile(file: File, options?: {
216
216
  progressCallback?: (percent: number) => void;
217
217
  }): Promise<any>;
@@ -2730,7 +2730,7 @@ function finalizeDelete(tokenId) {
2730
2730
  */
2731
2731
  function getOrCreateRoyaltyVault(tokenOwner) {
2732
2732
  return __awaiter(this, void 0, void 0, function* () {
2733
- const royaltyVaultTx = yield this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "getOrCreateRoyaltyVault", [tokenOwner], { waitForReceipt: true, simulate: true });
2733
+ const royaltyVaultTx = yield this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "getOrCreateRoyaltyVault", [tokenOwner], { waitForReceipt: true, simulate: false });
2734
2734
  console.log("Royalty Vault Tx:", royaltyVaultTx);
2735
2735
  return royaltyVaultTx.simulatedResult;
2736
2736
  });
@@ -2964,10 +2964,11 @@ class Origin {
2964
2964
  !uri) {
2965
2965
  throw new Error("Failed to register IpNFT: Missing required fields in registration response.");
2966
2966
  }
2967
- const [account] = yield this.viemClient.request({
2967
+ const accounts = (yield this.viemClient.request({
2968
2968
  method: "eth_requestAccounts",
2969
2969
  params: [],
2970
- });
2970
+ }));
2971
+ const account = accounts[0];
2971
2972
  const mintResult = yield this.mintWithSignature(account, tokenId, parents || [], creatorContentHash, uri, license, deadline, signature);
2972
2973
  if (mintResult.status !== "0x1") {
2973
2974
  console.error("Minting failed:", mintResult);
@@ -2991,10 +2992,11 @@ class Origin {
2991
2992
  !uri) {
2992
2993
  throw new Error("Failed to register Social IpNFT: Missing required fields in registration response.");
2993
2994
  }
2994
- const [account] = yield this.viemClient.request({
2995
+ const accounts = (yield this.viemClient.request({
2995
2996
  method: "eth_requestAccounts",
2996
2997
  params: [],
2997
- });
2998
+ }));
2999
+ const account = accounts[0];
2998
3000
  const mintResult = yield this.mintWithSignature(account, tokenId, [], creatorContentHash, uri, license, deadline, signature);
2999
3001
  if (mintResult.status !== "0x1") {
3000
3002
  throw new Error(`Minting Social IpNFT failed with status: ${mintResult.status}`);
@@ -3085,9 +3087,6 @@ class Origin {
3085
3087
  "stateMutability" in abiItem &&
3086
3088
  (abiItem.stateMutability === "view" ||
3087
3089
  abiItem.stateMutability === "pure");
3088
- if (!isView && !this.viemClient) {
3089
- throw new Error("WalletClient not connected.");
3090
- }
3091
3090
  if (isView) {
3092
3091
  const publicClient = getPublicClient();
3093
3092
  const result = (yield publicClient.readContract({
@@ -3098,40 +3097,41 @@ class Origin {
3098
3097
  })) || null;
3099
3098
  return result;
3100
3099
  }
3101
- else {
3102
- const [account] = yield this.viemClient.request({
3103
- method: "eth_requestAccounts",
3104
- params: [],
3105
- });
3106
- yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_ensureChainId).call(this, this.environment.CHAIN);
3107
- const publicClient = getPublicClient();
3108
- // simulate
3109
- const { result: simulatedResult, request } = yield publicClient.simulateContract({
3110
- account,
3111
- address: contractAddress,
3112
- abi,
3113
- functionName: methodName,
3114
- args: params,
3115
- value: options.value,
3116
- });
3117
- if (options.simulate) {
3118
- return simulatedResult;
3119
- }
3120
- try {
3121
- const txHash = yield this.viemClient.sendTransaction(request);
3122
- if (typeof txHash !== "string") {
3123
- throw new Error("Transaction failed to send.");
3124
- }
3125
- if (!options.waitForReceipt) {
3126
- return { txHash, simulatedResult };
3127
- }
3128
- const receipt = yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_waitForTxReceipt).call(this, txHash);
3129
- return { txHash, receipt, simulatedResult };
3100
+ if (!this.viemClient) {
3101
+ throw new Error("WalletClient not connected.");
3102
+ }
3103
+ const [account] = (yield this.viemClient.request({
3104
+ method: "eth_requestAccounts",
3105
+ params: [],
3106
+ }));
3107
+ yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_ensureChainId).call(this, this.environment.CHAIN);
3108
+ const publicClient = getPublicClient();
3109
+ // simulate
3110
+ const { result: simulatedResult, request } = yield publicClient.simulateContract({
3111
+ account,
3112
+ address: contractAddress,
3113
+ abi,
3114
+ functionName: methodName,
3115
+ args: params,
3116
+ value: options.value,
3117
+ });
3118
+ if (options.simulate) {
3119
+ return simulatedResult;
3120
+ }
3121
+ try {
3122
+ const txHash = yield this.viemClient.writeContract(request);
3123
+ if (typeof txHash !== "string") {
3124
+ throw new Error("Transaction failed to send.");
3130
3125
  }
3131
- catch (error) {
3132
- console.error("Transaction failed:", error);
3133
- throw new Error("Transaction failed: " + error);
3126
+ if (!options.waitForReceipt) {
3127
+ return { txHash, simulatedResult };
3134
3128
  }
3129
+ const receipt = yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_waitForTxReceipt).call(this, txHash);
3130
+ return { txHash, receipt, simulatedResult };
3131
+ }
3132
+ catch (error) {
3133
+ console.error("Transaction failed:", error);
3134
+ throw new Error("Transaction failed: " + error);
3135
3135
  }
3136
3136
  });
3137
3137
  }
@@ -3154,10 +3154,11 @@ class Origin {
3154
3154
  duration === undefined) {
3155
3155
  throw new Error("Terms missing price, paymentToken, or duration");
3156
3156
  }
3157
- const [account] = yield this.viemClient.request({
3157
+ const accounts = (yield this.viemClient.request({
3158
3158
  method: "eth_requestAccounts",
3159
3159
  params: [],
3160
- });
3160
+ }));
3161
+ const account = accounts[0];
3161
3162
  const totalCost = price;
3162
3163
  const isNative = paymentToken === zeroAddress;
3163
3164
  if (isNative) {
@@ -3324,12 +3325,10 @@ _Origin_instances = new WeakSet(), _Origin_generateURL = function _Origin_genera
3324
3325
  });
3325
3326
  }, _Origin_waitForTxReceipt = function _Origin_waitForTxReceipt(txHash) {
3326
3327
  return __awaiter(this, void 0, void 0, function* () {
3327
- if (!this.viemClient)
3328
- throw new Error("WalletClient not connected.");
3328
+ const publicClient = getPublicClient();
3329
3329
  while (true) {
3330
- const receipt = yield this.viemClient.request({
3331
- method: "eth_getTransactionReceipt",
3332
- params: [txHash],
3330
+ const receipt = yield publicClient.getTransactionReceipt({
3331
+ hash: txHash,
3333
3332
  });
3334
3333
  if (receipt && receipt.blockNumber) {
3335
3334
  return receipt;
@@ -3342,10 +3341,10 @@ _Origin_instances = new WeakSet(), _Origin_generateURL = function _Origin_genera
3342
3341
  // return;
3343
3342
  if (!this.viemClient)
3344
3343
  throw new Error("WalletClient not connected.");
3345
- let currentChainId = yield this.viemClient.request({
3344
+ let currentChainId = (yield this.viemClient.request({
3346
3345
  method: "eth_chainId",
3347
3346
  params: [],
3348
- });
3347
+ }));
3349
3348
  if (typeof currentChainId === "string") {
3350
3349
  currentChainId = parseInt(currentChainId, 16);
3351
3350
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@campnetwork/origin",
3
- "version": "1.0.0-alpha.5",
3
+ "version": "1.0.0-alpha.7",
4
4
  "main": "dist/core.cjs",
5
5
  "exports": {
6
6
  ".": {