@campnetwork/origin 1.3.0-alpha.9 → 1.3.0
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 +75 -10
- package/dist/core.cjs +248 -224
- package/dist/core.d.ts +114 -55
- package/dist/core.esm.d.ts +114 -55
- package/dist/core.esm.js +269 -245
- package/dist/react/index.esm.d.ts +103 -52
- package/dist/react/index.esm.js +1060 -794
- package/package.json +1 -1
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,
|
|
3
|
+
import { custom, createWalletClient, createPublicClient, http, zeroAddress, erc20Abi, getAbiItem, formatEther, formatUnits, encodeFunctionData, checksumAddress, parseEther } from 'viem';
|
|
4
4
|
import { toAccount } from 'viem/accounts';
|
|
5
5
|
import { createSiweMessage } from 'viem/siwe';
|
|
6
6
|
import axios from 'axios';
|
|
@@ -3330,7 +3330,7 @@ var tbaAbi = [
|
|
|
3330
3330
|
}
|
|
3331
3331
|
];
|
|
3332
3332
|
|
|
3333
|
-
var
|
|
3333
|
+
var batchOperationsAbi = [
|
|
3334
3334
|
{
|
|
3335
3335
|
inputs: [
|
|
3336
3336
|
{
|
|
@@ -3342,23 +3342,56 @@ var batchPurchaseAbi = [
|
|
|
3342
3342
|
internalType: "address",
|
|
3343
3343
|
name: "_ipNFT",
|
|
3344
3344
|
type: "address"
|
|
3345
|
+
},
|
|
3346
|
+
{
|
|
3347
|
+
internalType: "address",
|
|
3348
|
+
name: "_appRegistry",
|
|
3349
|
+
type: "address"
|
|
3345
3350
|
}
|
|
3346
3351
|
],
|
|
3347
3352
|
stateMutability: "nonpayable",
|
|
3348
3353
|
type: "constructor"
|
|
3349
3354
|
},
|
|
3355
|
+
{
|
|
3356
|
+
inputs: [
|
|
3357
|
+
],
|
|
3358
|
+
name: "EmptyMintList",
|
|
3359
|
+
type: "error"
|
|
3360
|
+
},
|
|
3350
3361
|
{
|
|
3351
3362
|
inputs: [
|
|
3352
3363
|
],
|
|
3353
3364
|
name: "EmptyPurchaseList",
|
|
3354
3365
|
type: "error"
|
|
3355
3366
|
},
|
|
3367
|
+
{
|
|
3368
|
+
inputs: [
|
|
3369
|
+
],
|
|
3370
|
+
name: "InsufficientAllowance",
|
|
3371
|
+
type: "error"
|
|
3372
|
+
},
|
|
3356
3373
|
{
|
|
3357
3374
|
inputs: [
|
|
3358
3375
|
],
|
|
3359
3376
|
name: "InvalidTotalPayment",
|
|
3360
3377
|
type: "error"
|
|
3361
3378
|
},
|
|
3379
|
+
{
|
|
3380
|
+
inputs: [
|
|
3381
|
+
{
|
|
3382
|
+
internalType: "uint256",
|
|
3383
|
+
name: "tokenId",
|
|
3384
|
+
type: "uint256"
|
|
3385
|
+
},
|
|
3386
|
+
{
|
|
3387
|
+
internalType: "string",
|
|
3388
|
+
name: "reason",
|
|
3389
|
+
type: "string"
|
|
3390
|
+
}
|
|
3391
|
+
],
|
|
3392
|
+
name: "MintFailed",
|
|
3393
|
+
type: "error"
|
|
3394
|
+
},
|
|
3362
3395
|
{
|
|
3363
3396
|
inputs: [
|
|
3364
3397
|
{
|
|
@@ -3375,6 +3408,12 @@ var batchPurchaseAbi = [
|
|
|
3375
3408
|
name: "PurchaseFailed",
|
|
3376
3409
|
type: "error"
|
|
3377
3410
|
},
|
|
3411
|
+
{
|
|
3412
|
+
inputs: [
|
|
3413
|
+
],
|
|
3414
|
+
name: "ReentrancyGuardReentrantCall",
|
|
3415
|
+
type: "error"
|
|
3416
|
+
},
|
|
3378
3417
|
{
|
|
3379
3418
|
inputs: [
|
|
3380
3419
|
],
|
|
@@ -3387,6 +3426,56 @@ var batchPurchaseAbi = [
|
|
|
3387
3426
|
name: "ZeroAddress",
|
|
3388
3427
|
type: "error"
|
|
3389
3428
|
},
|
|
3429
|
+
{
|
|
3430
|
+
anonymous: false,
|
|
3431
|
+
inputs: [
|
|
3432
|
+
{
|
|
3433
|
+
indexed: true,
|
|
3434
|
+
internalType: "address",
|
|
3435
|
+
name: "minter",
|
|
3436
|
+
type: "address"
|
|
3437
|
+
},
|
|
3438
|
+
{
|
|
3439
|
+
indexed: false,
|
|
3440
|
+
internalType: "uint256",
|
|
3441
|
+
name: "count",
|
|
3442
|
+
type: "uint256"
|
|
3443
|
+
}
|
|
3444
|
+
],
|
|
3445
|
+
name: "BulkMintExecuted",
|
|
3446
|
+
type: "event"
|
|
3447
|
+
},
|
|
3448
|
+
{
|
|
3449
|
+
anonymous: false,
|
|
3450
|
+
inputs: [
|
|
3451
|
+
{
|
|
3452
|
+
indexed: true,
|
|
3453
|
+
internalType: "address",
|
|
3454
|
+
name: "minter",
|
|
3455
|
+
type: "address"
|
|
3456
|
+
},
|
|
3457
|
+
{
|
|
3458
|
+
indexed: false,
|
|
3459
|
+
internalType: "uint256",
|
|
3460
|
+
name: "successCount",
|
|
3461
|
+
type: "uint256"
|
|
3462
|
+
},
|
|
3463
|
+
{
|
|
3464
|
+
indexed: false,
|
|
3465
|
+
internalType: "uint256",
|
|
3466
|
+
name: "failureCount",
|
|
3467
|
+
type: "uint256"
|
|
3468
|
+
},
|
|
3469
|
+
{
|
|
3470
|
+
indexed: false,
|
|
3471
|
+
internalType: "uint256[]",
|
|
3472
|
+
name: "failedTokenIds",
|
|
3473
|
+
type: "uint256[]"
|
|
3474
|
+
}
|
|
3475
|
+
],
|
|
3476
|
+
name: "BulkMintPartial",
|
|
3477
|
+
type: "event"
|
|
3478
|
+
},
|
|
3390
3479
|
{
|
|
3391
3480
|
anonymous: false,
|
|
3392
3481
|
inputs: [
|
|
@@ -3443,6 +3532,71 @@ var batchPurchaseAbi = [
|
|
|
3443
3532
|
name: "BulkPurchasePartial",
|
|
3444
3533
|
type: "event"
|
|
3445
3534
|
},
|
|
3535
|
+
{
|
|
3536
|
+
inputs: [
|
|
3537
|
+
],
|
|
3538
|
+
name: "appRegistry",
|
|
3539
|
+
outputs: [
|
|
3540
|
+
{
|
|
3541
|
+
internalType: "contract IAppRegistry",
|
|
3542
|
+
name: "",
|
|
3543
|
+
type: "address"
|
|
3544
|
+
}
|
|
3545
|
+
],
|
|
3546
|
+
stateMutability: "view",
|
|
3547
|
+
type: "function"
|
|
3548
|
+
},
|
|
3549
|
+
{
|
|
3550
|
+
inputs: [
|
|
3551
|
+
{
|
|
3552
|
+
internalType: "uint256[]",
|
|
3553
|
+
name: "tokenIds",
|
|
3554
|
+
type: "uint256[]"
|
|
3555
|
+
}
|
|
3556
|
+
],
|
|
3557
|
+
name: "buildPurchaseParams",
|
|
3558
|
+
outputs: [
|
|
3559
|
+
{
|
|
3560
|
+
components: [
|
|
3561
|
+
{
|
|
3562
|
+
internalType: "uint256",
|
|
3563
|
+
name: "tokenId",
|
|
3564
|
+
type: "uint256"
|
|
3565
|
+
},
|
|
3566
|
+
{
|
|
3567
|
+
internalType: "uint256",
|
|
3568
|
+
name: "expectedPrice",
|
|
3569
|
+
type: "uint256"
|
|
3570
|
+
},
|
|
3571
|
+
{
|
|
3572
|
+
internalType: "uint32",
|
|
3573
|
+
name: "expectedDuration",
|
|
3574
|
+
type: "uint32"
|
|
3575
|
+
},
|
|
3576
|
+
{
|
|
3577
|
+
internalType: "address",
|
|
3578
|
+
name: "expectedPaymentToken",
|
|
3579
|
+
type: "address"
|
|
3580
|
+
},
|
|
3581
|
+
{
|
|
3582
|
+
internalType: "uint16",
|
|
3583
|
+
name: "expectedProtocolFeeBps",
|
|
3584
|
+
type: "uint16"
|
|
3585
|
+
},
|
|
3586
|
+
{
|
|
3587
|
+
internalType: "uint16",
|
|
3588
|
+
name: "expectedAppFeeBps",
|
|
3589
|
+
type: "uint16"
|
|
3590
|
+
}
|
|
3591
|
+
],
|
|
3592
|
+
internalType: "struct IBatchOperations.BuyParams[]",
|
|
3593
|
+
name: "purchases",
|
|
3594
|
+
type: "tuple[]"
|
|
3595
|
+
}
|
|
3596
|
+
],
|
|
3597
|
+
stateMutability: "view",
|
|
3598
|
+
type: "function"
|
|
3599
|
+
},
|
|
3446
3600
|
{
|
|
3447
3601
|
inputs: [
|
|
3448
3602
|
{
|
|
@@ -3471,9 +3625,19 @@ var batchPurchaseAbi = [
|
|
|
3471
3625
|
internalType: "address",
|
|
3472
3626
|
name: "expectedPaymentToken",
|
|
3473
3627
|
type: "address"
|
|
3628
|
+
},
|
|
3629
|
+
{
|
|
3630
|
+
internalType: "uint16",
|
|
3631
|
+
name: "expectedProtocolFeeBps",
|
|
3632
|
+
type: "uint16"
|
|
3633
|
+
},
|
|
3634
|
+
{
|
|
3635
|
+
internalType: "uint16",
|
|
3636
|
+
name: "expectedAppFeeBps",
|
|
3637
|
+
type: "uint16"
|
|
3474
3638
|
}
|
|
3475
3639
|
],
|
|
3476
|
-
internalType: "struct
|
|
3640
|
+
internalType: "struct IBatchOperations.BuyParams[]",
|
|
3477
3641
|
name: "purchases",
|
|
3478
3642
|
type: "tuple[]"
|
|
3479
3643
|
}
|
|
@@ -3517,9 +3681,19 @@ var batchPurchaseAbi = [
|
|
|
3517
3681
|
internalType: "address",
|
|
3518
3682
|
name: "expectedPaymentToken",
|
|
3519
3683
|
type: "address"
|
|
3684
|
+
},
|
|
3685
|
+
{
|
|
3686
|
+
internalType: "uint16",
|
|
3687
|
+
name: "expectedProtocolFeeBps",
|
|
3688
|
+
type: "uint16"
|
|
3689
|
+
},
|
|
3690
|
+
{
|
|
3691
|
+
internalType: "uint16",
|
|
3692
|
+
name: "expectedAppFeeBps",
|
|
3693
|
+
type: "uint16"
|
|
3520
3694
|
}
|
|
3521
3695
|
],
|
|
3522
|
-
internalType: "struct
|
|
3696
|
+
internalType: "struct IBatchOperations.BuyParams[]",
|
|
3523
3697
|
name: "purchases",
|
|
3524
3698
|
type: "tuple[]"
|
|
3525
3699
|
}
|
|
@@ -3554,7 +3728,7 @@ var batchPurchaseAbi = [
|
|
|
3554
3728
|
type: "uint256[]"
|
|
3555
3729
|
}
|
|
3556
3730
|
],
|
|
3557
|
-
internalType: "struct
|
|
3731
|
+
internalType: "struct IBatchOperations.TolerantResult",
|
|
3558
3732
|
name: "result",
|
|
3559
3733
|
type: "tuple"
|
|
3560
3734
|
}
|
|
@@ -3564,108 +3738,275 @@ var batchPurchaseAbi = [
|
|
|
3564
3738
|
},
|
|
3565
3739
|
{
|
|
3566
3740
|
inputs: [
|
|
3567
|
-
{
|
|
3568
|
-
internalType: "uint256[]",
|
|
3569
|
-
name: "tokenIds",
|
|
3570
|
-
type: "uint256[]"
|
|
3571
|
-
}
|
|
3572
|
-
],
|
|
3573
|
-
name: "buildPurchaseParams",
|
|
3574
|
-
outputs: [
|
|
3575
3741
|
{
|
|
3576
3742
|
components: [
|
|
3743
|
+
{
|
|
3744
|
+
internalType: "address",
|
|
3745
|
+
name: "to",
|
|
3746
|
+
type: "address"
|
|
3747
|
+
},
|
|
3577
3748
|
{
|
|
3578
3749
|
internalType: "uint256",
|
|
3579
3750
|
name: "tokenId",
|
|
3580
3751
|
type: "uint256"
|
|
3581
3752
|
},
|
|
3753
|
+
{
|
|
3754
|
+
internalType: "bytes32",
|
|
3755
|
+
name: "creatorContentHash",
|
|
3756
|
+
type: "bytes32"
|
|
3757
|
+
},
|
|
3758
|
+
{
|
|
3759
|
+
internalType: "string",
|
|
3760
|
+
name: "uri",
|
|
3761
|
+
type: "string"
|
|
3762
|
+
},
|
|
3763
|
+
{
|
|
3764
|
+
components: [
|
|
3765
|
+
{
|
|
3766
|
+
internalType: "uint128",
|
|
3767
|
+
name: "price",
|
|
3768
|
+
type: "uint128"
|
|
3769
|
+
},
|
|
3770
|
+
{
|
|
3771
|
+
internalType: "uint32",
|
|
3772
|
+
name: "duration",
|
|
3773
|
+
type: "uint32"
|
|
3774
|
+
},
|
|
3775
|
+
{
|
|
3776
|
+
internalType: "uint16",
|
|
3777
|
+
name: "royaltyBps",
|
|
3778
|
+
type: "uint16"
|
|
3779
|
+
},
|
|
3780
|
+
{
|
|
3781
|
+
internalType: "address",
|
|
3782
|
+
name: "paymentToken",
|
|
3783
|
+
type: "address"
|
|
3784
|
+
},
|
|
3785
|
+
{
|
|
3786
|
+
internalType: "uint8",
|
|
3787
|
+
name: "licenseType",
|
|
3788
|
+
type: "uint8"
|
|
3789
|
+
}
|
|
3790
|
+
],
|
|
3791
|
+
internalType: "struct IBatchOperations.LicenseTermsParam",
|
|
3792
|
+
name: "licenseTerms",
|
|
3793
|
+
type: "tuple"
|
|
3794
|
+
},
|
|
3582
3795
|
{
|
|
3583
3796
|
internalType: "uint256",
|
|
3584
|
-
name: "
|
|
3797
|
+
name: "deadline",
|
|
3585
3798
|
type: "uint256"
|
|
3586
3799
|
},
|
|
3587
3800
|
{
|
|
3588
|
-
internalType: "
|
|
3589
|
-
name: "
|
|
3590
|
-
type: "
|
|
3801
|
+
internalType: "uint256[]",
|
|
3802
|
+
name: "parents",
|
|
3803
|
+
type: "uint256[]"
|
|
3591
3804
|
},
|
|
3592
3805
|
{
|
|
3593
|
-
internalType: "
|
|
3594
|
-
name: "
|
|
3595
|
-
type: "
|
|
3806
|
+
internalType: "bool",
|
|
3807
|
+
name: "isIP",
|
|
3808
|
+
type: "bool"
|
|
3809
|
+
},
|
|
3810
|
+
{
|
|
3811
|
+
internalType: "string",
|
|
3812
|
+
name: "appId",
|
|
3813
|
+
type: "string"
|
|
3814
|
+
},
|
|
3815
|
+
{
|
|
3816
|
+
internalType: "bytes",
|
|
3817
|
+
name: "signature",
|
|
3818
|
+
type: "bytes"
|
|
3596
3819
|
}
|
|
3597
3820
|
],
|
|
3598
|
-
internalType: "struct
|
|
3599
|
-
name: "
|
|
3821
|
+
internalType: "struct IBatchOperations.MintParams[]",
|
|
3822
|
+
name: "mints",
|
|
3600
3823
|
type: "tuple[]"
|
|
3601
3824
|
}
|
|
3602
3825
|
],
|
|
3603
|
-
|
|
3604
|
-
type: "function"
|
|
3605
|
-
},
|
|
3606
|
-
{
|
|
3607
|
-
inputs: [
|
|
3608
|
-
{
|
|
3609
|
-
internalType: "uint256[]",
|
|
3610
|
-
name: "tokenIds",
|
|
3611
|
-
type: "uint256[]"
|
|
3612
|
-
}
|
|
3613
|
-
],
|
|
3614
|
-
name: "checkActiveStatus",
|
|
3615
|
-
outputs: [
|
|
3616
|
-
{
|
|
3617
|
-
internalType: "bool[]",
|
|
3618
|
-
name: "activeFlags",
|
|
3619
|
-
type: "bool[]"
|
|
3620
|
-
}
|
|
3621
|
-
],
|
|
3622
|
-
stateMutability: "view",
|
|
3623
|
-
type: "function"
|
|
3624
|
-
},
|
|
3625
|
-
{
|
|
3626
|
-
inputs: [
|
|
3627
|
-
],
|
|
3628
|
-
name: "ipNFT",
|
|
3629
|
-
outputs: [
|
|
3630
|
-
{
|
|
3631
|
-
internalType: "contract IIpNFT",
|
|
3632
|
-
name: "",
|
|
3633
|
-
type: "address"
|
|
3634
|
-
}
|
|
3635
|
-
],
|
|
3636
|
-
stateMutability: "view",
|
|
3637
|
-
type: "function"
|
|
3638
|
-
},
|
|
3639
|
-
{
|
|
3640
|
-
inputs: [
|
|
3641
|
-
],
|
|
3642
|
-
name: "marketplace",
|
|
3826
|
+
name: "bulkMint",
|
|
3643
3827
|
outputs: [
|
|
3644
|
-
{
|
|
3645
|
-
internalType: "contract IMarketplace",
|
|
3646
|
-
name: "",
|
|
3647
|
-
type: "address"
|
|
3648
|
-
}
|
|
3649
3828
|
],
|
|
3650
|
-
stateMutability: "
|
|
3829
|
+
stateMutability: "nonpayable",
|
|
3651
3830
|
type: "function"
|
|
3652
3831
|
},
|
|
3653
3832
|
{
|
|
3654
3833
|
inputs: [
|
|
3655
|
-
{
|
|
3656
|
-
internalType: "uint256[]",
|
|
3657
|
-
name: "tokenIds",
|
|
3658
|
-
type: "uint256[]"
|
|
3659
|
-
}
|
|
3660
|
-
],
|
|
3661
|
-
name: "previewBulkCost",
|
|
3662
|
-
outputs: [
|
|
3663
3834
|
{
|
|
3664
3835
|
components: [
|
|
3665
3836
|
{
|
|
3666
|
-
internalType: "
|
|
3667
|
-
name: "
|
|
3668
|
-
type: "
|
|
3837
|
+
internalType: "address",
|
|
3838
|
+
name: "to",
|
|
3839
|
+
type: "address"
|
|
3840
|
+
},
|
|
3841
|
+
{
|
|
3842
|
+
internalType: "uint256",
|
|
3843
|
+
name: "tokenId",
|
|
3844
|
+
type: "uint256"
|
|
3845
|
+
},
|
|
3846
|
+
{
|
|
3847
|
+
internalType: "bytes32",
|
|
3848
|
+
name: "creatorContentHash",
|
|
3849
|
+
type: "bytes32"
|
|
3850
|
+
},
|
|
3851
|
+
{
|
|
3852
|
+
internalType: "string",
|
|
3853
|
+
name: "uri",
|
|
3854
|
+
type: "string"
|
|
3855
|
+
},
|
|
3856
|
+
{
|
|
3857
|
+
components: [
|
|
3858
|
+
{
|
|
3859
|
+
internalType: "uint128",
|
|
3860
|
+
name: "price",
|
|
3861
|
+
type: "uint128"
|
|
3862
|
+
},
|
|
3863
|
+
{
|
|
3864
|
+
internalType: "uint32",
|
|
3865
|
+
name: "duration",
|
|
3866
|
+
type: "uint32"
|
|
3867
|
+
},
|
|
3868
|
+
{
|
|
3869
|
+
internalType: "uint16",
|
|
3870
|
+
name: "royaltyBps",
|
|
3871
|
+
type: "uint16"
|
|
3872
|
+
},
|
|
3873
|
+
{
|
|
3874
|
+
internalType: "address",
|
|
3875
|
+
name: "paymentToken",
|
|
3876
|
+
type: "address"
|
|
3877
|
+
},
|
|
3878
|
+
{
|
|
3879
|
+
internalType: "uint8",
|
|
3880
|
+
name: "licenseType",
|
|
3881
|
+
type: "uint8"
|
|
3882
|
+
}
|
|
3883
|
+
],
|
|
3884
|
+
internalType: "struct IBatchOperations.LicenseTermsParam",
|
|
3885
|
+
name: "licenseTerms",
|
|
3886
|
+
type: "tuple"
|
|
3887
|
+
},
|
|
3888
|
+
{
|
|
3889
|
+
internalType: "uint256",
|
|
3890
|
+
name: "deadline",
|
|
3891
|
+
type: "uint256"
|
|
3892
|
+
},
|
|
3893
|
+
{
|
|
3894
|
+
internalType: "uint256[]",
|
|
3895
|
+
name: "parents",
|
|
3896
|
+
type: "uint256[]"
|
|
3897
|
+
},
|
|
3898
|
+
{
|
|
3899
|
+
internalType: "bool",
|
|
3900
|
+
name: "isIP",
|
|
3901
|
+
type: "bool"
|
|
3902
|
+
},
|
|
3903
|
+
{
|
|
3904
|
+
internalType: "string",
|
|
3905
|
+
name: "appId",
|
|
3906
|
+
type: "string"
|
|
3907
|
+
},
|
|
3908
|
+
{
|
|
3909
|
+
internalType: "bytes",
|
|
3910
|
+
name: "signature",
|
|
3911
|
+
type: "bytes"
|
|
3912
|
+
}
|
|
3913
|
+
],
|
|
3914
|
+
internalType: "struct IBatchOperations.MintParams[]",
|
|
3915
|
+
name: "mints",
|
|
3916
|
+
type: "tuple[]"
|
|
3917
|
+
}
|
|
3918
|
+
],
|
|
3919
|
+
name: "bulkMintTolerant",
|
|
3920
|
+
outputs: [
|
|
3921
|
+
{
|
|
3922
|
+
components: [
|
|
3923
|
+
{
|
|
3924
|
+
internalType: "uint256",
|
|
3925
|
+
name: "successCount",
|
|
3926
|
+
type: "uint256"
|
|
3927
|
+
},
|
|
3928
|
+
{
|
|
3929
|
+
internalType: "uint256",
|
|
3930
|
+
name: "failureCount",
|
|
3931
|
+
type: "uint256"
|
|
3932
|
+
},
|
|
3933
|
+
{
|
|
3934
|
+
internalType: "uint256[]",
|
|
3935
|
+
name: "failedTokenIds",
|
|
3936
|
+
type: "uint256[]"
|
|
3937
|
+
}
|
|
3938
|
+
],
|
|
3939
|
+
internalType: "struct IBatchOperations.TolerantMintResult",
|
|
3940
|
+
name: "result",
|
|
3941
|
+
type: "tuple"
|
|
3942
|
+
}
|
|
3943
|
+
],
|
|
3944
|
+
stateMutability: "nonpayable",
|
|
3945
|
+
type: "function"
|
|
3946
|
+
},
|
|
3947
|
+
{
|
|
3948
|
+
inputs: [
|
|
3949
|
+
{
|
|
3950
|
+
internalType: "uint256[]",
|
|
3951
|
+
name: "tokenIds",
|
|
3952
|
+
type: "uint256[]"
|
|
3953
|
+
}
|
|
3954
|
+
],
|
|
3955
|
+
name: "checkActiveStatus",
|
|
3956
|
+
outputs: [
|
|
3957
|
+
{
|
|
3958
|
+
internalType: "bool[]",
|
|
3959
|
+
name: "activeFlags",
|
|
3960
|
+
type: "bool[]"
|
|
3961
|
+
}
|
|
3962
|
+
],
|
|
3963
|
+
stateMutability: "view",
|
|
3964
|
+
type: "function"
|
|
3965
|
+
},
|
|
3966
|
+
{
|
|
3967
|
+
inputs: [
|
|
3968
|
+
],
|
|
3969
|
+
name: "ipNFT",
|
|
3970
|
+
outputs: [
|
|
3971
|
+
{
|
|
3972
|
+
internalType: "contract IIpNFT",
|
|
3973
|
+
name: "",
|
|
3974
|
+
type: "address"
|
|
3975
|
+
}
|
|
3976
|
+
],
|
|
3977
|
+
stateMutability: "view",
|
|
3978
|
+
type: "function"
|
|
3979
|
+
},
|
|
3980
|
+
{
|
|
3981
|
+
inputs: [
|
|
3982
|
+
],
|
|
3983
|
+
name: "marketplace",
|
|
3984
|
+
outputs: [
|
|
3985
|
+
{
|
|
3986
|
+
internalType: "contract IMarketplace",
|
|
3987
|
+
name: "",
|
|
3988
|
+
type: "address"
|
|
3989
|
+
}
|
|
3990
|
+
],
|
|
3991
|
+
stateMutability: "view",
|
|
3992
|
+
type: "function"
|
|
3993
|
+
},
|
|
3994
|
+
{
|
|
3995
|
+
inputs: [
|
|
3996
|
+
{
|
|
3997
|
+
internalType: "uint256[]",
|
|
3998
|
+
name: "tokenIds",
|
|
3999
|
+
type: "uint256[]"
|
|
4000
|
+
}
|
|
4001
|
+
],
|
|
4002
|
+
name: "previewBulkCost",
|
|
4003
|
+
outputs: [
|
|
4004
|
+
{
|
|
4005
|
+
components: [
|
|
4006
|
+
{
|
|
4007
|
+
internalType: "uint256",
|
|
4008
|
+
name: "totalNativeCost",
|
|
4009
|
+
type: "uint256"
|
|
3669
4010
|
},
|
|
3670
4011
|
{
|
|
3671
4012
|
internalType: "uint256",
|
|
@@ -3683,13 +4024,68 @@ var batchPurchaseAbi = [
|
|
|
3683
4024
|
type: "uint256[]"
|
|
3684
4025
|
}
|
|
3685
4026
|
],
|
|
3686
|
-
internalType: "struct
|
|
4027
|
+
internalType: "struct IBatchOperations.BulkCostPreview",
|
|
3687
4028
|
name: "preview",
|
|
3688
4029
|
type: "tuple"
|
|
3689
4030
|
}
|
|
3690
4031
|
],
|
|
3691
4032
|
stateMutability: "view",
|
|
3692
4033
|
type: "function"
|
|
4034
|
+
},
|
|
4035
|
+
{
|
|
4036
|
+
inputs: [
|
|
4037
|
+
{
|
|
4038
|
+
internalType: "address",
|
|
4039
|
+
name: "buyer",
|
|
4040
|
+
type: "address"
|
|
4041
|
+
},
|
|
4042
|
+
{
|
|
4043
|
+
components: [
|
|
4044
|
+
{
|
|
4045
|
+
internalType: "uint256",
|
|
4046
|
+
name: "tokenId",
|
|
4047
|
+
type: "uint256"
|
|
4048
|
+
},
|
|
4049
|
+
{
|
|
4050
|
+
internalType: "uint256",
|
|
4051
|
+
name: "expectedPrice",
|
|
4052
|
+
type: "uint256"
|
|
4053
|
+
},
|
|
4054
|
+
{
|
|
4055
|
+
internalType: "uint32",
|
|
4056
|
+
name: "expectedDuration",
|
|
4057
|
+
type: "uint32"
|
|
4058
|
+
},
|
|
4059
|
+
{
|
|
4060
|
+
internalType: "address",
|
|
4061
|
+
name: "expectedPaymentToken",
|
|
4062
|
+
type: "address"
|
|
4063
|
+
},
|
|
4064
|
+
{
|
|
4065
|
+
internalType: "uint16",
|
|
4066
|
+
name: "expectedProtocolFeeBps",
|
|
4067
|
+
type: "uint16"
|
|
4068
|
+
},
|
|
4069
|
+
{
|
|
4070
|
+
internalType: "uint16",
|
|
4071
|
+
name: "expectedAppFeeBps",
|
|
4072
|
+
type: "uint16"
|
|
4073
|
+
}
|
|
4074
|
+
],
|
|
4075
|
+
internalType: "struct IBatchOperations.BuyParams",
|
|
4076
|
+
name: "params",
|
|
4077
|
+
type: "tuple"
|
|
4078
|
+
}
|
|
4079
|
+
],
|
|
4080
|
+
name: "tryERC20Purchase",
|
|
4081
|
+
outputs: [
|
|
4082
|
+
],
|
|
4083
|
+
stateMutability: "nonpayable",
|
|
4084
|
+
type: "function"
|
|
4085
|
+
},
|
|
4086
|
+
{
|
|
4087
|
+
stateMutability: "payable",
|
|
4088
|
+
type: "receive"
|
|
3693
4089
|
}
|
|
3694
4090
|
];
|
|
3695
4091
|
|
|
@@ -5698,38 +6094,36 @@ const ENVIRONMENTS = {
|
|
|
5698
6094
|
ORIGIN_DASHBOARD: "https://origin.campnetwork.xyz",
|
|
5699
6095
|
DATANFT_CONTRACT_ADDRESS: "0x4d9aF5800701A4A686Df6b096A27B81486de36eB",
|
|
5700
6096
|
MARKETPLACE_CONTRACT_ADDRESS: "0x68B202caA162C418d3A2DF92F29fA1CAF90C58c1",
|
|
5701
|
-
|
|
6097
|
+
BATCH_OPERATIONS_CONTRACT_ADDRESS: "0xe1247F1663925B99Db62e60480B53e37f2bb8738",
|
|
5702
6098
|
DISPUTE_CONTRACT_ADDRESS: "0x45719337b1450b0D105cA671972be4263E6A9380",
|
|
5703
6099
|
APP_REGISTRY_CONTRACT_ADDRESS: "0x2096eb980Dd590DDF690Cb698572b80552B6F9Bb",
|
|
5704
|
-
// TODO: Add actual contract addresse when deployed
|
|
5705
6100
|
FRACTIONALIZER_CONTRACT_ADDRESS: "",
|
|
5706
6101
|
USDC_CONTRACT_ADDRESS: "0x8a2B28364102Bea189D99A475C494330Ef2bDD0B",
|
|
5707
6102
|
CHAIN: testnet,
|
|
5708
6103
|
IPNFT_ABI: ipnftMainnetAbi,
|
|
5709
6104
|
MARKETPLACE_ABI: marketplaceMainnetAbi,
|
|
5710
6105
|
TBA_ABI: tbaAbi,
|
|
5711
|
-
|
|
6106
|
+
BATCH_OPERATIONS_ABI: batchOperationsAbi,
|
|
5712
6107
|
DISPUTE_ABI: disputeAbi,
|
|
5713
6108
|
FRACTIONALIZER_ABI: fractionalizerAbi,
|
|
5714
6109
|
APP_REGISTRY_ABI: appRegistryAbi,
|
|
5715
6110
|
},
|
|
5716
6111
|
PRODUCTION: {
|
|
5717
6112
|
NAME: "PRODUCTION",
|
|
5718
|
-
AUTH_HUB_BASE_API: "https://
|
|
6113
|
+
AUTH_HUB_BASE_API: "https://origin-backend-mainnet.vercel.app",
|
|
5719
6114
|
ORIGIN_DASHBOARD: "https://origin.campnetwork.xyz",
|
|
5720
6115
|
DATANFT_CONTRACT_ADDRESS: "0x39EeE1C3989f0dD543Dee60f8582F7F81F522C38",
|
|
5721
6116
|
MARKETPLACE_CONTRACT_ADDRESS: "0xc69BAa987757d054455fC0f2d9797684E9FB8b9C",
|
|
5722
|
-
|
|
5723
|
-
|
|
5724
|
-
DISPUTE_CONTRACT_ADDRESS: "",
|
|
6117
|
+
BATCH_OPERATIONS_CONTRACT_ADDRESS: "0x31885cD2A445322067dF890bACf6CeFE9b233BCC",
|
|
6118
|
+
DISPUTE_CONTRACT_ADDRESS: "0x947A3C4A45f7039e77643026A090025D5412EDa2",
|
|
5725
6119
|
FRACTIONALIZER_CONTRACT_ADDRESS: "",
|
|
5726
|
-
APP_REGISTRY_CONTRACT_ADDRESS: "",
|
|
6120
|
+
APP_REGISTRY_CONTRACT_ADDRESS: "0xd09F15aA280F9109aCd403cA920e67D40Cb6C3FA",
|
|
5727
6121
|
USDC_CONTRACT_ADDRESS: "",
|
|
5728
6122
|
CHAIN: mainnet,
|
|
5729
6123
|
IPNFT_ABI: ipnftMainnetAbi,
|
|
5730
6124
|
MARKETPLACE_ABI: marketplaceMainnetAbi,
|
|
5731
6125
|
TBA_ABI: tbaAbi,
|
|
5732
|
-
|
|
6126
|
+
BATCH_OPERATIONS_ABI: batchOperationsAbi,
|
|
5733
6127
|
DISPUTE_ABI: disputeAbi,
|
|
5734
6128
|
FRACTIONALIZER_ABI: fractionalizerAbi,
|
|
5735
6129
|
APP_REGISTRY_ABI: appRegistryAbi,
|
|
@@ -5944,8 +6338,7 @@ const splitFileIntoChunks = (file, chunkSize) => {
|
|
|
5944
6338
|
return chunks;
|
|
5945
6339
|
};
|
|
5946
6340
|
const getBaseApiUrl = (environment) => {
|
|
5947
|
-
|
|
5948
|
-
return environment.AUTH_HUB_BASE_API + authEndpoint;
|
|
6341
|
+
return environment.AUTH_HUB_BASE_API;
|
|
5949
6342
|
};
|
|
5950
6343
|
|
|
5951
6344
|
/**
|
|
@@ -6081,712 +6474,111 @@ function getTerms(tokenId) {
|
|
|
6081
6474
|
* @returns The address of the owner of the IPNFT.
|
|
6082
6475
|
*/
|
|
6083
6476
|
function ownerOf(tokenId) {
|
|
6084
|
-
return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "ownerOf", [tokenId]);
|
|
6085
|
-
}
|
|
6086
|
-
|
|
6087
|
-
/**
|
|
6088
|
-
* Returns the number of IPNFTs owned by the given address.
|
|
6089
|
-
* @param owner The address to query.
|
|
6090
|
-
* @returns The number of IPNFTs owned by the address.
|
|
6091
|
-
*/
|
|
6092
|
-
function balanceOf(owner) {
|
|
6093
|
-
return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "balanceOf", [owner]);
|
|
6094
|
-
}
|
|
6095
|
-
|
|
6096
|
-
/**
|
|
6097
|
-
* Returns the metadata URI associated with a specific token ID.
|
|
6098
|
-
* @param tokenId The token ID to query.
|
|
6099
|
-
* @returns The metadata URI of the token ID.
|
|
6100
|
-
*/
|
|
6101
|
-
function tokenURI(tokenId) {
|
|
6102
|
-
return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "tokenURI", [tokenId]);
|
|
6103
|
-
}
|
|
6104
|
-
|
|
6105
|
-
/**
|
|
6106
|
-
* Returns the data status of the given token ID.
|
|
6107
|
-
* @param tokenId The token ID to query.
|
|
6108
|
-
* @returns The data status of the token ID.
|
|
6109
|
-
*/
|
|
6110
|
-
function dataStatus(tokenId) {
|
|
6111
|
-
return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "dataStatus", [tokenId]);
|
|
6112
|
-
}
|
|
6113
|
-
|
|
6114
|
-
/**
|
|
6115
|
-
* Checks if an operator is approved to manage all assets of a given owner.
|
|
6116
|
-
* @param owner The address of the asset owner.
|
|
6117
|
-
* @param operator The address of the operator to check.
|
|
6118
|
-
* @return A promise that resolves to a boolean indicating if the operator is approved for all assets of the owner.
|
|
6119
|
-
*/
|
|
6120
|
-
function isApprovedForAll(owner, operator) {
|
|
6121
|
-
return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "isApprovedForAll", [owner, operator]);
|
|
6122
|
-
}
|
|
6123
|
-
|
|
6124
|
-
function transferFrom(from, to, tokenId) {
|
|
6125
|
-
return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "transferFrom", [from, to, tokenId]);
|
|
6126
|
-
}
|
|
6127
|
-
|
|
6128
|
-
function safeTransferFrom(from, to, tokenId, data) {
|
|
6129
|
-
const args = data ? [from, to, tokenId, data] : [from, to, tokenId];
|
|
6130
|
-
return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "safeTransferFrom", args);
|
|
6131
|
-
}
|
|
6132
|
-
|
|
6133
|
-
function approve(to, tokenId) {
|
|
6134
|
-
return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "approve", [to, tokenId]);
|
|
6135
|
-
}
|
|
6136
|
-
|
|
6137
|
-
function setApprovalForAll(operator, approved) {
|
|
6138
|
-
return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "setApprovalForAll", [operator, approved]);
|
|
6139
|
-
}
|
|
6140
|
-
|
|
6141
|
-
/**
|
|
6142
|
-
* Buys access to a data NFT for a specified duration.
|
|
6143
|
-
* @param buyer The address of the buyer.
|
|
6144
|
-
* @param tokenId The ID of the data NFT.
|
|
6145
|
-
* @param expectedPrice The expected price for the access.
|
|
6146
|
-
* @param expectedDuration The expected duration of the access in seconds.
|
|
6147
|
-
* @param expectedPaymentToken The address of the payment token (use zero address for native token).
|
|
6148
|
-
* @param expectedProtocolFeeBps The expected protocol fee in basis points (0-10000). Defaults to 0.
|
|
6149
|
-
* @param expectedAppFeeBps The expected app fee in basis points (0-10000). Defaults to 0.
|
|
6150
|
-
* @param value The amount of native token to send (only required if paying with native token).
|
|
6151
|
-
* @returns A promise that resolves when the transaction is confirmed.
|
|
6152
|
-
*/
|
|
6153
|
-
function buyAccess(buyer, tokenId, expectedPrice, expectedDuration, expectedPaymentToken, expectedProtocolFeeBps = 0, expectedAppFeeBps = 0, value // only for native token payments
|
|
6154
|
-
) {
|
|
6155
|
-
return this.callContractMethod(this.environment.MARKETPLACE_CONTRACT_ADDRESS, this.environment.MARKETPLACE_ABI, "buyAccess", [
|
|
6156
|
-
buyer,
|
|
6157
|
-
tokenId,
|
|
6158
|
-
expectedPrice,
|
|
6159
|
-
expectedDuration,
|
|
6160
|
-
expectedPaymentToken,
|
|
6161
|
-
expectedProtocolFeeBps,
|
|
6162
|
-
expectedAppFeeBps,
|
|
6163
|
-
], { waitForReceipt: true, value });
|
|
6164
|
-
}
|
|
6165
|
-
|
|
6166
|
-
/**
|
|
6167
|
-
* Checks if a user has access to a specific token based on subscription expiry.
|
|
6168
|
-
* @param user - The address of the user.
|
|
6169
|
-
* @param tokenId - The ID of the token.
|
|
6170
|
-
* @returns A promise that resolves to a boolean indicating if the user has access.
|
|
6171
|
-
*/
|
|
6172
|
-
function hasAccess(user, tokenId) {
|
|
6173
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
6174
|
-
try {
|
|
6175
|
-
const expiryTimestamp = yield this.subscriptionExpiry(tokenId, user);
|
|
6176
|
-
const currentTimestamp = BigInt(Math.floor(Date.now() / 1000));
|
|
6177
|
-
return expiryTimestamp > currentTimestamp;
|
|
6178
|
-
}
|
|
6179
|
-
catch (error) {
|
|
6180
|
-
return false;
|
|
6181
|
-
}
|
|
6182
|
-
});
|
|
6183
|
-
}
|
|
6184
|
-
|
|
6185
|
-
function subscriptionExpiry(tokenId, user) {
|
|
6186
|
-
return this.callContractMethod(this.environment.MARKETPLACE_CONTRACT_ADDRESS, this.environment.MARKETPLACE_ABI, "subscriptionExpiry", [tokenId, user]);
|
|
6187
|
-
}
|
|
6188
|
-
|
|
6189
|
-
/**
|
|
6190
|
-
* Adapter for viem WalletClient
|
|
6191
|
-
*/
|
|
6192
|
-
class ViemSignerAdapter {
|
|
6193
|
-
constructor(signer) {
|
|
6194
|
-
this.type = "viem";
|
|
6195
|
-
this.signer = signer;
|
|
6196
|
-
}
|
|
6197
|
-
getAddress() {
|
|
6198
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
6199
|
-
if (this.signer.account) {
|
|
6200
|
-
return this.signer.account.address;
|
|
6201
|
-
}
|
|
6202
|
-
const accounts = yield this.signer.request({
|
|
6203
|
-
method: "eth_requestAccounts",
|
|
6204
|
-
params: [],
|
|
6205
|
-
});
|
|
6206
|
-
if (!accounts || accounts.length === 0) {
|
|
6207
|
-
throw new Error("No accounts found in viem wallet client");
|
|
6208
|
-
}
|
|
6209
|
-
return accounts[0];
|
|
6210
|
-
});
|
|
6211
|
-
}
|
|
6212
|
-
signMessage(message) {
|
|
6213
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
6214
|
-
const address = yield this.getAddress();
|
|
6215
|
-
return yield this.signer.signMessage({
|
|
6216
|
-
account: address,
|
|
6217
|
-
message,
|
|
6218
|
-
});
|
|
6219
|
-
});
|
|
6220
|
-
}
|
|
6221
|
-
signTypedData(domain, types, value) {
|
|
6222
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
6223
|
-
throw new Error("Viem WalletClient does not support signTypedData");
|
|
6224
|
-
});
|
|
6225
|
-
}
|
|
6226
|
-
getChainId() {
|
|
6227
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
6228
|
-
var _a;
|
|
6229
|
-
return ((_a = this.signer.chain) === null || _a === void 0 ? void 0 : _a.id) || 1;
|
|
6230
|
-
});
|
|
6231
|
-
}
|
|
6232
|
-
}
|
|
6233
|
-
/**
|
|
6234
|
-
* Adapter for ethers Signer (v5 and v6)
|
|
6235
|
-
*/
|
|
6236
|
-
class EthersSignerAdapter {
|
|
6237
|
-
constructor(signer) {
|
|
6238
|
-
this.type = "ethers";
|
|
6239
|
-
this.signer = signer;
|
|
6240
|
-
}
|
|
6241
|
-
getAddress() {
|
|
6242
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
6243
|
-
// Works for both ethers v5 and v6
|
|
6244
|
-
if (typeof this.signer.getAddress === "function") {
|
|
6245
|
-
return yield this.signer.getAddress();
|
|
6246
|
-
}
|
|
6247
|
-
if (this.signer.address) {
|
|
6248
|
-
return this.signer.address;
|
|
6249
|
-
}
|
|
6250
|
-
throw new Error("Unable to get address from ethers signer");
|
|
6251
|
-
});
|
|
6252
|
-
}
|
|
6253
|
-
signMessage(message) {
|
|
6254
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
6255
|
-
if (typeof this.signer.signMessage !== "function") {
|
|
6256
|
-
throw new Error("Signer does not support signMessage");
|
|
6257
|
-
}
|
|
6258
|
-
return yield this.signer.signMessage(message);
|
|
6259
|
-
});
|
|
6260
|
-
}
|
|
6261
|
-
signTypedData(domain, types, value) {
|
|
6262
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
6263
|
-
if (typeof this.signer._signTypedData === "function") {
|
|
6264
|
-
return yield this.signer._signTypedData(domain, types, value);
|
|
6265
|
-
}
|
|
6266
|
-
if (typeof this.signer.signTypedData !== "function") {
|
|
6267
|
-
throw new Error("Signer does not support signTypedData or _signTypedData");
|
|
6268
|
-
}
|
|
6269
|
-
return yield this.signer.signTypedData(domain, types, value);
|
|
6270
|
-
});
|
|
6271
|
-
}
|
|
6272
|
-
getChainId() {
|
|
6273
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
6274
|
-
// Try ethers v6 first
|
|
6275
|
-
if (this.signer.provider &&
|
|
6276
|
-
typeof this.signer.provider.getNetwork === "function") {
|
|
6277
|
-
const network = yield this.signer.provider.getNetwork();
|
|
6278
|
-
// ethers v6 returns bigint, v5 returns number
|
|
6279
|
-
return typeof network.chainId === "bigint"
|
|
6280
|
-
? Number(network.chainId)
|
|
6281
|
-
: network.chainId;
|
|
6282
|
-
}
|
|
6283
|
-
// Fallback for ethers v5
|
|
6284
|
-
if (typeof this.signer.getChainId === "function") {
|
|
6285
|
-
return yield this.signer.getChainId();
|
|
6286
|
-
}
|
|
6287
|
-
// Default to mainnet if we can't determine
|
|
6288
|
-
return 484;
|
|
6289
|
-
});
|
|
6290
|
-
}
|
|
6291
|
-
}
|
|
6292
|
-
/**
|
|
6293
|
-
* Adapter for custom signer implementations
|
|
6294
|
-
*/
|
|
6295
|
-
class CustomSignerAdapter {
|
|
6296
|
-
constructor(signer) {
|
|
6297
|
-
this.type = "custom";
|
|
6298
|
-
this.signer = signer;
|
|
6299
|
-
}
|
|
6300
|
-
getAddress() {
|
|
6301
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
6302
|
-
if (typeof this.signer.getAddress === "function") {
|
|
6303
|
-
return yield this.signer.getAddress();
|
|
6304
|
-
}
|
|
6305
|
-
if (this.signer.address) {
|
|
6306
|
-
return this.signer.address;
|
|
6307
|
-
}
|
|
6308
|
-
throw new Error("Custom signer must implement getAddress() or have address property");
|
|
6309
|
-
});
|
|
6310
|
-
}
|
|
6311
|
-
signMessage(message) {
|
|
6312
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
6313
|
-
if (typeof this.signer.signMessage !== "function") {
|
|
6314
|
-
throw new Error("Custom signer must implement signMessage()");
|
|
6315
|
-
}
|
|
6316
|
-
return yield this.signer.signMessage(message);
|
|
6317
|
-
});
|
|
6318
|
-
}
|
|
6319
|
-
signTypedData(domain, types, value) {
|
|
6320
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
6321
|
-
if (typeof this.signer.signTypedData !== "function") {
|
|
6322
|
-
throw new Error("Custom signer must implement signTypedData()");
|
|
6323
|
-
}
|
|
6324
|
-
return yield this.signer.signTypedData(domain, types, value);
|
|
6325
|
-
});
|
|
6326
|
-
}
|
|
6327
|
-
getChainId() {
|
|
6328
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
6329
|
-
if (typeof this.signer.getChainId === "function") {
|
|
6330
|
-
const chainId = yield this.signer.getChainId();
|
|
6331
|
-
return typeof chainId === "bigint" ? Number(chainId) : chainId;
|
|
6332
|
-
}
|
|
6333
|
-
if (this.signer.chainId !== undefined) {
|
|
6334
|
-
return typeof this.signer.chainId === "bigint"
|
|
6335
|
-
? Number(this.signer.chainId)
|
|
6336
|
-
: this.signer.chainId;
|
|
6337
|
-
}
|
|
6338
|
-
// Default to mainnet
|
|
6339
|
-
return 484;
|
|
6340
|
-
});
|
|
6341
|
-
}
|
|
6342
|
-
}
|
|
6343
|
-
/**
|
|
6344
|
-
* Factory function to create appropriate adapter based on signer type
|
|
6345
|
-
*/
|
|
6346
|
-
function createSignerAdapter(signer) {
|
|
6347
|
-
// Check for viem WalletClient
|
|
6348
|
-
if (signer.transport &&
|
|
6349
|
-
signer.chain &&
|
|
6350
|
-
typeof signer.signMessage === "function") {
|
|
6351
|
-
return new ViemSignerAdapter(signer);
|
|
6352
|
-
}
|
|
6353
|
-
// Check for ethers signer (v5 or v6)
|
|
6354
|
-
if (signer._isSigner ||
|
|
6355
|
-
(signer.provider && typeof signer.signMessage === "function")) {
|
|
6356
|
-
return new EthersSignerAdapter(signer);
|
|
6357
|
-
}
|
|
6358
|
-
// Try custom adapter
|
|
6359
|
-
return new CustomSignerAdapter(signer);
|
|
6360
|
-
}
|
|
6361
|
-
|
|
6362
|
-
/**
|
|
6363
|
-
* Fetches the protocol fee from the marketplace contract.
|
|
6364
|
-
*/
|
|
6365
|
-
function getProtocolFeeBps(origin) {
|
|
6366
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
6367
|
-
try {
|
|
6368
|
-
const protocolFeeBps = yield origin.callContractMethod(origin.environment.MARKETPLACE_CONTRACT_ADDRESS, origin.environment.MARKETPLACE_ABI, "protocolFeeBps", []);
|
|
6369
|
-
return Number(protocolFeeBps);
|
|
6370
|
-
}
|
|
6371
|
-
catch (error) {
|
|
6372
|
-
console.warn("Failed to fetch protocol fee, defaulting to 0:", error);
|
|
6373
|
-
return 0;
|
|
6374
|
-
}
|
|
6375
|
-
});
|
|
6376
|
-
}
|
|
6377
|
-
/**
|
|
6378
|
-
* Fetches the app fee for a specific token from the AppRegistry.
|
|
6379
|
-
*/
|
|
6380
|
-
function getAppFeeBpsForToken(origin, tokenId) {
|
|
6381
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
6382
|
-
try {
|
|
6383
|
-
const tokenInfo = yield origin.callContractMethod(origin.environment.DATANFT_CONTRACT_ADDRESS, origin.environment.IPNFT_ABI, "tokenInfo", [tokenId]);
|
|
6384
|
-
const appId = tokenInfo === null || tokenInfo === void 0 ? void 0 : tokenInfo.appId;
|
|
6385
|
-
if (!appId || appId === "")
|
|
6386
|
-
return 0;
|
|
6387
|
-
if (!origin.environment.APP_REGISTRY_CONTRACT_ADDRESS ||
|
|
6388
|
-
!origin.environment.APP_REGISTRY_ABI) {
|
|
6389
|
-
return 0;
|
|
6390
|
-
}
|
|
6391
|
-
const appInfo = yield origin.callContractMethod(origin.environment.APP_REGISTRY_CONTRACT_ADDRESS, origin.environment.APP_REGISTRY_ABI, "getAppInfo", [appId]);
|
|
6392
|
-
if (appInfo === null || appInfo === void 0 ? void 0 : appInfo.isActive) {
|
|
6393
|
-
return Number(appInfo.revenueShareBps);
|
|
6394
|
-
}
|
|
6395
|
-
return 0;
|
|
6396
|
-
}
|
|
6397
|
-
catch (error) {
|
|
6398
|
-
console.warn("Failed to fetch app fee, defaulting to 0:", error);
|
|
6399
|
-
return 0;
|
|
6400
|
-
}
|
|
6401
|
-
});
|
|
6402
|
-
}
|
|
6403
|
-
/**
|
|
6404
|
-
* EXPERIMENTAL METHOD
|
|
6405
|
-
* Settles a payment intent response by purchasing access if needed.
|
|
6406
|
-
* This method checks if the user already has access to the item, and if not,
|
|
6407
|
-
* it calls buyAccess with the parameters from the payment intent response.
|
|
6408
|
-
* Supports viem WalletClient, ethers Signer, and custom signer implementations.
|
|
6409
|
-
*
|
|
6410
|
-
* @param paymentIntentResponse - The response from getDataWithIntent containing payment details.
|
|
6411
|
-
* @param signer - Optional signer object used to interact with the blockchain. If not provided, uses the connected wallet client.
|
|
6412
|
-
* @returns A promise that resolves with the transaction hash and receipt, or null if access already exists.
|
|
6413
|
-
* @throws {Error} If the response doesn't contain marketplace action or if the method is not buyAccess.
|
|
6414
|
-
*/
|
|
6415
|
-
function settlePaymentIntent(paymentIntentResponse, signer) {
|
|
6416
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
6417
|
-
if (!paymentIntentResponse.marketplaceAction) {
|
|
6418
|
-
throw new ValidationError("Invalid X402 response: no marketplace action found. The response may be malformed or the server returned an error.");
|
|
6419
|
-
}
|
|
6420
|
-
const { marketplaceAction } = paymentIntentResponse;
|
|
6421
|
-
if (marketplaceAction.method !== "buyAccess") {
|
|
6422
|
-
throw new ValidationError(`Unsupported marketplace action method "${marketplaceAction.method}". Only "buyAccess" is currently supported.`);
|
|
6423
|
-
}
|
|
6424
|
-
const tokenId = BigInt(marketplaceAction.tokenId);
|
|
6425
|
-
const payerAddress = marketplaceAction.payer;
|
|
6426
|
-
const alreadyHasAccess = yield this.hasAccess(payerAddress, tokenId);
|
|
6427
|
-
if (alreadyHasAccess) {
|
|
6428
|
-
console.log("User already has access to this item");
|
|
6429
|
-
return null;
|
|
6430
|
-
}
|
|
6431
|
-
const expectedPrice = BigInt(marketplaceAction.amount);
|
|
6432
|
-
const expectedDuration = BigInt(marketplaceAction.duration);
|
|
6433
|
-
const expectedPaymentToken = marketplaceAction.asset;
|
|
6434
|
-
const isNativeToken = expectedPaymentToken === "0x0000000000000000000000000000000000000000";
|
|
6435
|
-
const value = isNativeToken ? expectedPrice : BigInt(0);
|
|
6436
|
-
const [protocolFeeBps, appFeeBps] = yield Promise.all([
|
|
6437
|
-
getProtocolFeeBps(this),
|
|
6438
|
-
getAppFeeBpsForToken(this, tokenId),
|
|
6439
|
-
]);
|
|
6440
|
-
if (signer) {
|
|
6441
|
-
const signerAdapter = createSignerAdapter(signer);
|
|
6442
|
-
const marketplaceAddress = this.environment
|
|
6443
|
-
.MARKETPLACE_CONTRACT_ADDRESS;
|
|
6444
|
-
const abi = this.environment.MARKETPLACE_ABI;
|
|
6445
|
-
const data = encodeFunctionData({
|
|
6446
|
-
abi,
|
|
6447
|
-
functionName: "buyAccess",
|
|
6448
|
-
args: [
|
|
6449
|
-
payerAddress,
|
|
6450
|
-
tokenId,
|
|
6451
|
-
expectedPrice,
|
|
6452
|
-
expectedDuration,
|
|
6453
|
-
expectedPaymentToken,
|
|
6454
|
-
protocolFeeBps,
|
|
6455
|
-
appFeeBps,
|
|
6456
|
-
],
|
|
6457
|
-
});
|
|
6458
|
-
if (signerAdapter.type === "viem") {
|
|
6459
|
-
const viemSigner = signerAdapter.signer;
|
|
6460
|
-
const txHash = yield viemSigner.sendTransaction({
|
|
6461
|
-
to: marketplaceAddress,
|
|
6462
|
-
data,
|
|
6463
|
-
value,
|
|
6464
|
-
account: (yield signerAdapter.getAddress()),
|
|
6465
|
-
});
|
|
6466
|
-
const receipt = yield viemSigner.waitForTransactionReceipt({
|
|
6467
|
-
hash: txHash,
|
|
6468
|
-
});
|
|
6469
|
-
return { txHash, receipt };
|
|
6470
|
-
}
|
|
6471
|
-
else if (signerAdapter.type === "ethers") {
|
|
6472
|
-
const ethersSigner = signerAdapter.signer;
|
|
6473
|
-
const tx = yield ethersSigner.sendTransaction({
|
|
6474
|
-
to: marketplaceAddress,
|
|
6475
|
-
data,
|
|
6476
|
-
value: value.toString(),
|
|
6477
|
-
});
|
|
6478
|
-
const receipt = yield tx.wait();
|
|
6479
|
-
return { txHash: tx.hash, receipt };
|
|
6480
|
-
}
|
|
6481
|
-
else {
|
|
6482
|
-
const customSigner = signerAdapter.signer;
|
|
6483
|
-
if (typeof customSigner.sendTransaction !== "function") {
|
|
6484
|
-
throw new ValidationError("Custom signer must implement sendTransaction() method to settle payment intents");
|
|
6485
|
-
}
|
|
6486
|
-
const tx = yield customSigner.sendTransaction({
|
|
6487
|
-
to: marketplaceAddress,
|
|
6488
|
-
data,
|
|
6489
|
-
value: value.toString(),
|
|
6490
|
-
});
|
|
6491
|
-
if (tx.wait && typeof tx.wait === "function") {
|
|
6492
|
-
const receipt = yield tx.wait();
|
|
6493
|
-
return { txHash: tx.hash, receipt };
|
|
6494
|
-
}
|
|
6495
|
-
return { txHash: tx.hash || tx };
|
|
6496
|
-
}
|
|
6497
|
-
}
|
|
6498
|
-
if (!this.viemClient) {
|
|
6499
|
-
throw new WalletError("Cannot settle payment intent: no signer or wallet connected. Please connect a wallet or provide a signer.");
|
|
6500
|
-
}
|
|
6501
|
-
return yield this.buyAccess(payerAddress, tokenId, expectedPrice, expectedDuration, expectedPaymentToken, protocolFeeBps, appFeeBps, isNativeToken ? value : undefined);
|
|
6502
|
-
});
|
|
6503
|
-
}
|
|
6504
|
-
|
|
6505
|
-
/**
|
|
6506
|
-
* Resolves a wallet address from an optional address parameter or connected wallet.
|
|
6507
|
-
* Checks viemClient.account first, then falls back to eth_requestAccounts.
|
|
6508
|
-
*
|
|
6509
|
-
* @param viemClient The viem WalletClient instance.
|
|
6510
|
-
* @param address Optional address to use directly.
|
|
6511
|
-
* @returns The resolved wallet address.
|
|
6512
|
-
* @throws Error if no address provided and no wallet connected or no accounts found.
|
|
6513
|
-
*/
|
|
6514
|
-
function resolveWalletAddress(viemClient, address) {
|
|
6515
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
6516
|
-
if (address) {
|
|
6517
|
-
return address;
|
|
6518
|
-
}
|
|
6519
|
-
if (!viemClient) {
|
|
6520
|
-
throw new Error("No address provided and no wallet connected. Please provide an address or connect a wallet.");
|
|
6521
|
-
}
|
|
6522
|
-
if (viemClient.account) {
|
|
6523
|
-
return viemClient.account.address;
|
|
6524
|
-
}
|
|
6525
|
-
const accounts = yield viemClient.request({
|
|
6526
|
-
method: "eth_requestAccounts",
|
|
6527
|
-
params: [],
|
|
6528
|
-
});
|
|
6529
|
-
if (!accounts || accounts.length === 0) {
|
|
6530
|
-
throw new Error("No accounts found in connected wallet.");
|
|
6531
|
-
}
|
|
6532
|
-
return accounts[0];
|
|
6533
|
-
});
|
|
6534
|
-
}
|
|
6535
|
-
/**
|
|
6536
|
-
* Enum representing the type of license for an IP NFT.
|
|
6537
|
-
* - DURATION_BASED: License expires after a set duration (subscription model).
|
|
6538
|
-
* - SINGLE_PAYMENT: One-time payment for perpetual access.
|
|
6539
|
-
* - X402: HTTP 402-based micropayment license (no on-chain payments).
|
|
6540
|
-
*/
|
|
6541
|
-
var LicenseType;
|
|
6542
|
-
(function (LicenseType) {
|
|
6543
|
-
LicenseType[LicenseType["DURATION_BASED"] = 0] = "DURATION_BASED";
|
|
6544
|
-
LicenseType[LicenseType["SINGLE_PAYMENT"] = 1] = "SINGLE_PAYMENT";
|
|
6545
|
-
LicenseType[LicenseType["X402"] = 2] = "X402";
|
|
6546
|
-
})(LicenseType || (LicenseType = {}));
|
|
6547
|
-
/**
|
|
6548
|
-
* Enum representing the status of data in the system.
|
|
6549
|
-
* - ACTIVE: The data is currently active and available.
|
|
6550
|
-
* - DELETED: The data has been deleted and is no longer available.
|
|
6551
|
-
* - DISPUTED: The data has been disputed and marked as potentially infringing.
|
|
6552
|
-
*/
|
|
6553
|
-
var DataStatus;
|
|
6554
|
-
(function (DataStatus) {
|
|
6555
|
-
DataStatus[DataStatus["ACTIVE"] = 0] = "ACTIVE";
|
|
6556
|
-
DataStatus[DataStatus["DELETED"] = 1] = "DELETED";
|
|
6557
|
-
DataStatus[DataStatus["DISPUTED"] = 2] = "DISPUTED";
|
|
6558
|
-
})(DataStatus || (DataStatus = {}));
|
|
6559
|
-
/**
|
|
6560
|
-
* Enum representing the status of a dispute.
|
|
6561
|
-
* - Uninitialized: Dispute does not exist.
|
|
6562
|
-
* - Raised: Dispute has been raised but not yet asserted by IP owner.
|
|
6563
|
-
* - Asserted: IP owner has responded to the dispute.
|
|
6564
|
-
* - Resolved: Dispute has been resolved (either valid or invalid).
|
|
6565
|
-
* - Cancelled: Dispute was cancelled by the initiator.
|
|
6566
|
-
*/
|
|
6567
|
-
var DisputeStatus;
|
|
6568
|
-
(function (DisputeStatus) {
|
|
6569
|
-
DisputeStatus[DisputeStatus["Uninitialized"] = 0] = "Uninitialized";
|
|
6570
|
-
DisputeStatus[DisputeStatus["Raised"] = 1] = "Raised";
|
|
6571
|
-
DisputeStatus[DisputeStatus["Asserted"] = 2] = "Asserted";
|
|
6572
|
-
DisputeStatus[DisputeStatus["Resolved"] = 3] = "Resolved";
|
|
6573
|
-
DisputeStatus[DisputeStatus["Cancelled"] = 4] = "Cancelled";
|
|
6574
|
-
})(DisputeStatus || (DisputeStatus = {}));
|
|
6575
|
-
/**
|
|
6576
|
-
* Creates license terms for a digital asset.
|
|
6577
|
-
* @param price The price of the asset in wei.
|
|
6578
|
-
* @param duration The duration of the license in seconds (use 0 for SINGLE_PAYMENT and X402).
|
|
6579
|
-
* @param royaltyBps The royalty percentage in basis points (0-10000).
|
|
6580
|
-
* @param paymentToken The address of the payment token (ERC20 / address(0) for native currency).
|
|
6581
|
-
* @param licenseType The type of license (defaults to DURATION_BASED).
|
|
6582
|
-
* @returns The created license terms.
|
|
6477
|
+
return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "ownerOf", [tokenId]);
|
|
6478
|
+
}
|
|
6479
|
+
|
|
6480
|
+
/**
|
|
6481
|
+
* Returns the number of IPNFTs owned by the given address.
|
|
6482
|
+
* @param owner The address to query.
|
|
6483
|
+
* @returns The number of IPNFTs owned by the address.
|
|
6583
6484
|
*/
|
|
6584
|
-
|
|
6585
|
-
|
|
6586
|
-
|
|
6587
|
-
|
|
6588
|
-
}
|
|
6589
|
-
if (licenseType === LicenseType.DURATION_BASED) {
|
|
6590
|
-
if (duration < constants.MIN_LICENSE_DURATION ||
|
|
6591
|
-
duration > constants.MAX_LICENSE_DURATION) {
|
|
6592
|
-
throw new Error(`Duration must be between ${constants.MIN_LICENSE_DURATION} and ${constants.MAX_LICENSE_DURATION} seconds for DURATION_BASED licenses`);
|
|
6593
|
-
}
|
|
6594
|
-
}
|
|
6595
|
-
else if ((licenseType === LicenseType.SINGLE_PAYMENT ||
|
|
6596
|
-
licenseType === LicenseType.X402) &&
|
|
6597
|
-
duration > 0) {
|
|
6598
|
-
throw new Error(`Duration must be 0 for ${LicenseType[licenseType]} licenses`);
|
|
6599
|
-
}
|
|
6600
|
-
if (price < constants.MIN_PRICE) {
|
|
6601
|
-
throw new Error(`Price must be at least ${constants.MIN_PRICE} wei`);
|
|
6602
|
-
}
|
|
6603
|
-
return {
|
|
6604
|
-
price,
|
|
6605
|
-
duration,
|
|
6606
|
-
royaltyBps,
|
|
6607
|
-
paymentToken,
|
|
6608
|
-
licenseType,
|
|
6609
|
-
};
|
|
6610
|
-
};
|
|
6485
|
+
function balanceOf(owner) {
|
|
6486
|
+
return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "balanceOf", [owner]);
|
|
6487
|
+
}
|
|
6488
|
+
|
|
6611
6489
|
/**
|
|
6612
|
-
*
|
|
6490
|
+
* Returns the metadata URI associated with a specific token ID.
|
|
6491
|
+
* @param tokenId The token ID to query.
|
|
6492
|
+
* @returns The metadata URI of the token ID.
|
|
6613
6493
|
*/
|
|
6614
|
-
|
|
6615
|
-
|
|
6616
|
-
|
|
6617
|
-
{ name: "asset", type: "address" },
|
|
6618
|
-
{ name: "amount", type: "uint256" },
|
|
6619
|
-
{ name: "httpMethod", type: "string" },
|
|
6620
|
-
{ name: "payTo", type: "address" },
|
|
6621
|
-
{ name: "tokenId", type: "uint256" },
|
|
6622
|
-
{ name: "duration", type: "uint32" },
|
|
6623
|
-
{ name: "expiresAt", type: "uint256" },
|
|
6624
|
-
{ name: "nonce", type: "bytes32" },
|
|
6625
|
-
],
|
|
6626
|
-
};
|
|
6494
|
+
function tokenURI(tokenId) {
|
|
6495
|
+
return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "tokenURI", [tokenId]);
|
|
6496
|
+
}
|
|
6627
6497
|
|
|
6628
|
-
const fetchTokenData = (origin, tokenId, headers) => __awaiter(void 0, void 0, void 0, function* () {
|
|
6629
|
-
const response = yield fetch(`${origin.environment.AUTH_HUB_BASE_API}/origin/data/${tokenId}`, {
|
|
6630
|
-
method: "GET",
|
|
6631
|
-
headers: Object.assign({ "Content-Type": "application/json" }, headers),
|
|
6632
|
-
});
|
|
6633
|
-
return response;
|
|
6634
|
-
});
|
|
6635
6498
|
/**
|
|
6636
|
-
*
|
|
6637
|
-
*
|
|
6638
|
-
* @
|
|
6639
|
-
* @param {any} [signer] Optional signer object for signing the X402 intent.
|
|
6640
|
-
* @returns {Promise<any>} A promise that resolves with the fetched data.
|
|
6641
|
-
* @throws {Error} Throws an error if the data cannot be fetched or if no signer/wallet client is provided.
|
|
6499
|
+
* Returns the data status of the given token ID.
|
|
6500
|
+
* @param tokenId The token ID to query.
|
|
6501
|
+
* @returns The data status of the token ID.
|
|
6642
6502
|
*/
|
|
6643
|
-
function
|
|
6644
|
-
return
|
|
6645
|
-
var _a;
|
|
6646
|
-
const viemClient = this.viemClient;
|
|
6647
|
-
if (!signer && !viemClient) {
|
|
6648
|
-
throw new WalletError(`Cannot fetch data for token ${tokenId}: no signer or wallet client provided. Please connect a wallet or provide a signer.`);
|
|
6649
|
-
}
|
|
6650
|
-
const initialResponse = yield fetchTokenData(this, tokenId, {});
|
|
6651
|
-
if (initialResponse.status !== 402) {
|
|
6652
|
-
if (!initialResponse.ok) {
|
|
6653
|
-
const errorText = yield initialResponse
|
|
6654
|
-
.text()
|
|
6655
|
-
.catch(() => initialResponse.statusText);
|
|
6656
|
-
throw new APIError(`Failed to fetch data for token ${tokenId} (HTTP ${initialResponse.status}): ${errorText}`, initialResponse.status);
|
|
6657
|
-
}
|
|
6658
|
-
return initialResponse.json();
|
|
6659
|
-
}
|
|
6660
|
-
const sig = viemClient || createSignerAdapter(signer);
|
|
6661
|
-
const walletAddress = viemClient
|
|
6662
|
-
? yield getCurrentAccount.call(this)
|
|
6663
|
-
: yield sig.getAddress();
|
|
6664
|
-
const intentData = yield initialResponse.json();
|
|
6665
|
-
if (intentData.error) {
|
|
6666
|
-
throw new APIError(`Failed to process X402 intent for token ${tokenId}: ${intentData.error}`);
|
|
6667
|
-
}
|
|
6668
|
-
const requirements = intentData.accepts[0];
|
|
6669
|
-
const x402Payload = yield buildX402Payload.call(this, requirements, checksumAddress(walletAddress), sig);
|
|
6670
|
-
const header = btoa(JSON.stringify(x402Payload));
|
|
6671
|
-
const retryResponse = yield fetchTokenData(this, tokenId, {
|
|
6672
|
-
"X-PAYMENT": header,
|
|
6673
|
-
});
|
|
6674
|
-
if (retryResponse.status === 402) {
|
|
6675
|
-
// subscription required
|
|
6676
|
-
if (decide) {
|
|
6677
|
-
const resJson = yield retryResponse.json();
|
|
6678
|
-
const accepted = yield decide(resJson.marketplaceAction);
|
|
6679
|
-
if (accepted) {
|
|
6680
|
-
const settlement = yield this.settlePaymentIntent(resJson, signer || viemClient);
|
|
6681
|
-
if (settlement && !settlement.txHash) {
|
|
6682
|
-
throw new APIError(`Failed to settle X402 payment for token ${tokenId}: no transaction hash returned`);
|
|
6683
|
-
}
|
|
6684
|
-
// retry fetching data after settlement
|
|
6685
|
-
const finalResponse = yield this.getDataWithIntent(tokenId, signer, undefined);
|
|
6686
|
-
return finalResponse;
|
|
6687
|
-
}
|
|
6688
|
-
else {
|
|
6689
|
-
// user declined to proceed with payment
|
|
6690
|
-
return {
|
|
6691
|
-
error: "User declined to proceed with payment",
|
|
6692
|
-
data: null,
|
|
6693
|
-
};
|
|
6694
|
-
}
|
|
6695
|
-
}
|
|
6696
|
-
else {
|
|
6697
|
-
return retryResponse.json();
|
|
6698
|
-
}
|
|
6699
|
-
}
|
|
6700
|
-
if (!retryResponse.ok) {
|
|
6701
|
-
const errorText = yield retryResponse
|
|
6702
|
-
.text()
|
|
6703
|
-
.catch(() => retryResponse.statusText);
|
|
6704
|
-
throw new APIError(`Failed to fetch data for token ${tokenId} after X402 payment (HTTP ${retryResponse.status}): ${errorText}`, retryResponse.status);
|
|
6705
|
-
}
|
|
6706
|
-
const res = yield retryResponse.json();
|
|
6707
|
-
return {
|
|
6708
|
-
error: null,
|
|
6709
|
-
data: (_a = res.data) !== null && _a !== void 0 ? _a : res,
|
|
6710
|
-
};
|
|
6711
|
-
});
|
|
6503
|
+
function dataStatus(tokenId) {
|
|
6504
|
+
return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "dataStatus", [tokenId]);
|
|
6712
6505
|
}
|
|
6506
|
+
|
|
6713
6507
|
/**
|
|
6714
|
-
*
|
|
6715
|
-
* @
|
|
6508
|
+
* Checks if an operator is approved to manage all assets of a given owner.
|
|
6509
|
+
* @param owner The address of the asset owner.
|
|
6510
|
+
* @param operator The address of the operator to check.
|
|
6511
|
+
* @return A promise that resolves to a boolean indicating if the operator is approved for all assets of the owner.
|
|
6716
6512
|
*/
|
|
6717
|
-
function
|
|
6718
|
-
return
|
|
6719
|
-
|
|
6720
|
-
|
|
6721
|
-
|
|
6722
|
-
|
|
6723
|
-
|
|
6724
|
-
|
|
6725
|
-
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
|
|
6729
|
-
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
|
|
6735
|
-
|
|
6736
|
-
};
|
|
6737
|
-
const signerAdapter = createSignerAdapter(signer);
|
|
6738
|
-
const signature = yield signerAdapter.signTypedData(domain, types, payment);
|
|
6739
|
-
const x402Payload = {
|
|
6740
|
-
x402Version: 1,
|
|
6741
|
-
scheme: "exact",
|
|
6742
|
-
network: requirements.network,
|
|
6743
|
-
payload: Object.assign(Object.assign({}, payment), { sigType: "eip712", signature: signature, license: {
|
|
6744
|
-
tokenId: requirements.extra.tokenId,
|
|
6745
|
-
duration: duration,
|
|
6746
|
-
} }),
|
|
6747
|
-
};
|
|
6748
|
-
return x402Payload;
|
|
6749
|
-
});
|
|
6513
|
+
function isApprovedForAll(owner, operator) {
|
|
6514
|
+
return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "isApprovedForAll", [owner, operator]);
|
|
6515
|
+
}
|
|
6516
|
+
|
|
6517
|
+
function transferFrom(from, to, tokenId) {
|
|
6518
|
+
return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "transferFrom", [from, to, tokenId]);
|
|
6519
|
+
}
|
|
6520
|
+
|
|
6521
|
+
function safeTransferFrom(from, to, tokenId, data) {
|
|
6522
|
+
const args = data ? [from, to, tokenId, data] : [from, to, tokenId];
|
|
6523
|
+
return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "safeTransferFrom", args);
|
|
6524
|
+
}
|
|
6525
|
+
|
|
6526
|
+
function approve(to, tokenId) {
|
|
6527
|
+
return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "approve", [to, tokenId]);
|
|
6528
|
+
}
|
|
6529
|
+
|
|
6530
|
+
function setApprovalForAll(operator, approved) {
|
|
6531
|
+
return this.callContractMethod(this.environment.DATANFT_CONTRACT_ADDRESS, this.environment.IPNFT_ABI, "setApprovalForAll", [operator, approved]);
|
|
6750
6532
|
}
|
|
6533
|
+
|
|
6751
6534
|
/**
|
|
6752
|
-
*
|
|
6753
|
-
* @
|
|
6535
|
+
* Buys access to a data NFT for a specified duration.
|
|
6536
|
+
* @param buyer The address of the buyer.
|
|
6537
|
+
* @param tokenId The ID of the data NFT.
|
|
6538
|
+
* @param expectedPrice The expected price for the access.
|
|
6539
|
+
* @param expectedDuration The expected duration of the access in seconds.
|
|
6540
|
+
* @param expectedPaymentToken The address of the payment token (use zero address for native token).
|
|
6541
|
+
* @param expectedProtocolFeeBps The expected protocol fee in basis points (0-10000). Defaults to 0.
|
|
6542
|
+
* @param expectedAppFeeBps The expected app fee in basis points (0-10000). Defaults to 0.
|
|
6543
|
+
* @param value The amount of native token to send (only required if paying with native token).
|
|
6544
|
+
* @returns A promise that resolves when the transaction is confirmed.
|
|
6754
6545
|
*/
|
|
6755
|
-
function
|
|
6756
|
-
|
|
6757
|
-
|
|
6758
|
-
|
|
6759
|
-
|
|
6760
|
-
|
|
6761
|
-
|
|
6762
|
-
|
|
6546
|
+
function buyAccess(buyer, tokenId, expectedPrice, expectedDuration, expectedPaymentToken, expectedProtocolFeeBps = 0, expectedAppFeeBps = 0, value // only for native token payments
|
|
6547
|
+
) {
|
|
6548
|
+
return this.callContractMethod(this.environment.MARKETPLACE_CONTRACT_ADDRESS, this.environment.MARKETPLACE_ABI, "buyAccess", [
|
|
6549
|
+
buyer,
|
|
6550
|
+
tokenId,
|
|
6551
|
+
expectedPrice,
|
|
6552
|
+
expectedDuration,
|
|
6553
|
+
expectedPaymentToken,
|
|
6554
|
+
expectedProtocolFeeBps,
|
|
6555
|
+
expectedAppFeeBps,
|
|
6556
|
+
], { waitForReceipt: true, value });
|
|
6763
6557
|
}
|
|
6558
|
+
|
|
6764
6559
|
/**
|
|
6765
|
-
*
|
|
6766
|
-
* @
|
|
6560
|
+
* Checks if a user has access to a specific token based on subscription expiry.
|
|
6561
|
+
* @param user - The address of the user.
|
|
6562
|
+
* @param tokenId - The ID of the token.
|
|
6563
|
+
* @returns A promise that resolves to a boolean indicating if the user has access.
|
|
6767
6564
|
*/
|
|
6768
|
-
function
|
|
6565
|
+
function hasAccess(user, tokenId) {
|
|
6769
6566
|
return __awaiter(this, void 0, void 0, function* () {
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
|
|
6773
|
-
|
|
6774
|
-
// If account is already set on the client, return it directly
|
|
6775
|
-
if (viemClient.account) {
|
|
6776
|
-
return viemClient.account.address;
|
|
6567
|
+
try {
|
|
6568
|
+
const expiryTimestamp = yield this.subscriptionExpiry(tokenId, user);
|
|
6569
|
+
const currentTimestamp = BigInt(Math.floor(Date.now() / 1000));
|
|
6570
|
+
return expiryTimestamp > currentTimestamp;
|
|
6777
6571
|
}
|
|
6778
|
-
|
|
6779
|
-
|
|
6780
|
-
method: "eth_requestAccounts",
|
|
6781
|
-
params: [],
|
|
6782
|
-
});
|
|
6783
|
-
if (!accounts || accounts.length === 0) {
|
|
6784
|
-
throw new WalletError("No accounts found in connected wallet. Please unlock your wallet or add an account.");
|
|
6572
|
+
catch (error) {
|
|
6573
|
+
return false;
|
|
6785
6574
|
}
|
|
6786
|
-
return accounts[0];
|
|
6787
6575
|
});
|
|
6788
6576
|
}
|
|
6789
6577
|
|
|
6578
|
+
function subscriptionExpiry(tokenId, user) {
|
|
6579
|
+
return this.callContractMethod(this.environment.MARKETPLACE_CONTRACT_ADDRESS, this.environment.MARKETPLACE_ABI, "subscriptionExpiry", [tokenId, user]);
|
|
6580
|
+
}
|
|
6581
|
+
|
|
6790
6582
|
/**
|
|
6791
6583
|
* Raises a dispute against an IP NFT.
|
|
6792
6584
|
* Automatically handles token approval for ERC20 bonds or native token value.
|
|
@@ -7013,13 +6805,17 @@ function encodeCidToBytes32(cid) {
|
|
|
7013
6805
|
// CIDv1: multibase 'b' prefix + base32-encoded (version + codec + multihash)
|
|
7014
6806
|
const decoded = base32Decode(cid.slice(1));
|
|
7015
6807
|
// CIDv1 structure: version (1 byte) + codec (varint) + multihash
|
|
6808
|
+
// For raw codec with sha2-256: 0x01 + 0x55 + 0x12 + 0x20 + 32-byte digest
|
|
7016
6809
|
// For dag-pb with sha2-256: 0x01 + 0x70 + 0x12 + 0x20 + 32-byte digest
|
|
7017
|
-
if (decoded[0] !== 0x01 ||
|
|
7018
|
-
|
|
7019
|
-
|
|
7020
|
-
|
|
7021
|
-
|
|
7022
|
-
throw new Error(
|
|
6810
|
+
if (decoded[0] !== 0x01 || decoded.length !== 36) {
|
|
6811
|
+
throw new Error("Invalid CIDv1: expected version 1 with 36 bytes");
|
|
6812
|
+
}
|
|
6813
|
+
const codec = decoded[1];
|
|
6814
|
+
if (codec !== 0x55 && codec !== 0x70) {
|
|
6815
|
+
throw new Error(`Invalid CIDv1: unsupported codec 0x${codec.toString(16)}`);
|
|
6816
|
+
}
|
|
6817
|
+
if (decoded[2] !== 0x12 || decoded[3] !== 0x20) {
|
|
6818
|
+
throw new Error("Invalid CIDv1: expected SHA-256 hash");
|
|
7023
6819
|
}
|
|
7024
6820
|
digest = decoded.slice(4);
|
|
7025
6821
|
}
|
|
@@ -7251,6 +7047,113 @@ function getDispute(disputeId) {
|
|
|
7251
7047
|
});
|
|
7252
7048
|
}
|
|
7253
7049
|
|
|
7050
|
+
/**
|
|
7051
|
+
* Resolves a wallet address from an optional address parameter or connected wallet.
|
|
7052
|
+
* Checks viemClient.account first, then falls back to eth_requestAccounts.
|
|
7053
|
+
*
|
|
7054
|
+
* @param viemClient The viem WalletClient instance.
|
|
7055
|
+
* @param address Optional address to use directly.
|
|
7056
|
+
* @returns The resolved wallet address.
|
|
7057
|
+
* @throws Error if no address provided and no wallet connected or no accounts found.
|
|
7058
|
+
*/
|
|
7059
|
+
function resolveWalletAddress(viemClient, address) {
|
|
7060
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
7061
|
+
if (address) {
|
|
7062
|
+
return address;
|
|
7063
|
+
}
|
|
7064
|
+
if (!viemClient) {
|
|
7065
|
+
throw new Error("No address provided and no wallet connected. Please provide an address or connect a wallet.");
|
|
7066
|
+
}
|
|
7067
|
+
if (viemClient.account) {
|
|
7068
|
+
return viemClient.account.address;
|
|
7069
|
+
}
|
|
7070
|
+
const accounts = yield viemClient.request({
|
|
7071
|
+
method: "eth_requestAccounts",
|
|
7072
|
+
params: [],
|
|
7073
|
+
});
|
|
7074
|
+
if (!accounts || accounts.length === 0) {
|
|
7075
|
+
throw new Error("No accounts found in connected wallet.");
|
|
7076
|
+
}
|
|
7077
|
+
return accounts[0];
|
|
7078
|
+
});
|
|
7079
|
+
}
|
|
7080
|
+
/**
|
|
7081
|
+
* Enum representing the type of license for an IP NFT.
|
|
7082
|
+
* - DURATION_BASED: License expires after a set duration (subscription model).
|
|
7083
|
+
* - SINGLE_PAYMENT: One-time payment for perpetual access.
|
|
7084
|
+
* - X402: HTTP 402-based micropayment license (no on-chain payments).
|
|
7085
|
+
*/
|
|
7086
|
+
var LicenseType;
|
|
7087
|
+
(function (LicenseType) {
|
|
7088
|
+
LicenseType[LicenseType["DURATION_BASED"] = 0] = "DURATION_BASED";
|
|
7089
|
+
LicenseType[LicenseType["SINGLE_PAYMENT"] = 1] = "SINGLE_PAYMENT";
|
|
7090
|
+
LicenseType[LicenseType["X402"] = 2] = "X402";
|
|
7091
|
+
})(LicenseType || (LicenseType = {}));
|
|
7092
|
+
/**
|
|
7093
|
+
* Enum representing the status of data in the system.
|
|
7094
|
+
* - ACTIVE: The data is currently active and available.
|
|
7095
|
+
* - DELETED: The data has been deleted and is no longer available.
|
|
7096
|
+
* - DISPUTED: The data has been disputed and marked as potentially infringing.
|
|
7097
|
+
*/
|
|
7098
|
+
var DataStatus;
|
|
7099
|
+
(function (DataStatus) {
|
|
7100
|
+
DataStatus[DataStatus["ACTIVE"] = 0] = "ACTIVE";
|
|
7101
|
+
DataStatus[DataStatus["DELETED"] = 1] = "DELETED";
|
|
7102
|
+
DataStatus[DataStatus["DISPUTED"] = 2] = "DISPUTED";
|
|
7103
|
+
})(DataStatus || (DataStatus = {}));
|
|
7104
|
+
/**
|
|
7105
|
+
* Enum representing the status of a dispute.
|
|
7106
|
+
* - Uninitialized: Dispute does not exist.
|
|
7107
|
+
* - Raised: Dispute has been raised but not yet asserted by IP owner.
|
|
7108
|
+
* - Asserted: IP owner has responded to the dispute.
|
|
7109
|
+
* - Resolved: Dispute has been resolved (either valid or invalid).
|
|
7110
|
+
* - Cancelled: Dispute was cancelled by the initiator.
|
|
7111
|
+
*/
|
|
7112
|
+
var DisputeStatus;
|
|
7113
|
+
(function (DisputeStatus) {
|
|
7114
|
+
DisputeStatus[DisputeStatus["Uninitialized"] = 0] = "Uninitialized";
|
|
7115
|
+
DisputeStatus[DisputeStatus["Raised"] = 1] = "Raised";
|
|
7116
|
+
DisputeStatus[DisputeStatus["Asserted"] = 2] = "Asserted";
|
|
7117
|
+
DisputeStatus[DisputeStatus["Resolved"] = 3] = "Resolved";
|
|
7118
|
+
DisputeStatus[DisputeStatus["Cancelled"] = 4] = "Cancelled";
|
|
7119
|
+
})(DisputeStatus || (DisputeStatus = {}));
|
|
7120
|
+
/**
|
|
7121
|
+
* Creates license terms for a digital asset.
|
|
7122
|
+
* @param price The price of the asset in wei.
|
|
7123
|
+
* @param duration The duration of the license in seconds (use 0 for SINGLE_PAYMENT and X402).
|
|
7124
|
+
* @param royaltyBps The royalty percentage in basis points (0-10000).
|
|
7125
|
+
* @param paymentToken The address of the payment token (ERC20 / address(0) for native currency).
|
|
7126
|
+
* @param licenseType The type of license (defaults to DURATION_BASED).
|
|
7127
|
+
* @returns The created license terms.
|
|
7128
|
+
*/
|
|
7129
|
+
const createLicenseTerms = (price, duration, royaltyBps, paymentToken, licenseType = LicenseType.DURATION_BASED) => {
|
|
7130
|
+
if (royaltyBps < constants.MIN_ROYALTY_BPS ||
|
|
7131
|
+
royaltyBps > constants.MAX_ROYALTY_BPS) {
|
|
7132
|
+
throw new Error(`Royalty basis points must be between ${constants.MIN_ROYALTY_BPS} and ${constants.MAX_ROYALTY_BPS}`);
|
|
7133
|
+
}
|
|
7134
|
+
if (licenseType === LicenseType.DURATION_BASED) {
|
|
7135
|
+
if (duration < constants.MIN_LICENSE_DURATION ||
|
|
7136
|
+
duration > constants.MAX_LICENSE_DURATION) {
|
|
7137
|
+
throw new Error(`Duration must be between ${constants.MIN_LICENSE_DURATION} and ${constants.MAX_LICENSE_DURATION} seconds for DURATION_BASED licenses`);
|
|
7138
|
+
}
|
|
7139
|
+
}
|
|
7140
|
+
else if ((licenseType === LicenseType.SINGLE_PAYMENT ||
|
|
7141
|
+
licenseType === LicenseType.X402) &&
|
|
7142
|
+
duration > 0) {
|
|
7143
|
+
throw new Error(`Duration must be 0 for ${LicenseType[licenseType]} licenses`);
|
|
7144
|
+
}
|
|
7145
|
+
if (price < constants.MIN_PRICE) {
|
|
7146
|
+
throw new Error(`Price must be at least ${constants.MIN_PRICE} wei`);
|
|
7147
|
+
}
|
|
7148
|
+
return {
|
|
7149
|
+
price,
|
|
7150
|
+
duration,
|
|
7151
|
+
royaltyBps,
|
|
7152
|
+
paymentToken,
|
|
7153
|
+
licenseType,
|
|
7154
|
+
};
|
|
7155
|
+
};
|
|
7156
|
+
|
|
7254
7157
|
// minimal ABI for staking vault
|
|
7255
7158
|
const STAKING_VAULT_ABI = [
|
|
7256
7159
|
{
|
|
@@ -8016,7 +7919,7 @@ function approveIfNeeded(_a) {
|
|
|
8016
7919
|
* ```
|
|
8017
7920
|
*/
|
|
8018
7921
|
function bulkBuyAccess(buyer, purchases, value) {
|
|
8019
|
-
return this.callContractMethod(this.environment.
|
|
7922
|
+
return this.callContractMethod(this.environment.BATCH_OPERATIONS_CONTRACT_ADDRESS, this.environment.BATCH_OPERATIONS_ABI, "bulkBuyAccess", [buyer, purchases], { waitForReceipt: true, value });
|
|
8020
7923
|
}
|
|
8021
7924
|
/**
|
|
8022
7925
|
* Executes a fault-tolerant bulk purchase of multiple IP-NFT licenses.
|
|
@@ -8036,7 +7939,7 @@ function bulkBuyAccess(buyer, purchases, value) {
|
|
|
8036
7939
|
* ```
|
|
8037
7940
|
*/
|
|
8038
7941
|
function bulkBuyAccessTolerant(buyer, purchases, value) {
|
|
8039
|
-
return this.callContractMethod(this.environment.
|
|
7942
|
+
return this.callContractMethod(this.environment.BATCH_OPERATIONS_CONTRACT_ADDRESS, this.environment.BATCH_OPERATIONS_ABI, "bulkBuyAccessTolerant", [buyer, purchases], { waitForReceipt: true, value });
|
|
8040
7943
|
}
|
|
8041
7944
|
/**
|
|
8042
7945
|
* Previews the total cost of purchasing multiple IP-NFT licenses.
|
|
@@ -8053,7 +7956,7 @@ function bulkBuyAccessTolerant(buyer, purchases, value) {
|
|
|
8053
7956
|
* ```
|
|
8054
7957
|
*/
|
|
8055
7958
|
function previewBulkCost(tokenIds) {
|
|
8056
|
-
return this.callContractMethod(this.environment.
|
|
7959
|
+
return this.callContractMethod(this.environment.BATCH_OPERATIONS_CONTRACT_ADDRESS, this.environment.BATCH_OPERATIONS_ABI, "previewBulkCost", [tokenIds]);
|
|
8057
7960
|
}
|
|
8058
7961
|
/**
|
|
8059
7962
|
* Builds purchase parameters for multiple tokens by fetching their current license terms.
|
|
@@ -8069,7 +7972,7 @@ function previewBulkCost(tokenIds) {
|
|
|
8069
7972
|
* ```
|
|
8070
7973
|
*/
|
|
8071
7974
|
function buildPurchaseParams(tokenIds) {
|
|
8072
|
-
return this.callContractMethod(this.environment.
|
|
7975
|
+
return this.callContractMethod(this.environment.BATCH_OPERATIONS_CONTRACT_ADDRESS, this.environment.BATCH_OPERATIONS_ABI, "buildPurchaseParams", [tokenIds]);
|
|
8073
7976
|
}
|
|
8074
7977
|
/**
|
|
8075
7978
|
* Checks the active status of multiple tokens.
|
|
@@ -8084,7 +7987,7 @@ function buildPurchaseParams(tokenIds) {
|
|
|
8084
7987
|
* ```
|
|
8085
7988
|
*/
|
|
8086
7989
|
function checkActiveStatus(tokenIds) {
|
|
8087
|
-
return this.callContractMethod(this.environment.
|
|
7990
|
+
return this.callContractMethod(this.environment.BATCH_OPERATIONS_CONTRACT_ADDRESS, this.environment.BATCH_OPERATIONS_ABI, "checkActiveStatus", [tokenIds]);
|
|
8088
7991
|
}
|
|
8089
7992
|
/**
|
|
8090
7993
|
* Smart bulk purchase that automatically fetches terms and handles the entire purchase flow.
|
|
@@ -8158,7 +8061,7 @@ function bulkBuyAccessSmart(tokenIds, options) {
|
|
|
8158
8061
|
publicClient,
|
|
8159
8062
|
tokenAddress: erc20.token,
|
|
8160
8063
|
owner: buyer,
|
|
8161
|
-
spender: this.environment.
|
|
8064
|
+
spender: this.environment.BATCH_OPERATIONS_CONTRACT_ADDRESS,
|
|
8162
8065
|
amount: erc20.amount,
|
|
8163
8066
|
chain: this.environment.CHAIN,
|
|
8164
8067
|
});
|
|
@@ -8173,6 +8076,53 @@ function bulkBuyAccessSmart(tokenIds, options) {
|
|
|
8173
8076
|
});
|
|
8174
8077
|
}
|
|
8175
8078
|
|
|
8079
|
+
/**
|
|
8080
|
+
* Executes an atomic bulk mint of multiple IP-NFTs.
|
|
8081
|
+
* All mints succeed or all fail together.
|
|
8082
|
+
*
|
|
8083
|
+
* @param mints Array of mint parameters for each token.
|
|
8084
|
+
* @returns A promise that resolves with the transaction result.
|
|
8085
|
+
*
|
|
8086
|
+
* @example
|
|
8087
|
+
* ```typescript
|
|
8088
|
+
* const mints = [
|
|
8089
|
+
* {
|
|
8090
|
+
* to: "0x...",
|
|
8091
|
+
* tokenId: 1n,
|
|
8092
|
+
* creatorContentHash: "0x...",
|
|
8093
|
+
* uri: "ipfs://...",
|
|
8094
|
+
* licenseTerms: { price: 1000n, duration: 86400, royaltyBps: 500, paymentToken: zeroAddress, licenseType: 0 },
|
|
8095
|
+
* deadline: BigInt(Date.now() + 600000),
|
|
8096
|
+
* parents: [],
|
|
8097
|
+
* isIP: true,
|
|
8098
|
+
* appId: "myApp",
|
|
8099
|
+
* signature: "0x...",
|
|
8100
|
+
* },
|
|
8101
|
+
* ];
|
|
8102
|
+
* await origin.bulkMint(mints);
|
|
8103
|
+
* ```
|
|
8104
|
+
*/
|
|
8105
|
+
function bulkMint(mints) {
|
|
8106
|
+
return this.callContractMethod(this.environment.BATCH_OPERATIONS_CONTRACT_ADDRESS, this.environment.BATCH_OPERATIONS_ABI, "bulkMint", [mints], { waitForReceipt: true });
|
|
8107
|
+
}
|
|
8108
|
+
/**
|
|
8109
|
+
* Executes a fault-tolerant bulk mint of multiple IP-NFTs.
|
|
8110
|
+
* Individual mints can fail without reverting the entire transaction.
|
|
8111
|
+
*
|
|
8112
|
+
* @param mints Array of mint parameters for each token.
|
|
8113
|
+
* @returns A promise that resolves with the tolerant mint result including success/failure counts.
|
|
8114
|
+
*
|
|
8115
|
+
* @example
|
|
8116
|
+
* ```typescript
|
|
8117
|
+
* const result = await origin.bulkMintTolerant(mints);
|
|
8118
|
+
* console.log(`Minted ${result.successCount} of ${mints.length} tokens`);
|
|
8119
|
+
* console.log(`Failed tokens: ${result.failedTokenIds}`);
|
|
8120
|
+
* ```
|
|
8121
|
+
*/
|
|
8122
|
+
function bulkMintTolerant(mints) {
|
|
8123
|
+
return this.callContractMethod(this.environment.BATCH_OPERATIONS_CONTRACT_ADDRESS, this.environment.BATCH_OPERATIONS_ABI, "bulkMintTolerant", [mints], { waitForReceipt: true });
|
|
8124
|
+
}
|
|
8125
|
+
|
|
8176
8126
|
var _Origin_instances, _Origin_generateURL, _Origin_setOriginStatus, _Origin_uploadToIPFS, _Origin_uploadFile, _Origin_waitForTxReceipt, _Origin_ensureChainId, _Origin_getCurrentAccount, _Origin_getProtocolFeeBps, _Origin_getAppFeeBpsForToken, _Origin_resolveWalletAddress;
|
|
8177
8127
|
/**
|
|
8178
8128
|
* The Origin class
|
|
@@ -8192,8 +8142,6 @@ class Origin {
|
|
|
8192
8142
|
typeof environment === "string"
|
|
8193
8143
|
? ENVIRONMENTS[environment]
|
|
8194
8144
|
: environment || ENVIRONMENTS["DEVELOPMENT"];
|
|
8195
|
-
this.environment.AUTH_HUB_BASE_API +=
|
|
8196
|
-
environment === "PRODUCTION" ? "/auth-mainnet" : "";
|
|
8197
8145
|
this.baseParentId = baseParentId;
|
|
8198
8146
|
this.appId = appId;
|
|
8199
8147
|
// DataNFT methods
|
|
@@ -8216,8 +8164,6 @@ class Origin {
|
|
|
8216
8164
|
this.buyAccess = buyAccess.bind(this);
|
|
8217
8165
|
this.hasAccess = hasAccess.bind(this);
|
|
8218
8166
|
this.subscriptionExpiry = subscriptionExpiry.bind(this);
|
|
8219
|
-
this.settlePaymentIntent = settlePaymentIntent.bind(this);
|
|
8220
|
-
this.getDataWithIntent = getDataWithIntent.bind(this);
|
|
8221
8167
|
// Bulk purchase methods
|
|
8222
8168
|
this.bulkBuyAccess = bulkBuyAccess.bind(this);
|
|
8223
8169
|
this.bulkBuyAccessTolerant = bulkBuyAccessTolerant.bind(this);
|
|
@@ -8225,6 +8171,9 @@ class Origin {
|
|
|
8225
8171
|
this.previewBulkCost = previewBulkCost.bind(this);
|
|
8226
8172
|
this.buildPurchaseParams = buildPurchaseParams.bind(this);
|
|
8227
8173
|
this.checkActiveStatus = checkActiveStatus.bind(this);
|
|
8174
|
+
// Bulk mint methods
|
|
8175
|
+
this.bulkMint = bulkMint.bind(this);
|
|
8176
|
+
this.bulkMintTolerant = bulkMintTolerant.bind(this);
|
|
8228
8177
|
// Dispute module methods
|
|
8229
8178
|
this.raiseDispute = raiseDispute.bind(this);
|
|
8230
8179
|
this.raiseDisputeSmart = raiseDisputeSmart.bind(this);
|
|
@@ -8378,6 +8327,152 @@ class Origin {
|
|
|
8378
8327
|
return tokenId.toString();
|
|
8379
8328
|
});
|
|
8380
8329
|
}
|
|
8330
|
+
/**
|
|
8331
|
+
* Mints multiple file-based IpNFTs in a single transaction using the BatchOperations contract.
|
|
8332
|
+
* Each file is uploaded and registered individually, then all mints are batched into one on-chain call.
|
|
8333
|
+
*
|
|
8334
|
+
* @param entries Array of file entries to mint, each containing a file, metadata, license terms, and optional parents/preview.
|
|
8335
|
+
* @param options Optional configuration including tolerant mode and progress callback.
|
|
8336
|
+
* @returns A promise that resolves with an array of token ID strings for each entry, and the transaction result.
|
|
8337
|
+
*
|
|
8338
|
+
* @example
|
|
8339
|
+
* ```typescript
|
|
8340
|
+
* const result = await origin.bulkMintFile([
|
|
8341
|
+
* { file: file1, metadata: { name: "Asset 1" }, license: myLicense },
|
|
8342
|
+
* { file: file2, metadata: { name: "Asset 2" }, license: myLicense },
|
|
8343
|
+
* ]);
|
|
8344
|
+
* console.log(`Minted token IDs: ${result.tokenIds}`);
|
|
8345
|
+
*
|
|
8346
|
+
* // Tolerant mode - continue even if some mints fail
|
|
8347
|
+
* const result = await origin.bulkMintFile(entries, { tolerant: true });
|
|
8348
|
+
* ```
|
|
8349
|
+
*/
|
|
8350
|
+
bulkMintFile(entries, options) {
|
|
8351
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
8352
|
+
var _a, _b;
|
|
8353
|
+
if (!entries || entries.length === 0) {
|
|
8354
|
+
throw new ValidationError("No file entries provided for bulk mint. Please provide at least one entry.");
|
|
8355
|
+
}
|
|
8356
|
+
let account = null;
|
|
8357
|
+
try {
|
|
8358
|
+
account = yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_getCurrentAccount).call(this);
|
|
8359
|
+
}
|
|
8360
|
+
catch (error) {
|
|
8361
|
+
throw new WalletError("Cannot bulk mint files: wallet not connected. Please connect a wallet first.");
|
|
8362
|
+
}
|
|
8363
|
+
const mintParams = [];
|
|
8364
|
+
const tokenIds = [];
|
|
8365
|
+
const uploadInfos = [];
|
|
8366
|
+
for (let i = 0; i < entries.length; i++) {
|
|
8367
|
+
const entry = entries[i];
|
|
8368
|
+
const { file, metadata, license } = entry;
|
|
8369
|
+
let { parents } = entry;
|
|
8370
|
+
// Upload file
|
|
8371
|
+
let info;
|
|
8372
|
+
try {
|
|
8373
|
+
info = yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_uploadFile).call(this, file, {
|
|
8374
|
+
progressCallback: (percent) => {
|
|
8375
|
+
var _a;
|
|
8376
|
+
(_a = options === null || options === void 0 ? void 0 : options.progressCallback) === null || _a === void 0 ? void 0 : _a.call(options, {
|
|
8377
|
+
fileIndex: i,
|
|
8378
|
+
fileCount: entries.length,
|
|
8379
|
+
stage: "uploading",
|
|
8380
|
+
percent,
|
|
8381
|
+
});
|
|
8382
|
+
},
|
|
8383
|
+
});
|
|
8384
|
+
if (!info || !info.key) {
|
|
8385
|
+
throw new APIError(`Failed to upload file "${file.name}": no upload info returned from server`);
|
|
8386
|
+
}
|
|
8387
|
+
}
|
|
8388
|
+
catch (error) {
|
|
8389
|
+
if (error instanceof APIError || error instanceof WalletError)
|
|
8390
|
+
throw error;
|
|
8391
|
+
throw new APIError(`Failed to upload file "${file.name}": ${getErrorMessage(error)}`);
|
|
8392
|
+
}
|
|
8393
|
+
uploadInfos.push(info);
|
|
8394
|
+
// Set mimetype
|
|
8395
|
+
if (file.type) {
|
|
8396
|
+
metadata.mimetype = file.type;
|
|
8397
|
+
}
|
|
8398
|
+
// Handle preview image
|
|
8399
|
+
let previewImageIpfsHash = null;
|
|
8400
|
+
if (entry.previewImage && entry.previewImage.type.startsWith("image/")) {
|
|
8401
|
+
previewImageIpfsHash = yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_uploadToIPFS).call(this, entry.previewImage);
|
|
8402
|
+
}
|
|
8403
|
+
else if (entry.useAssetAsPreview && file.type.startsWith("image/")) {
|
|
8404
|
+
previewImageIpfsHash = yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_uploadToIPFS).call(this, file);
|
|
8405
|
+
}
|
|
8406
|
+
if (previewImageIpfsHash) {
|
|
8407
|
+
metadata.image = `ipfs://${previewImageIpfsHash}`;
|
|
8408
|
+
}
|
|
8409
|
+
const deadline = BigInt(Date.now() + 600000); // 10 minutes from now
|
|
8410
|
+
// Prepare parents
|
|
8411
|
+
if (this.baseParentId) {
|
|
8412
|
+
if (!parents) {
|
|
8413
|
+
parents = [];
|
|
8414
|
+
}
|
|
8415
|
+
parents = [this.baseParentId, ...parents];
|
|
8416
|
+
}
|
|
8417
|
+
// Register IpNFT to get signature
|
|
8418
|
+
(_a = options === null || options === void 0 ? void 0 : options.progressCallback) === null || _a === void 0 ? void 0 : _a.call(options, {
|
|
8419
|
+
fileIndex: i,
|
|
8420
|
+
fileCount: entries.length,
|
|
8421
|
+
stage: "registering",
|
|
8422
|
+
percent: 100,
|
|
8423
|
+
});
|
|
8424
|
+
let registration;
|
|
8425
|
+
try {
|
|
8426
|
+
registration = yield this.registerIpNFT("file", deadline, license, metadata, true, // isIp
|
|
8427
|
+
info.key, // fileKey
|
|
8428
|
+
parents, this.appId);
|
|
8429
|
+
}
|
|
8430
|
+
catch (error) {
|
|
8431
|
+
yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_setOriginStatus).call(this, info.key, info.uploadId, []);
|
|
8432
|
+
throw new Error(`Failed to register IpNFT for file "${file.name}": ${error instanceof Error ? error.message : String(error)}`);
|
|
8433
|
+
}
|
|
8434
|
+
const { tokenId, creatorContentHash, signature, uri } = registration;
|
|
8435
|
+
if (!tokenId || !creatorContentHash || signature === undefined || !uri) {
|
|
8436
|
+
yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_setOriginStatus).call(this, info.key, info.uploadId, []);
|
|
8437
|
+
throw new Error(`Failed to register IpNFT for file "${file.name}": Missing required fields in registration response.`);
|
|
8438
|
+
}
|
|
8439
|
+
tokenIds.push(tokenId.toString());
|
|
8440
|
+
mintParams.push({
|
|
8441
|
+
to: account,
|
|
8442
|
+
tokenId: BigInt(tokenId),
|
|
8443
|
+
creatorContentHash: creatorContentHash,
|
|
8444
|
+
uri,
|
|
8445
|
+
licenseTerms: license,
|
|
8446
|
+
deadline,
|
|
8447
|
+
parents: parents || [],
|
|
8448
|
+
isIP: true,
|
|
8449
|
+
appId: (_b = this.appId) !== null && _b !== void 0 ? _b : "",
|
|
8450
|
+
signature: signature,
|
|
8451
|
+
});
|
|
8452
|
+
}
|
|
8453
|
+
// Execute bulk mint
|
|
8454
|
+
try {
|
|
8455
|
+
let result;
|
|
8456
|
+
if (options === null || options === void 0 ? void 0 : options.tolerant) {
|
|
8457
|
+
result = yield this.bulkMintTolerant(mintParams);
|
|
8458
|
+
}
|
|
8459
|
+
else {
|
|
8460
|
+
result = yield this.bulkMint(mintParams);
|
|
8461
|
+
}
|
|
8462
|
+
return { tokenIds, result };
|
|
8463
|
+
}
|
|
8464
|
+
catch (error) {
|
|
8465
|
+
// Mark all uploads as failed
|
|
8466
|
+
for (const info of uploadInfos) {
|
|
8467
|
+
try {
|
|
8468
|
+
yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_setOriginStatus).call(this, info.key, info.uploadId, []);
|
|
8469
|
+
}
|
|
8470
|
+
catch (_c) { }
|
|
8471
|
+
}
|
|
8472
|
+
throw new Error(`Bulk mint transaction failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
8473
|
+
}
|
|
8474
|
+
});
|
|
8475
|
+
}
|
|
8381
8476
|
/**
|
|
8382
8477
|
* Mints a social IpNFT.
|
|
8383
8478
|
* @param source The social media source (spotify, twitter, tiktok).
|
|
@@ -9115,6 +9210,179 @@ _Origin_instances = new WeakSet(), _Origin_generateURL = function _Origin_genera
|
|
|
9115
9210
|
});
|
|
9116
9211
|
};
|
|
9117
9212
|
|
|
9213
|
+
/**
|
|
9214
|
+
* Adapter for viem WalletClient
|
|
9215
|
+
*/
|
|
9216
|
+
class ViemSignerAdapter {
|
|
9217
|
+
constructor(signer) {
|
|
9218
|
+
this.type = "viem";
|
|
9219
|
+
this.signer = signer;
|
|
9220
|
+
}
|
|
9221
|
+
getAddress() {
|
|
9222
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
9223
|
+
if (this.signer.account) {
|
|
9224
|
+
return this.signer.account.address;
|
|
9225
|
+
}
|
|
9226
|
+
const accounts = yield this.signer.request({
|
|
9227
|
+
method: "eth_requestAccounts",
|
|
9228
|
+
params: [],
|
|
9229
|
+
});
|
|
9230
|
+
if (!accounts || accounts.length === 0) {
|
|
9231
|
+
throw new Error("No accounts found in viem wallet client");
|
|
9232
|
+
}
|
|
9233
|
+
return accounts[0];
|
|
9234
|
+
});
|
|
9235
|
+
}
|
|
9236
|
+
signMessage(message) {
|
|
9237
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
9238
|
+
const address = yield this.getAddress();
|
|
9239
|
+
return yield this.signer.signMessage({
|
|
9240
|
+
account: address,
|
|
9241
|
+
message,
|
|
9242
|
+
});
|
|
9243
|
+
});
|
|
9244
|
+
}
|
|
9245
|
+
signTypedData(domain, types, value) {
|
|
9246
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
9247
|
+
throw new Error("Viem WalletClient does not support signTypedData");
|
|
9248
|
+
});
|
|
9249
|
+
}
|
|
9250
|
+
getChainId() {
|
|
9251
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
9252
|
+
var _a;
|
|
9253
|
+
return ((_a = this.signer.chain) === null || _a === void 0 ? void 0 : _a.id) || 1;
|
|
9254
|
+
});
|
|
9255
|
+
}
|
|
9256
|
+
}
|
|
9257
|
+
/**
|
|
9258
|
+
* Adapter for ethers Signer (v5 and v6)
|
|
9259
|
+
*/
|
|
9260
|
+
class EthersSignerAdapter {
|
|
9261
|
+
constructor(signer) {
|
|
9262
|
+
this.type = "ethers";
|
|
9263
|
+
this.signer = signer;
|
|
9264
|
+
}
|
|
9265
|
+
getAddress() {
|
|
9266
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
9267
|
+
// Works for both ethers v5 and v6
|
|
9268
|
+
if (typeof this.signer.getAddress === "function") {
|
|
9269
|
+
return yield this.signer.getAddress();
|
|
9270
|
+
}
|
|
9271
|
+
if (this.signer.address) {
|
|
9272
|
+
return this.signer.address;
|
|
9273
|
+
}
|
|
9274
|
+
throw new Error("Unable to get address from ethers signer");
|
|
9275
|
+
});
|
|
9276
|
+
}
|
|
9277
|
+
signMessage(message) {
|
|
9278
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
9279
|
+
if (typeof this.signer.signMessage !== "function") {
|
|
9280
|
+
throw new Error("Signer does not support signMessage");
|
|
9281
|
+
}
|
|
9282
|
+
return yield this.signer.signMessage(message);
|
|
9283
|
+
});
|
|
9284
|
+
}
|
|
9285
|
+
signTypedData(domain, types, value) {
|
|
9286
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
9287
|
+
if (typeof this.signer._signTypedData === "function") {
|
|
9288
|
+
return yield this.signer._signTypedData(domain, types, value);
|
|
9289
|
+
}
|
|
9290
|
+
if (typeof this.signer.signTypedData !== "function") {
|
|
9291
|
+
throw new Error("Signer does not support signTypedData or _signTypedData");
|
|
9292
|
+
}
|
|
9293
|
+
return yield this.signer.signTypedData(domain, types, value);
|
|
9294
|
+
});
|
|
9295
|
+
}
|
|
9296
|
+
getChainId() {
|
|
9297
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
9298
|
+
// Try ethers v6 first
|
|
9299
|
+
if (this.signer.provider &&
|
|
9300
|
+
typeof this.signer.provider.getNetwork === "function") {
|
|
9301
|
+
const network = yield this.signer.provider.getNetwork();
|
|
9302
|
+
// ethers v6 returns bigint, v5 returns number
|
|
9303
|
+
return typeof network.chainId === "bigint"
|
|
9304
|
+
? Number(network.chainId)
|
|
9305
|
+
: network.chainId;
|
|
9306
|
+
}
|
|
9307
|
+
// Fallback for ethers v5
|
|
9308
|
+
if (typeof this.signer.getChainId === "function") {
|
|
9309
|
+
return yield this.signer.getChainId();
|
|
9310
|
+
}
|
|
9311
|
+
// Default to mainnet if we can't determine
|
|
9312
|
+
return 484;
|
|
9313
|
+
});
|
|
9314
|
+
}
|
|
9315
|
+
}
|
|
9316
|
+
/**
|
|
9317
|
+
* Adapter for custom signer implementations
|
|
9318
|
+
*/
|
|
9319
|
+
class CustomSignerAdapter {
|
|
9320
|
+
constructor(signer) {
|
|
9321
|
+
this.type = "custom";
|
|
9322
|
+
this.signer = signer;
|
|
9323
|
+
}
|
|
9324
|
+
getAddress() {
|
|
9325
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
9326
|
+
if (typeof this.signer.getAddress === "function") {
|
|
9327
|
+
return yield this.signer.getAddress();
|
|
9328
|
+
}
|
|
9329
|
+
if (this.signer.address) {
|
|
9330
|
+
return this.signer.address;
|
|
9331
|
+
}
|
|
9332
|
+
throw new Error("Custom signer must implement getAddress() or have address property");
|
|
9333
|
+
});
|
|
9334
|
+
}
|
|
9335
|
+
signMessage(message) {
|
|
9336
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
9337
|
+
if (typeof this.signer.signMessage !== "function") {
|
|
9338
|
+
throw new Error("Custom signer must implement signMessage()");
|
|
9339
|
+
}
|
|
9340
|
+
return yield this.signer.signMessage(message);
|
|
9341
|
+
});
|
|
9342
|
+
}
|
|
9343
|
+
signTypedData(domain, types, value) {
|
|
9344
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
9345
|
+
if (typeof this.signer.signTypedData !== "function") {
|
|
9346
|
+
throw new Error("Custom signer must implement signTypedData()");
|
|
9347
|
+
}
|
|
9348
|
+
return yield this.signer.signTypedData(domain, types, value);
|
|
9349
|
+
});
|
|
9350
|
+
}
|
|
9351
|
+
getChainId() {
|
|
9352
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
9353
|
+
if (typeof this.signer.getChainId === "function") {
|
|
9354
|
+
const chainId = yield this.signer.getChainId();
|
|
9355
|
+
return typeof chainId === "bigint" ? Number(chainId) : chainId;
|
|
9356
|
+
}
|
|
9357
|
+
if (this.signer.chainId !== undefined) {
|
|
9358
|
+
return typeof this.signer.chainId === "bigint"
|
|
9359
|
+
? Number(this.signer.chainId)
|
|
9360
|
+
: this.signer.chainId;
|
|
9361
|
+
}
|
|
9362
|
+
// Default to mainnet
|
|
9363
|
+
return 484;
|
|
9364
|
+
});
|
|
9365
|
+
}
|
|
9366
|
+
}
|
|
9367
|
+
/**
|
|
9368
|
+
* Factory function to create appropriate adapter based on signer type
|
|
9369
|
+
*/
|
|
9370
|
+
function createSignerAdapter(signer) {
|
|
9371
|
+
// Check for viem WalletClient
|
|
9372
|
+
if (signer.transport &&
|
|
9373
|
+
signer.chain &&
|
|
9374
|
+
typeof signer.signMessage === "function") {
|
|
9375
|
+
return new ViemSignerAdapter(signer);
|
|
9376
|
+
}
|
|
9377
|
+
// Check for ethers signer (v5 or v6)
|
|
9378
|
+
if (signer._isSigner ||
|
|
9379
|
+
(signer.provider && typeof signer.signMessage === "function")) {
|
|
9380
|
+
return new EthersSignerAdapter(signer);
|
|
9381
|
+
}
|
|
9382
|
+
// Try custom adapter
|
|
9383
|
+
return new CustomSignerAdapter(signer);
|
|
9384
|
+
}
|
|
9385
|
+
|
|
9118
9386
|
/**
|
|
9119
9387
|
* Browser localStorage adapter
|
|
9120
9388
|
*/
|
|
@@ -9229,8 +9497,6 @@ class Auth {
|
|
|
9229
9497
|
(__classPrivateFieldGet(this, _Auth_isNodeEnvironment, "f") ? new MemoryStorage() : new BrowserStorage()), "f");
|
|
9230
9498
|
this.viem = null;
|
|
9231
9499
|
this.environment = ENVIRONMENTS[environment];
|
|
9232
|
-
this.environment.AUTH_HUB_BASE_API +=
|
|
9233
|
-
environment === "PRODUCTION" ? "/auth-mainnet" : "";
|
|
9234
9500
|
this.baseParentId = baseParentId;
|
|
9235
9501
|
this.redirectUri = createRedirectUriObject(redirectUri);
|
|
9236
9502
|
this.clientId = clientId;
|