@campnetwork/origin 1.2.1 → 1.2.2

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.
@@ -203,12 +203,12 @@ declare class Origin {
203
203
  buyAccess: typeof buyAccess;
204
204
  hasAccess: typeof hasAccess;
205
205
  subscriptionExpiry: typeof subscriptionExpiry;
206
- private jwt;
206
+ private jwt?;
207
207
  environment: Environment;
208
208
  private viemClient?;
209
209
  baseParentId?: bigint;
210
- constructor(jwt: string, environment: Environment, viemClient?: WalletClient, baseParentId?: bigint);
211
- getJwt(): string;
210
+ constructor(environment: Environment | string, jwt?: string, viemClient?: WalletClient, baseParentId?: bigint);
211
+ getJwt(): string | undefined;
212
212
  setViemClient(client: WalletClient): void;
213
213
  mintFile(file: File, metadata: Record<string, unknown>, license: LicenseTerms, parents?: bigint[], options?: {
214
214
  progressCallback?: (percent: number) => void;
@@ -231,7 +231,21 @@ declare class Origin {
231
231
  * @returns {Promise<any>} The result of the buyAccess call.
232
232
  */
233
233
  buyAccessSmart(tokenId: bigint): Promise<any>;
234
+ /**
235
+ * Fetch the underlying data associated with a specific token ID.
236
+ * @param {bigint} tokenId - The token ID to fetch data for.
237
+ * @returns {Promise<any>} A promise that resolves with the fetched data.
238
+ * @throws {Error} Throws an error if the data cannot be fetched.
239
+ */
234
240
  getData(tokenId: bigint): Promise<any>;
241
+ /**
242
+ * Fetch data with X402 payment handling.
243
+ * @param {bigint} tokenId The token ID to fetch data for.
244
+ * @param {any} [signer] Optional signer object for signing the X402 intent.
245
+ * @returns {Promise<any>} A promise that resolves with the fetched data.
246
+ * @throws {Error} Throws an error if the data cannot be fetched or if no signer/wallet client is provided.
247
+ */
248
+ getDataWithX402(tokenId: bigint, signer?: any): Promise<any>;
235
249
  /**
236
250
  * Get the Token Bound Account (TBA) address for a specific token ID.
237
251
  * @param {bigint} tokenId - The token ID to get the TBA address for.
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import React, { createContext, useState, useContext, useEffect, useLayoutEffect, useRef, useSyncExternalStore } from 'react';
3
- import { custom, createWalletClient, createPublicClient, http, erc20Abi, getAbiItem, zeroAddress, formatEther, formatUnits, encodeFunctionData, checksumAddress, parseEther } from 'viem';
3
+ import { custom, createWalletClient, createPublicClient, http, erc20Abi, getAbiItem, checksumAddress, zeroAddress, formatEther, formatUnits, encodeFunctionData, keccak256, toBytes, parseEther } from 'viem';
4
4
  import { toAccount } from 'viem/accounts';
5
5
  import { createSiweMessage } from 'viem/siwe';
6
6
  import axios from 'axios';
@@ -3456,32 +3456,6 @@ function subscriptionExpiry(tokenId, user) {
3456
3456
  return this.callContractMethod(this.environment.MARKETPLACE_CONTRACT_ADDRESS, this.environment.MARKETPLACE_ABI, "subscriptionExpiry", [tokenId, user]);
3457
3457
  }
3458
3458
 
3459
- /**
3460
- * Approves a spender to spend a specified amount of tokens on behalf of the owner.
3461
- * If the current allowance is less than the specified amount, it will perform the approval.
3462
- * @param {ApproveParams} params - The parameters for the approval.
3463
- */
3464
- function approveIfNeeded(_a) {
3465
- return __awaiter(this, arguments, void 0, function* ({ walletClient, publicClient, tokenAddress, owner, spender, amount, }) {
3466
- const allowance = yield publicClient.readContract({
3467
- address: tokenAddress,
3468
- abi: erc20Abi,
3469
- functionName: "allowance",
3470
- args: [owner, spender],
3471
- });
3472
- if (allowance < amount) {
3473
- yield walletClient.writeContract({
3474
- address: tokenAddress,
3475
- account: owner,
3476
- abi: erc20Abi,
3477
- functionName: "approve",
3478
- args: [spender, amount],
3479
- chain: testnet,
3480
- });
3481
- }
3482
- });
3483
- }
3484
-
3485
3459
  /**
3486
3460
  * Enum representing the status of data in the system.
3487
3461
  * * - ACTIVE: The data is currently active and available.
@@ -3521,18 +3495,239 @@ const createLicenseTerms = (price, duration, royaltyBps, paymentToken) => {
3521
3495
  paymentToken,
3522
3496
  };
3523
3497
  };
3498
+ /**
3499
+ * Defines the EIP-712 typed data structure for X402 Intent signatures.
3500
+ */
3501
+ const X402_INTENT_TYPES = {
3502
+ X402Intent: [
3503
+ { name: "payer", type: "address" },
3504
+ { name: "asset", type: "address" },
3505
+ { name: "amount", type: "uint256" },
3506
+ { name: "httpMethod", type: "string" },
3507
+ { name: "payTo", type: "address" },
3508
+ { name: "tokenId", type: "uint256" },
3509
+ { name: "duration", type: "uint32" },
3510
+ { name: "expiresAt", type: "uint256" },
3511
+ { name: "nonce", type: "bytes32" },
3512
+ ],
3513
+ };
3514
+
3515
+ /**
3516
+ * Approves a spender to spend a specified amount of tokens on behalf of the owner.
3517
+ * If the current allowance is less than the specified amount, it will perform the approval.
3518
+ * @param {ApproveParams} params - The parameters for the approval.
3519
+ */
3520
+ function approveIfNeeded(_a) {
3521
+ return __awaiter(this, arguments, void 0, function* ({ walletClient, publicClient, tokenAddress, owner, spender, amount, }) {
3522
+ const allowance = yield publicClient.readContract({
3523
+ address: tokenAddress,
3524
+ abi: erc20Abi,
3525
+ functionName: "allowance",
3526
+ args: [owner, spender],
3527
+ });
3528
+ if (allowance < amount) {
3529
+ yield walletClient.writeContract({
3530
+ address: tokenAddress,
3531
+ account: owner,
3532
+ abi: erc20Abi,
3533
+ functionName: "approve",
3534
+ args: [spender, amount],
3535
+ chain: testnet,
3536
+ });
3537
+ }
3538
+ });
3539
+ }
3524
3540
 
3525
- var _Origin_instances, _Origin_generateURL, _Origin_setOriginStatus, _Origin_uploadFile, _Origin_waitForTxReceipt, _Origin_ensureChainId, _Origin_getCurrentAccount, _Origin_resolveWalletAddress;
3541
+ /**
3542
+ * Adapter for viem WalletClient
3543
+ */
3544
+ class ViemSignerAdapter {
3545
+ constructor(signer) {
3546
+ this.type = "viem";
3547
+ this.signer = signer;
3548
+ }
3549
+ getAddress() {
3550
+ return __awaiter(this, void 0, void 0, function* () {
3551
+ if (this.signer.account) {
3552
+ return this.signer.account.address;
3553
+ }
3554
+ const accounts = yield this.signer.request({
3555
+ method: "eth_requestAccounts",
3556
+ params: [],
3557
+ });
3558
+ if (!accounts || accounts.length === 0) {
3559
+ throw new Error("No accounts found in viem wallet client");
3560
+ }
3561
+ return accounts[0];
3562
+ });
3563
+ }
3564
+ signMessage(message) {
3565
+ return __awaiter(this, void 0, void 0, function* () {
3566
+ const address = yield this.getAddress();
3567
+ return yield this.signer.signMessage({
3568
+ account: address,
3569
+ message,
3570
+ });
3571
+ });
3572
+ }
3573
+ signTypedData(domain, types, value) {
3574
+ return __awaiter(this, void 0, void 0, function* () {
3575
+ throw new Error("Viem WalletClient does not support signTypedData");
3576
+ });
3577
+ }
3578
+ getChainId() {
3579
+ return __awaiter(this, void 0, void 0, function* () {
3580
+ var _a;
3581
+ return ((_a = this.signer.chain) === null || _a === void 0 ? void 0 : _a.id) || 1;
3582
+ });
3583
+ }
3584
+ }
3585
+ /**
3586
+ * Adapter for ethers Signer (v5 and v6)
3587
+ */
3588
+ class EthersSignerAdapter {
3589
+ constructor(signer) {
3590
+ this.type = "ethers";
3591
+ this.signer = signer;
3592
+ }
3593
+ getAddress() {
3594
+ return __awaiter(this, void 0, void 0, function* () {
3595
+ // Works for both ethers v5 and v6
3596
+ if (typeof this.signer.getAddress === "function") {
3597
+ return yield this.signer.getAddress();
3598
+ }
3599
+ if (this.signer.address) {
3600
+ return this.signer.address;
3601
+ }
3602
+ throw new Error("Unable to get address from ethers signer");
3603
+ });
3604
+ }
3605
+ signMessage(message) {
3606
+ return __awaiter(this, void 0, void 0, function* () {
3607
+ if (typeof this.signer.signMessage !== "function") {
3608
+ throw new Error("Signer does not support signMessage");
3609
+ }
3610
+ return yield this.signer.signMessage(message);
3611
+ });
3612
+ }
3613
+ signTypedData(domain, types, value) {
3614
+ return __awaiter(this, void 0, void 0, function* () {
3615
+ if (typeof this.signer._signTypedData === "function") {
3616
+ return yield this.signer._signTypedData(domain, types, value);
3617
+ }
3618
+ if (typeof this.signer.signTypedData !== "function") {
3619
+ throw new Error("Signer does not support signTypedData or _signTypedData");
3620
+ }
3621
+ return yield this.signer.signTypedData(domain, types, value);
3622
+ });
3623
+ }
3624
+ getChainId() {
3625
+ return __awaiter(this, void 0, void 0, function* () {
3626
+ // Try ethers v6 first
3627
+ if (this.signer.provider &&
3628
+ typeof this.signer.provider.getNetwork === "function") {
3629
+ const network = yield this.signer.provider.getNetwork();
3630
+ // ethers v6 returns bigint, v5 returns number
3631
+ return typeof network.chainId === "bigint"
3632
+ ? Number(network.chainId)
3633
+ : network.chainId;
3634
+ }
3635
+ // Fallback for ethers v5
3636
+ if (typeof this.signer.getChainId === "function") {
3637
+ return yield this.signer.getChainId();
3638
+ }
3639
+ // Default to mainnet if we can't determine
3640
+ return 484;
3641
+ });
3642
+ }
3643
+ }
3644
+ /**
3645
+ * Adapter for custom signer implementations
3646
+ */
3647
+ class CustomSignerAdapter {
3648
+ constructor(signer) {
3649
+ this.type = "custom";
3650
+ this.signer = signer;
3651
+ }
3652
+ getAddress() {
3653
+ return __awaiter(this, void 0, void 0, function* () {
3654
+ if (typeof this.signer.getAddress === "function") {
3655
+ return yield this.signer.getAddress();
3656
+ }
3657
+ if (this.signer.address) {
3658
+ return this.signer.address;
3659
+ }
3660
+ throw new Error("Custom signer must implement getAddress() or have address property");
3661
+ });
3662
+ }
3663
+ signMessage(message) {
3664
+ return __awaiter(this, void 0, void 0, function* () {
3665
+ if (typeof this.signer.signMessage !== "function") {
3666
+ throw new Error("Custom signer must implement signMessage()");
3667
+ }
3668
+ return yield this.signer.signMessage(message);
3669
+ });
3670
+ }
3671
+ signTypedData(domain, types, value) {
3672
+ return __awaiter(this, void 0, void 0, function* () {
3673
+ if (typeof this.signer.signTypedData !== "function") {
3674
+ throw new Error("Custom signer must implement signTypedData()");
3675
+ }
3676
+ return yield this.signer.signTypedData(domain, types, value);
3677
+ });
3678
+ }
3679
+ getChainId() {
3680
+ return __awaiter(this, void 0, void 0, function* () {
3681
+ if (typeof this.signer.getChainId === "function") {
3682
+ const chainId = yield this.signer.getChainId();
3683
+ return typeof chainId === "bigint" ? Number(chainId) : chainId;
3684
+ }
3685
+ if (this.signer.chainId !== undefined) {
3686
+ return typeof this.signer.chainId === "bigint"
3687
+ ? Number(this.signer.chainId)
3688
+ : this.signer.chainId;
3689
+ }
3690
+ // Default to mainnet
3691
+ return 484;
3692
+ });
3693
+ }
3694
+ }
3695
+ /**
3696
+ * Factory function to create appropriate adapter based on signer type
3697
+ */
3698
+ function createSignerAdapter(signer) {
3699
+ // Check for viem WalletClient
3700
+ if (signer.transport &&
3701
+ signer.chain &&
3702
+ typeof signer.signMessage === "function") {
3703
+ return new ViemSignerAdapter(signer);
3704
+ }
3705
+ // Check for ethers signer (v5 or v6)
3706
+ if (signer._isSigner ||
3707
+ (signer.provider && typeof signer.signMessage === "function")) {
3708
+ return new EthersSignerAdapter(signer);
3709
+ }
3710
+ // Try custom adapter
3711
+ return new CustomSignerAdapter(signer);
3712
+ }
3713
+
3714
+ var _Origin_instances, _Origin_generateURL, _Origin_setOriginStatus, _Origin_uploadFile, _Origin_waitForTxReceipt, _Origin_ensureChainId, _Origin_getCurrentAccount, _Origin_makeX402IntentDomain, _Origin_buildX402Payload, _Origin_resolveWalletAddress;
3526
3715
  /**
3527
3716
  * The Origin class
3528
3717
  * Handles the upload of files to Origin, as well as querying the user's stats
3529
3718
  */
3530
3719
  class Origin {
3531
- constructor(jwt, environment, viemClient, baseParentId) {
3720
+ constructor(environment, jwt, viemClient, baseParentId) {
3532
3721
  _Origin_instances.add(this);
3533
- this.jwt = jwt;
3722
+ if (jwt) {
3723
+ this.jwt = jwt;
3724
+ }
3725
+ else {
3726
+ console.warn("JWT not provided. Some features may be unavailable.");
3727
+ }
3534
3728
  this.viemClient = viemClient;
3535
- this.environment = environment;
3729
+ this.environment =
3730
+ typeof environment === "string" ? ENVIRONMENTS[environment] : environment;
3536
3731
  this.baseParentId = baseParentId;
3537
3732
  // DataNFT methods
3538
3733
  this.mintWithSignature = mintWithSignature.bind(this);
@@ -3764,6 +3959,12 @@ class Origin {
3764
3959
  return this.buyAccess(account, tokenId, totalCost, duration, paymentToken);
3765
3960
  });
3766
3961
  }
3962
+ /**
3963
+ * Fetch the underlying data associated with a specific token ID.
3964
+ * @param {bigint} tokenId - The token ID to fetch data for.
3965
+ * @returns {Promise<any>} A promise that resolves with the fetched data.
3966
+ * @throws {Error} Throws an error if the data cannot be fetched.
3967
+ */
3767
3968
  getData(tokenId) {
3768
3969
  return __awaiter(this, void 0, void 0, function* () {
3769
3970
  const response = yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/data/${tokenId}`, {
@@ -3779,6 +3980,60 @@ class Origin {
3779
3980
  return response.json();
3780
3981
  });
3781
3982
  }
3983
+ /**
3984
+ * Fetch data with X402 payment handling.
3985
+ * @param {bigint} tokenId The token ID to fetch data for.
3986
+ * @param {any} [signer] Optional signer object for signing the X402 intent.
3987
+ * @returns {Promise<any>} A promise that resolves with the fetched data.
3988
+ * @throws {Error} Throws an error if the data cannot be fetched or if no signer/wallet client is provided.
3989
+ */
3990
+ getDataWithX402(tokenId, signer) {
3991
+ return __awaiter(this, void 0, void 0, function* () {
3992
+ var _a;
3993
+ if (!signer && !this.viemClient) {
3994
+ throw new Error("No signer or wallet client provided for X402 intent.");
3995
+ }
3996
+ const initialResponse = yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/data/${tokenId}`, {
3997
+ method: "GET",
3998
+ });
3999
+ if (initialResponse.status !== 402) {
4000
+ if (!initialResponse.ok) {
4001
+ throw new Error("Failed to fetch data");
4002
+ }
4003
+ return initialResponse.json();
4004
+ }
4005
+ const sig = this.viemClient || createSignerAdapter(signer);
4006
+ const walletAddress = this.viemClient
4007
+ ? yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_getCurrentAccount).call(this)
4008
+ : yield sig.getAddress();
4009
+ const intentData = yield initialResponse.json();
4010
+ if (intentData.error) {
4011
+ throw new Error(intentData.error);
4012
+ }
4013
+ const requirements = intentData.accepts[0];
4014
+ const x402Payload = yield __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_buildX402Payload).call(this, requirements, checksumAddress(walletAddress), sig);
4015
+ const header = btoa(JSON.stringify(x402Payload));
4016
+ const retryResponse = yield fetch(`${this.environment.AUTH_HUB_BASE_API}/${this.environment.AUTH_ENDPOINT}/origin/data/${tokenId}`, {
4017
+ method: "GET",
4018
+ headers: {
4019
+ "Content-Type": "application/json",
4020
+ "X-PAYMENT": header,
4021
+ },
4022
+ });
4023
+ if (retryResponse.status === 402) {
4024
+ // subscription required
4025
+ return retryResponse.json();
4026
+ }
4027
+ if (!retryResponse.ok) {
4028
+ throw new Error("Failed to fetch data after X402 payment");
4029
+ }
4030
+ const res = yield retryResponse.json();
4031
+ return {
4032
+ error: null,
4033
+ data: (_a = res.data) !== null && _a !== void 0 ? _a : res,
4034
+ };
4035
+ });
4036
+ }
3782
4037
  /**
3783
4038
  * Get the Token Bound Account (TBA) address for a specific token ID.
3784
4039
  * @param {bigint} tokenId - The token ID to get the TBA address for.
@@ -4114,6 +4369,47 @@ _Origin_instances = new WeakSet(), _Origin_generateURL = function _Origin_genera
4114
4369
  }
4115
4370
  return accounts[0];
4116
4371
  });
4372
+ }, _Origin_makeX402IntentDomain = function _Origin_makeX402IntentDomain() {
4373
+ return {
4374
+ name: "Origin X402 Intent",
4375
+ version: "1",
4376
+ chainId: this.environment.CHAIN.id,
4377
+ verifyingContract: this.environment
4378
+ .MARKETPLACE_CONTRACT_ADDRESS,
4379
+ };
4380
+ }, _Origin_buildX402Payload = function _Origin_buildX402Payload(requirements, payer, signer) {
4381
+ return __awaiter(this, void 0, void 0, function* () {
4382
+ const asset = requirements.asset === "native" ? zeroAddress : requirements.asset;
4383
+ const amount = BigInt(requirements.maxAmountRequired || 0);
4384
+ const duration = requirements.extra.duration;
4385
+ const domain = __classPrivateFieldGet(this, _Origin_instances, "m", _Origin_makeX402IntentDomain).call(this);
4386
+ const types = X402_INTENT_TYPES;
4387
+ const nonce = crypto.randomUUID();
4388
+ const nonceBytes32 = keccak256(toBytes(nonce));
4389
+ const payment = {
4390
+ payer: payer,
4391
+ asset: asset,
4392
+ amount: amount.toString(),
4393
+ httpMethod: "GET",
4394
+ payTo: checksumAddress(this.environment.MARKETPLACE_CONTRACT_ADDRESS),
4395
+ tokenId: requirements.extra.tokenId,
4396
+ duration: duration,
4397
+ expiresAt: Math.floor(Date.now() / 1000) + requirements.maxTimeoutSeconds,
4398
+ nonce: nonceBytes32,
4399
+ };
4400
+ const signerAdapter = createSignerAdapter(signer);
4401
+ const signature = yield signerAdapter.signTypedData(domain, types, payment);
4402
+ const x402Payload = {
4403
+ x402Version: 1,
4404
+ scheme: "exact",
4405
+ network: requirements.network,
4406
+ payload: Object.assign(Object.assign({}, payment), { sigType: "eip712", signature: signature, license: {
4407
+ tokenId: requirements.extra.tokenId,
4408
+ duration: duration,
4409
+ } }),
4410
+ };
4411
+ return x402Payload;
4412
+ });
4117
4413
  }, _Origin_resolveWalletAddress = function _Origin_resolveWalletAddress(owner) {
4118
4414
  return __awaiter(this, void 0, void 0, function* () {
4119
4415
  if (owner) {
@@ -4138,155 +4434,6 @@ _Origin_instances = new WeakSet(), _Origin_generateURL = function _Origin_genera
4138
4434
  });
4139
4435
  };
4140
4436
 
4141
- /**
4142
- * Adapter for viem WalletClient
4143
- */
4144
- class ViemSignerAdapter {
4145
- constructor(signer) {
4146
- this.type = "viem";
4147
- this.signer = signer;
4148
- }
4149
- getAddress() {
4150
- return __awaiter(this, void 0, void 0, function* () {
4151
- if (this.signer.account) {
4152
- return this.signer.account.address;
4153
- }
4154
- const accounts = yield this.signer.request({
4155
- method: "eth_requestAccounts",
4156
- params: [],
4157
- });
4158
- if (!accounts || accounts.length === 0) {
4159
- throw new Error("No accounts found in viem wallet client");
4160
- }
4161
- return accounts[0];
4162
- });
4163
- }
4164
- signMessage(message) {
4165
- return __awaiter(this, void 0, void 0, function* () {
4166
- const address = yield this.getAddress();
4167
- return yield this.signer.signMessage({
4168
- account: address,
4169
- message,
4170
- });
4171
- });
4172
- }
4173
- getChainId() {
4174
- return __awaiter(this, void 0, void 0, function* () {
4175
- var _a;
4176
- return ((_a = this.signer.chain) === null || _a === void 0 ? void 0 : _a.id) || 1;
4177
- });
4178
- }
4179
- }
4180
- /**
4181
- * Adapter for ethers Signer (v5 and v6)
4182
- */
4183
- class EthersSignerAdapter {
4184
- constructor(signer) {
4185
- this.type = "ethers";
4186
- this.signer = signer;
4187
- }
4188
- getAddress() {
4189
- return __awaiter(this, void 0, void 0, function* () {
4190
- // Works for both ethers v5 and v6
4191
- if (typeof this.signer.getAddress === "function") {
4192
- return yield this.signer.getAddress();
4193
- }
4194
- if (this.signer.address) {
4195
- return this.signer.address;
4196
- }
4197
- throw new Error("Unable to get address from ethers signer");
4198
- });
4199
- }
4200
- signMessage(message) {
4201
- return __awaiter(this, void 0, void 0, function* () {
4202
- if (typeof this.signer.signMessage !== "function") {
4203
- throw new Error("Signer does not support signMessage");
4204
- }
4205
- return yield this.signer.signMessage(message);
4206
- });
4207
- }
4208
- getChainId() {
4209
- return __awaiter(this, void 0, void 0, function* () {
4210
- // Try ethers v6 first
4211
- if (this.signer.provider &&
4212
- typeof this.signer.provider.getNetwork === "function") {
4213
- const network = yield this.signer.provider.getNetwork();
4214
- // ethers v6 returns bigint, v5 returns number
4215
- return typeof network.chainId === "bigint"
4216
- ? Number(network.chainId)
4217
- : network.chainId;
4218
- }
4219
- // Fallback for ethers v5
4220
- if (typeof this.signer.getChainId === "function") {
4221
- return yield this.signer.getChainId();
4222
- }
4223
- // Default to mainnet if we can't determine
4224
- return 484;
4225
- });
4226
- }
4227
- }
4228
- /**
4229
- * Adapter for custom signer implementations
4230
- */
4231
- class CustomSignerAdapter {
4232
- constructor(signer) {
4233
- this.type = "custom";
4234
- this.signer = signer;
4235
- }
4236
- getAddress() {
4237
- return __awaiter(this, void 0, void 0, function* () {
4238
- if (typeof this.signer.getAddress === "function") {
4239
- return yield this.signer.getAddress();
4240
- }
4241
- if (this.signer.address) {
4242
- return this.signer.address;
4243
- }
4244
- throw new Error("Custom signer must implement getAddress() or have address property");
4245
- });
4246
- }
4247
- signMessage(message) {
4248
- return __awaiter(this, void 0, void 0, function* () {
4249
- if (typeof this.signer.signMessage !== "function") {
4250
- throw new Error("Custom signer must implement signMessage()");
4251
- }
4252
- return yield this.signer.signMessage(message);
4253
- });
4254
- }
4255
- getChainId() {
4256
- return __awaiter(this, void 0, void 0, function* () {
4257
- if (typeof this.signer.getChainId === "function") {
4258
- const chainId = yield this.signer.getChainId();
4259
- return typeof chainId === "bigint" ? Number(chainId) : chainId;
4260
- }
4261
- if (this.signer.chainId !== undefined) {
4262
- return typeof this.signer.chainId === "bigint"
4263
- ? Number(this.signer.chainId)
4264
- : this.signer.chainId;
4265
- }
4266
- // Default to mainnet
4267
- return 484;
4268
- });
4269
- }
4270
- }
4271
- /**
4272
- * Factory function to create appropriate adapter based on signer type
4273
- */
4274
- function createSignerAdapter(signer) {
4275
- // Check for viem WalletClient
4276
- if (signer.transport &&
4277
- signer.chain &&
4278
- typeof signer.signMessage === "function") {
4279
- return new ViemSignerAdapter(signer);
4280
- }
4281
- // Check for ethers signer (v5 or v6)
4282
- if (signer._isSigner ||
4283
- (signer.provider && typeof signer.signMessage === "function")) {
4284
- return new EthersSignerAdapter(signer);
4285
- }
4286
- // Try custom adapter
4287
- return new CustomSignerAdapter(signer);
4288
- }
4289
-
4290
4437
  /**
4291
4438
  * Browser localStorage adapter
4292
4439
  */
@@ -4629,7 +4776,7 @@ class Auth {
4629
4776
  this.isAuthenticated = true;
4630
4777
  this.userId = res.userId;
4631
4778
  this.jwt = res.token;
4632
- this.origin = new Origin(this.jwt, this.environment, this.viem, this.baseParentId);
4779
+ this.origin = new Origin(this.environment, this.jwt, this.viem, this.baseParentId);
4633
4780
  yield __classPrivateFieldGet(this, _Auth_storage, "f").setItem("camp-sdk:jwt", this.jwt);
4634
4781
  yield __classPrivateFieldGet(this, _Auth_storage, "f").setItem("camp-sdk:wallet-address", this.walletAddress);
4635
4782
  yield __classPrivateFieldGet(this, _Auth_storage, "f").setItem("camp-sdk:user-id", this.userId);
@@ -4691,7 +4838,7 @@ class Auth {
4691
4838
  this.isAuthenticated = true;
4692
4839
  this.userId = res.userId;
4693
4840
  this.jwt = res.token;
4694
- this.origin = new Origin(this.jwt, this.environment, this.viem, this.baseParentId);
4841
+ this.origin = new Origin(this.environment, this.jwt, this.viem, this.baseParentId);
4695
4842
  yield __classPrivateFieldGet(this, _Auth_storage, "f").setItem("camp-sdk:jwt", this.jwt);
4696
4843
  yield __classPrivateFieldGet(this, _Auth_storage, "f").setItem("camp-sdk:wallet-address", this.walletAddress);
4697
4844
  yield __classPrivateFieldGet(this, _Auth_storage, "f").setItem("camp-sdk:user-id", this.userId);
@@ -5080,7 +5227,7 @@ _Auth_triggers = new WeakMap(), _Auth_isNodeEnvironment = new WeakMap(), _Auth_s
5080
5227
  this.walletAddress = walletAddress;
5081
5228
  this.userId = userId;
5082
5229
  this.jwt = jwt;
5083
- this.origin = new Origin(this.jwt, this.environment, this.viem, this.baseParentId);
5230
+ this.origin = new Origin(this.environment, this.jwt, this.viem, this.baseParentId);
5084
5231
  this.isAuthenticated = true;
5085
5232
  if (provider) {
5086
5233
  this.setProvider({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@campnetwork/origin",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "main": "dist/core.cjs",
5
5
  "exports": {
6
6
  ".": {