@campnetwork/origin 1.0.0-alpha.0 → 1.0.0-alpha.1
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 +2 -3
- package/dist/core.d.ts +2 -3
- package/dist/core.esm.d.ts +2 -3
- package/dist/core.esm.js +2 -3
- package/dist/react/index.esm.d.ts +2 -3
- package/dist/react/index.esm.js +12 -10
- package/package.json +1 -1
package/dist/core.cjs
CHANGED
|
@@ -57,7 +57,7 @@ let y=null,c=null;const h=()=>(c||(c=t.createPublicClient({chain:l,transport:t.h
|
|
|
57
57
|
* @param deadline The deadline for the registration operation.
|
|
58
58
|
* @param fileKey Optional file key for file uploads.
|
|
59
59
|
* @return A promise that resolves with the registration data.
|
|
60
|
-
*/function E(e,t,n,i,r,s){return a(this,void 0,void 0,(function*(){const a={source:e,deadline:Number(t),licenseTerms:{price:n.price.toString(),duration:n.duration,royaltyBps:n.royaltyBps,paymentToken:n.paymentToken},metadata:i,parentId:s||[]};void 0!==r&&(a.fileKey=r);const o=yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/register`,{method:"POST",headers:{Authorization:`Bearer ${this.getJwt()}`,"Content-Type":"application/json"},body:JSON.stringify(a)});if(!o.ok)throw new Error(`Failed to get signature: ${o.statusText}`);const d=yield o.json();if(d.isError)throw new Error(`Failed to get signature: ${d.message}`);return d.data}))}function _(e,t,n){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"updateTerms",[e,t,n],{waitForReceipt:!0})}function C(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"finalizeDelete",[e])}function S(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"getTerms",[e])}function k(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"ownerOf",[e])}function D(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"balanceOf",[e])}function N(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"contentHash",[e])}function P(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"tokenURI",[e])}function x(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"dataStatus",[e])}function M(e,t){return a(this,void 0,void 0,(function*(){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"royaltyInfo",[e,t])}))}function U(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"getApproved",[e])}function O(e,t){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"isApprovedForAll",[e,t])}function B(e,t,n){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"transferFrom",[e,t,n])}function F(e,t,n,i){const a=i?[e,t,n,i]:[e,t,n];return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"safeTransferFrom",a)}function R(e,t){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"approve",[e,t])}function $(e,t){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"setApprovalForAll",[e,t])}function H(e,t,n,i){return this.callContractMethod(this.environment.MARKETPLACE_CONTRACT_ADDRESS,this.environment.MARKETPLACE_ABI,"buyAccess",[e,t,n],{waitForReceipt:!0,value:
|
|
60
|
+
*/function E(e,t,n,i,r,s){return a(this,void 0,void 0,(function*(){const a={source:e,deadline:Number(t),licenseTerms:{price:n.price.toString(),duration:n.duration,royaltyBps:n.royaltyBps,paymentToken:n.paymentToken},metadata:i,parentId:s||[]};void 0!==r&&(a.fileKey=r);const o=yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/register`,{method:"POST",headers:{Authorization:`Bearer ${this.getJwt()}`,"Content-Type":"application/json"},body:JSON.stringify(a)});if(!o.ok)throw new Error(`Failed to get signature: ${o.statusText}`);const d=yield o.json();if(d.isError)throw new Error(`Failed to get signature: ${d.message}`);return d.data}))}function _(e,t,n){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"updateTerms",[e,t,n],{waitForReceipt:!0})}function C(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"finalizeDelete",[e])}function S(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"getTerms",[e])}function k(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"ownerOf",[e])}function D(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"balanceOf",[e])}function N(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"contentHash",[e])}function P(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"tokenURI",[e])}function x(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"dataStatus",[e])}function M(e,t){return a(this,void 0,void 0,(function*(){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"royaltyInfo",[e,t])}))}function U(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"getApproved",[e])}function O(e,t){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"isApprovedForAll",[e,t])}function B(e,t,n){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"transferFrom",[e,t,n])}function F(e,t,n,i){const a=i?[e,t,n,i]:[e,t,n];return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"safeTransferFrom",a)}function R(e,t){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"approve",[e,t])}function $(e,t){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"setApprovalForAll",[e,t])}function H(e,t,n,i,a,r){return this.callContractMethod(this.environment.MARKETPLACE_CONTRACT_ADDRESS,this.environment.MARKETPLACE_ABI,"buyAccess",[e,t,n,i,a],{waitForReceipt:!0,value:r})}function j(e,t,n,i){return this.callContractMethod(this.environment.MARKETPLACE_CONTRACT_ADDRESS,this.environment.MARKETPLACE_ABI,"renewAccess",[e,t,n],void 0!==i?{value:i}:void 0)}function L(e,t){return this.callContractMethod(this.environment.MARKETPLACE_CONTRACT_ADDRESS,this.environment.MARKETPLACE_ABI,"hasAccess",[e,t])}function W(e,t){return this.callContractMethod(this.environment.MARKETPLACE_CONTRACT_ADDRESS,this.environment.MARKETPLACE_ABI,"subscriptionExpiry",[e,t])}
|
|
61
61
|
/**
|
|
62
62
|
* Approves a spender to spend a specified amount of tokens on behalf of the owner.
|
|
63
63
|
* If the current allowance is less than the specified amount, it will perform the approval.
|
|
@@ -108,9 +108,8 @@ this.buyAccess=H.bind(this),this.renewAccess=j.bind(this),this.hasAccess=L.bind(
|
|
|
108
108
|
/**
|
|
109
109
|
* Buy access to an asset by first checking its price via getTerms, then calling buyAccess.
|
|
110
110
|
* @param {bigint} tokenId The token ID of the asset.
|
|
111
|
-
* @param {number} periods The number of periods to buy access for.
|
|
112
111
|
* @returns {Promise<any>} The result of the buyAccess call.
|
|
113
|
-
*/buyAccessSmart(e
|
|
112
|
+
*/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()}))}}K=new WeakMap,z=new WeakMap,q=new WeakSet,J=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)))}}))},V=function(e){return a(this,void 0,void 0,(function*(){
|
|
114
113
|
// return;
|
|
115
114
|
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){
|
|
116
115
|
// Unrecognized chain
|
package/dist/core.d.ts
CHANGED
|
@@ -290,7 +290,7 @@ declare function approve(this: Origin, to: Address, tokenId: bigint): Promise<an
|
|
|
290
290
|
|
|
291
291
|
declare function setApprovalForAll(this: Origin, operator: Address, approved: boolean): Promise<any>;
|
|
292
292
|
|
|
293
|
-
declare function buyAccess(this: Origin, buyer: Address, tokenId: bigint,
|
|
293
|
+
declare function buyAccess(this: Origin, buyer: Address, tokenId: bigint, expectedPrice: bigint, expectedDuration: bigint, expectedPaymentToken: Address, value?: bigint): Promise<any>;
|
|
294
294
|
|
|
295
295
|
declare function renewAccess(this: Origin, tokenId: bigint, buyer: Address, periods: number, value?: bigint): Promise<any>;
|
|
296
296
|
|
|
@@ -386,10 +386,9 @@ declare class Origin {
|
|
|
386
386
|
/**
|
|
387
387
|
* Buy access to an asset by first checking its price via getTerms, then calling buyAccess.
|
|
388
388
|
* @param {bigint} tokenId The token ID of the asset.
|
|
389
|
-
* @param {number} periods The number of periods to buy access for.
|
|
390
389
|
* @returns {Promise<any>} The result of the buyAccess call.
|
|
391
390
|
*/
|
|
392
|
-
buyAccessSmart(tokenId: bigint
|
|
391
|
+
buyAccessSmart(tokenId: bigint): Promise<any>;
|
|
393
392
|
getData(tokenId: bigint): Promise<any>;
|
|
394
393
|
}
|
|
395
394
|
|
package/dist/core.esm.d.ts
CHANGED
|
@@ -290,7 +290,7 @@ declare function approve(this: Origin, to: Address, tokenId: bigint): Promise<an
|
|
|
290
290
|
|
|
291
291
|
declare function setApprovalForAll(this: Origin, operator: Address, approved: boolean): Promise<any>;
|
|
292
292
|
|
|
293
|
-
declare function buyAccess(this: Origin, buyer: Address, tokenId: bigint,
|
|
293
|
+
declare function buyAccess(this: Origin, buyer: Address, tokenId: bigint, expectedPrice: bigint, expectedDuration: bigint, expectedPaymentToken: Address, value?: bigint): Promise<any>;
|
|
294
294
|
|
|
295
295
|
declare function renewAccess(this: Origin, tokenId: bigint, buyer: Address, periods: number, value?: bigint): Promise<any>;
|
|
296
296
|
|
|
@@ -386,10 +386,9 @@ declare class Origin {
|
|
|
386
386
|
/**
|
|
387
387
|
* Buy access to an asset by first checking its price via getTerms, then calling buyAccess.
|
|
388
388
|
* @param {bigint} tokenId The token ID of the asset.
|
|
389
|
-
* @param {number} periods The number of periods to buy access for.
|
|
390
389
|
* @returns {Promise<any>} The result of the buyAccess call.
|
|
391
390
|
*/
|
|
392
|
-
buyAccessSmart(tokenId: bigint
|
|
391
|
+
buyAccessSmart(tokenId: bigint): Promise<any>;
|
|
393
392
|
getData(tokenId: bigint): Promise<any>;
|
|
394
393
|
}
|
|
395
394
|
|
package/dist/core.esm.js
CHANGED
|
@@ -220,7 +220,7 @@ let g=null,b=null;const E=()=>(b||(b=i({chain:I,transport:a()})),b);var _=[{inpu
|
|
|
220
220
|
* @param deadline The deadline for the registration operation.
|
|
221
221
|
* @param fileKey Optional file key for file uploads.
|
|
222
222
|
* @return A promise that resolves with the registration data.
|
|
223
|
-
*/function M(e,t,n,i,a,r){return y(this,void 0,void 0,(function*(){const s={source:e,deadline:Number(t),licenseTerms:{price:n.price.toString(),duration:n.duration,royaltyBps:n.royaltyBps,paymentToken:n.paymentToken},metadata:i,parentId:r||[]};void 0!==a&&(s.fileKey=a);const o=yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/register`,{method:"POST",headers:{Authorization:`Bearer ${this.getJwt()}`,"Content-Type":"application/json"},body:JSON.stringify(s)});if(!o.ok)throw new Error(`Failed to get signature: ${o.statusText}`);const d=yield o.json();if(d.isError)throw new Error(`Failed to get signature: ${d.message}`);return d.data}))}function O(e,t,n){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"updateTerms",[e,t,n],{waitForReceipt:!0})}function B(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"finalizeDelete",[e])}function F(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"getTerms",[e])}function R(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"ownerOf",[e])}function $(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"balanceOf",[e])}function H(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"contentHash",[e])}function j(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"tokenURI",[e])}function L(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"dataStatus",[e])}function W(e,t){return y(this,void 0,void 0,(function*(){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"royaltyInfo",[e,t])}))}function q(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"getApproved",[e])}function K(e,t){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"isApprovedForAll",[e,t])}function z(e,t,n){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"transferFrom",[e,t,n])}function J(e,t,n,i){const a=i?[e,t,n,i]:[e,t,n];return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"safeTransferFrom",a)}function V(e,t){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"approve",[e,t])}function G(e,t){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"setApprovalForAll",[e,t])}function X(e,t,n,i){return this.callContractMethod(this.environment.MARKETPLACE_CONTRACT_ADDRESS,this.environment.MARKETPLACE_ABI,"buyAccess",[e,t,n],{waitForReceipt:!0,value:
|
|
223
|
+
*/function M(e,t,n,i,a,r){return y(this,void 0,void 0,(function*(){const s={source:e,deadline:Number(t),licenseTerms:{price:n.price.toString(),duration:n.duration,royaltyBps:n.royaltyBps,paymentToken:n.paymentToken},metadata:i,parentId:r||[]};void 0!==a&&(s.fileKey=a);const o=yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/register`,{method:"POST",headers:{Authorization:`Bearer ${this.getJwt()}`,"Content-Type":"application/json"},body:JSON.stringify(s)});if(!o.ok)throw new Error(`Failed to get signature: ${o.statusText}`);const d=yield o.json();if(d.isError)throw new Error(`Failed to get signature: ${d.message}`);return d.data}))}function O(e,t,n){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"updateTerms",[e,t,n],{waitForReceipt:!0})}function B(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"finalizeDelete",[e])}function F(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"getTerms",[e])}function R(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"ownerOf",[e])}function $(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"balanceOf",[e])}function H(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"contentHash",[e])}function j(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"tokenURI",[e])}function L(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"dataStatus",[e])}function W(e,t){return y(this,void 0,void 0,(function*(){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"royaltyInfo",[e,t])}))}function q(e){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"getApproved",[e])}function K(e,t){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"isApprovedForAll",[e,t])}function z(e,t,n){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"transferFrom",[e,t,n])}function J(e,t,n,i){const a=i?[e,t,n,i]:[e,t,n];return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"safeTransferFrom",a)}function V(e,t){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"approve",[e,t])}function G(e,t){return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS,this.environment.IPNFT_ABI,"setApprovalForAll",[e,t])}function X(e,t,n,i,a,r){return this.callContractMethod(this.environment.MARKETPLACE_CONTRACT_ADDRESS,this.environment.MARKETPLACE_ABI,"buyAccess",[e,t,n,i,a],{waitForReceipt:!0,value:r})}function Y(e,t,n,i){return this.callContractMethod(this.environment.MARKETPLACE_CONTRACT_ADDRESS,this.environment.MARKETPLACE_ABI,"renewAccess",[e,t,n],void 0!==i?{value:i}:void 0)}function Z(e,t){return this.callContractMethod(this.environment.MARKETPLACE_CONTRACT_ADDRESS,this.environment.MARKETPLACE_ABI,"hasAccess",[e,t])}function Q(e,t){return this.callContractMethod(this.environment.MARKETPLACE_CONTRACT_ADDRESS,this.environment.MARKETPLACE_ABI,"subscriptionExpiry",[e,t])}
|
|
224
224
|
/**
|
|
225
225
|
* Approves a spender to spend a specified amount of tokens on behalf of the owner.
|
|
226
226
|
* If the current allowance is less than the specified amount, it will perform the approval.
|
|
@@ -271,9 +271,8 @@ this.buyAccess=X.bind(this),this.renewAccess=Y.bind(this),this.hasAccess=Z.bind(
|
|
|
271
271
|
/**
|
|
272
272
|
* Buy access to an asset by first checking its price via getTerms, then calling buyAccess.
|
|
273
273
|
* @param {bigint} tokenId The token ID of the asset.
|
|
274
|
-
* @param {number} periods The number of periods to buy access for.
|
|
275
274
|
* @returns {Promise<any>} The result of the buyAccess call.
|
|
276
|
-
*/buyAccessSmart(e
|
|
275
|
+
*/buyAccessSmart(e){return y(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:[]}),o=n;return i===d?this.buyAccess(s,e,o,a,i,o):(yield function(e){return y(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:I}))}))}({walletClient:this.viemClient,publicClient:E(),tokenAddress:i,owner:s,spender:this.environment.MARKETPLACE_CONTRACT_ADDRESS,amount:o}),this.buyAccess(s,e,o,a,i))}))}getData(e){return y(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()}))}}te=new WeakMap,ne=new WeakMap,ee=new WeakSet,ie=function(e){return y(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)))}}))},ae=function(e){return y(this,void 0,void 0,(function*(){
|
|
277
276
|
// return;
|
|
278
277
|
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){
|
|
279
278
|
// Unrecognized chain
|
|
@@ -96,7 +96,7 @@ declare function approve(this: Origin, to: Address, tokenId: bigint): Promise<an
|
|
|
96
96
|
|
|
97
97
|
declare function setApprovalForAll(this: Origin, operator: Address, approved: boolean): Promise<any>;
|
|
98
98
|
|
|
99
|
-
declare function buyAccess(this: Origin, buyer: Address, tokenId: bigint,
|
|
99
|
+
declare function buyAccess(this: Origin, buyer: Address, tokenId: bigint, expectedPrice: bigint, expectedDuration: bigint, expectedPaymentToken: Address, value?: bigint): Promise<any>;
|
|
100
100
|
|
|
101
101
|
declare function renewAccess(this: Origin, tokenId: bigint, buyer: Address, periods: number, value?: bigint): Promise<any>;
|
|
102
102
|
|
|
@@ -192,10 +192,9 @@ declare class Origin {
|
|
|
192
192
|
/**
|
|
193
193
|
* Buy access to an asset by first checking its price via getTerms, then calling buyAccess.
|
|
194
194
|
* @param {bigint} tokenId The token ID of the asset.
|
|
195
|
-
* @param {number} periods The number of periods to buy access for.
|
|
196
195
|
* @returns {Promise<any>} The result of the buyAccess call.
|
|
197
196
|
*/
|
|
198
|
-
buyAccessSmart(tokenId: bigint
|
|
197
|
+
buyAccessSmart(tokenId: bigint): Promise<any>;
|
|
199
198
|
getData(tokenId: bigint): Promise<any>;
|
|
200
199
|
}
|
|
201
200
|
|
package/dist/react/index.esm.js
CHANGED
|
@@ -2655,9 +2655,9 @@ function setApprovalForAll(operator, approved) {
|
|
|
2655
2655
|
return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "setApprovalForAll", [operator, approved]);
|
|
2656
2656
|
}
|
|
2657
2657
|
|
|
2658
|
-
function buyAccess(buyer, tokenId,
|
|
2658
|
+
function buyAccess(buyer, tokenId, expectedPrice, expectedDuration, expectedPaymentToken, value // only for native token payments
|
|
2659
2659
|
) {
|
|
2660
|
-
return this.callContractMethod(this.environment.MARKETPLACE_CONTRACT_ADDRESS, this.environment.MARKETPLACE_ABI, "buyAccess", [buyer, tokenId,
|
|
2660
|
+
return this.callContractMethod(this.environment.MARKETPLACE_CONTRACT_ADDRESS, this.environment.MARKETPLACE_ABI, "buyAccess", [buyer, tokenId, expectedPrice, expectedDuration, expectedPaymentToken], { waitForReceipt: true, value });
|
|
2661
2661
|
}
|
|
2662
2662
|
|
|
2663
2663
|
function renewAccess(tokenId, buyer, periods, value) {
|
|
@@ -3049,10 +3049,9 @@ class Origin {
|
|
|
3049
3049
|
/**
|
|
3050
3050
|
* Buy access to an asset by first checking its price via getTerms, then calling buyAccess.
|
|
3051
3051
|
* @param {bigint} tokenId The token ID of the asset.
|
|
3052
|
-
* @param {number} periods The number of periods to buy access for.
|
|
3053
3052
|
* @returns {Promise<any>} The result of the buyAccess call.
|
|
3054
3053
|
*/
|
|
3055
|
-
buyAccessSmart(tokenId
|
|
3054
|
+
buyAccessSmart(tokenId) {
|
|
3056
3055
|
return __awaiter(this, void 0, void 0, function* () {
|
|
3057
3056
|
if (!this.viemClient) {
|
|
3058
3057
|
throw new Error("WalletClient not connected.");
|
|
@@ -3060,18 +3059,21 @@ class Origin {
|
|
|
3060
3059
|
const terms = yield this.getTerms(tokenId);
|
|
3061
3060
|
if (!terms)
|
|
3062
3061
|
throw new Error("Failed to fetch terms for asset");
|
|
3063
|
-
const { price, paymentToken } = terms;
|
|
3064
|
-
if (price === undefined ||
|
|
3065
|
-
|
|
3062
|
+
const { price, paymentToken, duration } = terms;
|
|
3063
|
+
if (price === undefined ||
|
|
3064
|
+
paymentToken === undefined ||
|
|
3065
|
+
duration === undefined) {
|
|
3066
|
+
throw new Error("Terms missing price, paymentToken, or duration");
|
|
3066
3067
|
}
|
|
3067
3068
|
const [account] = yield this.viemClient.request({
|
|
3068
3069
|
method: "eth_requestAccounts",
|
|
3069
3070
|
params: [],
|
|
3070
3071
|
});
|
|
3071
|
-
const totalCost = price
|
|
3072
|
+
const totalCost = price;
|
|
3072
3073
|
const isNative = paymentToken === zeroAddress;
|
|
3073
3074
|
if (isNative) {
|
|
3074
|
-
return this.buyAccess(account, tokenId, periods, totalCost);
|
|
3075
|
+
// return this.buyAccess(account, tokenId, periods, totalCost);
|
|
3076
|
+
return this.buyAccess(account, tokenId, totalCost, duration, paymentToken, totalCost);
|
|
3075
3077
|
}
|
|
3076
3078
|
yield approveIfNeeded({
|
|
3077
3079
|
walletClient: this.viemClient,
|
|
@@ -3081,7 +3083,7 @@ class Origin {
|
|
|
3081
3083
|
spender: this.environment.MARKETPLACE_CONTRACT_ADDRESS,
|
|
3082
3084
|
amount: totalCost,
|
|
3083
3085
|
});
|
|
3084
|
-
return this.buyAccess(account, tokenId,
|
|
3086
|
+
return this.buyAccess(account, tokenId, totalCost, duration, paymentToken);
|
|
3085
3087
|
});
|
|
3086
3088
|
}
|
|
3087
3089
|
getData(tokenId) {
|