privately-smartcontract-lib 1.1.1 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.d.ts CHANGED
@@ -1,6 +1,16 @@
1
1
  import { Block, Signer, TransactionResponse } from "ethers";
2
2
  import { PrivatelyAuctionSystemClient } from "./modules/auctions";
3
3
  import { PrivatelyCollectionClient } from "./modules/collection";
4
+ /**
5
+ * Options for creating a PrivatelyClient instance.
6
+ * Use these to override default contract addresses (e.g., for testnet/mainnet).
7
+ */
8
+ export interface PrivatelyClientOptions {
9
+ /** Override the collection contract address */
10
+ collectionAddress?: string;
11
+ /** Override the auction contract address */
12
+ auctionAddress?: string;
13
+ }
4
14
  export declare class PrivatelyClient {
5
15
  readonly signer: Signer;
6
16
  readonly collection: PrivatelyCollectionClient;
@@ -9,9 +19,10 @@ export declare class PrivatelyClient {
9
19
  /**
10
20
  * Creates a new PrivatelyClient instance using the provided signer.
11
21
  * @param signer The signer to use for transactions.
22
+ * @param options Optional configuration for contract addresses.
12
23
  * @returns A new PrivatelyClient instance.
13
24
  */
14
- static create(signer: Signer): Promise<PrivatelyClient>;
25
+ static create(signer: Signer, options?: PrivatelyClientOptions): Promise<PrivatelyClient>;
15
26
  /**
16
27
  * Fetches the latest block from the connected provider.
17
28
  * @returns The latest block.
package/dist/client.js CHANGED
@@ -8,21 +8,22 @@ class PrivatelyClient {
8
8
  signer;
9
9
  collection;
10
10
  auctions;
11
- constructor(signer, network) {
11
+ constructor(signer, network, options) {
12
12
  this.signer = signer;
13
- this.collection = new collection_1.PrivatelyCollectionClient(signer, network);
14
- this.auctions = new auctions_1.PrivatelyAuctionSystemClient(signer, network);
13
+ this.collection = new collection_1.PrivatelyCollectionClient(signer, network, options?.collectionAddress);
14
+ this.auctions = new auctions_1.PrivatelyAuctionSystemClient(signer, network, options?.auctionAddress);
15
15
  }
16
16
  /**
17
17
  * Creates a new PrivatelyClient instance using the provided signer.
18
18
  * @param signer The signer to use for transactions.
19
+ * @param options Optional configuration for contract addresses.
19
20
  * @returns A new PrivatelyClient instance.
20
21
  */
21
- static async create(signer) {
22
+ static async create(signer, options) {
22
23
  if (!signer.provider)
23
24
  throw new Error("Signer must be connected to a provider.");
24
25
  const network = await signer.provider.getNetwork();
25
- return new PrivatelyClient(signer, network);
26
+ return new PrivatelyClient(signer, network, options);
26
27
  }
27
28
  /**
28
29
  * Fetches the latest block from the connected provider.
@@ -1,11 +1,10 @@
1
1
  export declare enum RequestType {
2
2
  AUCTION_CREATE = "AUCTION_CREATE",
3
3
  AUCTION_BID = "AUCTION_BID",
4
- COIN_TRANSFER = "COIN_TRANSFER",
5
- COIN_APPROVE = "COIN_APPROVE",
6
4
  COLLECTION_MINT = "COLLECTION_MINT",
7
5
  COLLECTION_TRANSFER = "COLLECTION_TRANSFER",
8
- COLLECTION_APPROVE = "COLLECTION_APPROVE"
6
+ COLLECTION_APPROVE = "COLLECTION_APPROVE",
7
+ COLLECTION_SET_TOKEN_URI = "COLLECTION_SET_TOKEN_URI"
9
8
  }
10
9
  export declare class RequestSignature<T> {
11
10
  readonly type: RequestType;
@@ -6,13 +6,11 @@ var RequestType;
6
6
  // Auctions requests types
7
7
  RequestType["AUCTION_CREATE"] = "AUCTION_CREATE";
8
8
  RequestType["AUCTION_BID"] = "AUCTION_BID";
9
- // Coin requests types
10
- RequestType["COIN_TRANSFER"] = "COIN_TRANSFER";
11
- RequestType["COIN_APPROVE"] = "COIN_APPROVE";
12
9
  // Collection requests types
13
10
  RequestType["COLLECTION_MINT"] = "COLLECTION_MINT";
14
11
  RequestType["COLLECTION_TRANSFER"] = "COLLECTION_TRANSFER";
15
12
  RequestType["COLLECTION_APPROVE"] = "COLLECTION_APPROVE";
13
+ RequestType["COLLECTION_SET_TOKEN_URI"] = "COLLECTION_SET_TOKEN_URI";
16
14
  })(RequestType || (exports.RequestType = RequestType = {}));
17
15
  class RequestSignature {
18
16
  type;
@@ -4,11 +4,14 @@ import { Auction } from "./auctions.auction";
4
4
  import { BidAuctionRequest } from "./auctions.bid.reqest";
5
5
  import { CreateAuctionRequest } from "./auctions.create.request";
6
6
  import { OnBidListener, OnCreateListener, OnEnd, OnWithdrawListener } from "./auctions.events";
7
+ /** Default address for local Hardhat deployment */
8
+ export declare const DEFAULT_AUCTION_ADDRESS = "0x9fe46736679d2d9a65f0992f2272de9f3c7fa6e0";
7
9
  export declare class PrivatelyAuctionSystemClient {
8
10
  readonly contract: Contract;
11
+ readonly address: string;
9
12
  private readonly signer;
10
13
  private readonly domain;
11
- constructor(signer: Signer, network: Network);
14
+ constructor(signer: Signer, network: Network, address?: string);
12
15
  /**
13
16
  * Retrieves the address of the current deployed contract.
14
17
  * @returns The contract address.
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.PrivatelyAuctionSystemClient = void 0;
6
+ exports.PrivatelyAuctionSystemClient = exports.DEFAULT_AUCTION_ADDRESS = void 0;
7
7
  const ethers_1 = require("ethers");
8
8
  const PrivatelyAuctionSystem_json_1 = __importDefault(require("../../../PrivatelyAuctionSystem.json"));
9
9
  const request_signature_1 = require("../../common/request-signature");
@@ -11,20 +11,23 @@ const auctions_auction_1 = require("./auctions.auction");
11
11
  const auctions_bid_reqest_1 = require("./auctions.bid.reqest");
12
12
  const auctions_create_request_1 = require("./auctions.create.request");
13
13
  const auctions_errors_1 = require("./auctions.errors");
14
- const AUCTION_SYSTEM_ADDRESS = "0x9fe46736679d2d9a65f0992f2272de9f3c7fa6e0";
14
+ /** Default address for local Hardhat deployment */
15
+ exports.DEFAULT_AUCTION_ADDRESS = "0x9fe46736679d2d9a65f0992f2272de9f3c7fa6e0";
15
16
  class PrivatelyAuctionSystemClient {
16
17
  contract;
18
+ address;
17
19
  signer;
18
20
  domain;
19
- constructor(signer, network) {
21
+ constructor(signer, network, address = exports.DEFAULT_AUCTION_ADDRESS) {
20
22
  this.signer = signer;
21
- this.contract = new ethers_1.Contract(AUCTION_SYSTEM_ADDRESS, PrivatelyAuctionSystem_json_1.default.abi, signer);
23
+ this.address = address;
24
+ this.contract = new ethers_1.Contract(address, PrivatelyAuctionSystem_json_1.default.abi, signer);
22
25
  const name = PrivatelyAuctionSystem_json_1.default.contractName;
23
26
  this.domain = {
24
27
  name,
25
28
  version: "1.0.0",
26
29
  chainId: network.chainId,
27
- verifyingContract: AUCTION_SYSTEM_ADDRESS
30
+ verifyingContract: address
28
31
  };
29
32
  }
30
33
  /**
@@ -32,7 +35,7 @@ class PrivatelyAuctionSystemClient {
32
35
  * @returns The contract address.
33
36
  */
34
37
  getContractAddress() {
35
- return AUCTION_SYSTEM_ADDRESS;
38
+ return this.address;
36
39
  }
37
40
  /**
38
41
  * Creates and signs a CreateAuctionRequest using EIP-712 structured data.
@@ -4,12 +4,16 @@ import { CollectionApproveRequest } from "./collection.approve.request";
4
4
  import { OnMintListener, OnTransferListener } from "./collection.events";
5
5
  import { CollectionMintRequest } from "./collection.mint.request";
6
6
  import { PrivatelyNFT } from "./collection.nft";
7
+ import { CollectionSetTokenURIRequest } from "./collection.settokenuri.request";
7
8
  import { CollectionTransferRequest } from "./collection.transfer.request";
9
+ /** Default address for local Hardhat deployment */
10
+ export declare const DEFAULT_COLLECTION_ADDRESS = "0xe7f1725e7734ce288f8367e1bb143e90bb3f0512";
8
11
  export declare class PrivatelyCollectionClient {
9
12
  readonly contract: Contract;
13
+ readonly address: string;
10
14
  private readonly signer;
11
15
  private readonly domain;
12
- constructor(signer: Signer, network: Network);
16
+ constructor(signer: Signer, network: Network, address?: string);
13
17
  /**
14
18
  * Retrieves a list of all NFT token IDs currently stored in the contract.
15
19
  * @returns An array of token IDs as bigint.
@@ -79,6 +83,28 @@ export declare class PrivatelyCollectionClient {
79
83
  * @returns A TransactionResponse object from ethers.
80
84
  */
81
85
  relayApproveRequest(request: CollectionApproveRequest, signature: string): Promise<TransactionResponse>;
86
+ /**
87
+ * Creates a signed request to update the token URI for an NFT.
88
+ * This allows the owner to update the NFT's metadata URI via meta-transaction.
89
+ * @param tokenId The ID of the NFT to update.
90
+ * @param tokenURI The new metadata URI.
91
+ * @returns A RequestSignature containing the SetTokenURIRequest and signature.
92
+ */
93
+ createSetTokenURIRequest(tokenId: bigint, tokenURI: string): Promise<RequestSignature<CollectionSetTokenURIRequest>>;
94
+ /**
95
+ * Relays a signed setTokenURI request to the blockchain.
96
+ * The relayer (caller of this function) is responsible for the transaction's gas cost.
97
+ * @param request The SetTokenURIRequest object containing owner, tokenId, tokenURI, and nonce.
98
+ * @param signature The EIP-712 signature that authorizes this update.
99
+ * @returns A TransactionResponse object from ethers.
100
+ */
101
+ relaySetTokenURIRequest(request: CollectionSetTokenURIRequest, signature: string): Promise<TransactionResponse>;
102
+ /**
103
+ * Retrieves the token URI for a given NFT.
104
+ * @param tokenId The ID of the NFT.
105
+ * @returns The metadata URI string.
106
+ */
107
+ getTokenURI(tokenId: bigint): Promise<string>;
82
108
  /**
83
109
  * Registers a listener for the "OnMint" event emitted by the contract when a new NFT is minted.
84
110
  * @param listener A callback function to be executed when the "OnMint" event is triggered.
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.PrivatelyCollectionClient = void 0;
6
+ exports.PrivatelyCollectionClient = exports.DEFAULT_COLLECTION_ADDRESS = void 0;
7
7
  const ethers_1 = require("ethers");
8
8
  const PrivatelyCollection_json_1 = __importDefault(require("../../../PrivatelyCollection.json"));
9
9
  const request_signature_1 = require("../../common/request-signature");
@@ -11,21 +11,25 @@ const collection_approve_request_1 = require("./collection.approve.request");
11
11
  const collection_errors_1 = require("./collection.errors");
12
12
  const collection_mint_request_1 = require("./collection.mint.request");
13
13
  const collection_nft_1 = require("./collection.nft");
14
+ const collection_settokenuri_request_1 = require("./collection.settokenuri.request");
14
15
  const collection_transfer_request_1 = require("./collection.transfer.request");
15
- const COLLECTION_ADDRESS = "0xe7f1725e7734ce288f8367e1bb143e90bb3f0512";
16
+ /** Default address for local Hardhat deployment */
17
+ exports.DEFAULT_COLLECTION_ADDRESS = "0xe7f1725e7734ce288f8367e1bb143e90bb3f0512";
16
18
  class PrivatelyCollectionClient {
17
19
  contract;
20
+ address;
18
21
  signer;
19
22
  domain;
20
- constructor(signer, network) {
23
+ constructor(signer, network, address = exports.DEFAULT_COLLECTION_ADDRESS) {
21
24
  this.signer = signer;
22
- this.contract = new ethers_1.Contract(COLLECTION_ADDRESS, PrivatelyCollection_json_1.default.abi, signer);
25
+ this.address = address;
26
+ this.contract = new ethers_1.Contract(address, PrivatelyCollection_json_1.default.abi, signer);
23
27
  const name = PrivatelyCollection_json_1.default.contractName;
24
28
  this.domain = {
25
29
  name,
26
30
  version: "1.0.0",
27
31
  chainId: network.chainId,
28
- verifyingContract: COLLECTION_ADDRESS
32
+ verifyingContract: address
29
33
  };
30
34
  }
31
35
  /**
@@ -188,6 +192,55 @@ class PrivatelyCollectionClient {
188
192
  throw collection_errors_1.CollectionError.from(error, this.contract);
189
193
  }
190
194
  }
195
+ /**
196
+ * Creates a signed request to update the token URI for an NFT.
197
+ * This allows the owner to update the NFT's metadata URI via meta-transaction.
198
+ * @param tokenId The ID of the NFT to update.
199
+ * @param tokenURI The new metadata URI.
200
+ * @returns A RequestSignature containing the SetTokenURIRequest and signature.
201
+ */
202
+ async createSetTokenURIRequest(tokenId, tokenURI) {
203
+ if (!tokenURI.trim())
204
+ throw new collection_errors_1.CollectionError("Token URI cannot be empty");
205
+ const owner = await this.signer.getAddress();
206
+ const nonce = (await this.getNonces()).mintNonce;
207
+ const request = {
208
+ owner,
209
+ tokenId,
210
+ tokenURI,
211
+ nonce
212
+ };
213
+ const signature = await this.signer.signTypedData(this.domain, collection_settokenuri_request_1.COLLECTION_SET_TOKEN_URI_REQUEST_TYPE, request);
214
+ return new request_signature_1.RequestSignature(request_signature_1.RequestType.COLLECTION_SET_TOKEN_URI, signature, request);
215
+ }
216
+ /**
217
+ * Relays a signed setTokenURI request to the blockchain.
218
+ * The relayer (caller of this function) is responsible for the transaction's gas cost.
219
+ * @param request The SetTokenURIRequest object containing owner, tokenId, tokenURI, and nonce.
220
+ * @param signature The EIP-712 signature that authorizes this update.
221
+ * @returns A TransactionResponse object from ethers.
222
+ */
223
+ async relaySetTokenURIRequest(request, signature) {
224
+ try {
225
+ return await this.contract.metaSetTokenURI(request, signature);
226
+ }
227
+ catch (error) {
228
+ throw collection_errors_1.CollectionError.from(error, this.contract);
229
+ }
230
+ }
231
+ /**
232
+ * Retrieves the token URI for a given NFT.
233
+ * @param tokenId The ID of the NFT.
234
+ * @returns The metadata URI string.
235
+ */
236
+ async getTokenURI(tokenId) {
237
+ try {
238
+ return await this.contract.tokenURI(tokenId);
239
+ }
240
+ catch (error) {
241
+ throw collection_errors_1.CollectionError.from(error, this.contract);
242
+ }
243
+ }
191
244
  /**
192
245
  * Registers a listener for the "OnMint" event emitted by the contract when a new NFT is minted.
193
246
  * @param listener A callback function to be executed when the "OnMint" event is triggered.
@@ -0,0 +1,8 @@
1
+ import { TypedDataField } from "ethers";
2
+ export interface CollectionSetTokenURIRequest {
3
+ owner: string;
4
+ tokenId: bigint;
5
+ tokenURI: string;
6
+ nonce: bigint;
7
+ }
8
+ export declare const COLLECTION_SET_TOKEN_URI_REQUEST_TYPE: Record<string, TypedDataField[]>;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.COLLECTION_SET_TOKEN_URI_REQUEST_TYPE = void 0;
4
+ exports.COLLECTION_SET_TOKEN_URI_REQUEST_TYPE = {
5
+ SetTokenURIRequest: [
6
+ { name: "owner", type: "address" },
7
+ { name: "tokenId", type: "uint256" },
8
+ { name: "tokenURI", type: "string" },
9
+ { name: "nonce", type: "uint256" }
10
+ ]
11
+ };
@@ -4,4 +4,5 @@ export * from "./collection.errors";
4
4
  export * from "./collection.mint.request";
5
5
  export * from "./collection.nft";
6
6
  export * from "./collection.nonces";
7
+ export * from "./collection.settokenuri.request";
7
8
  export * from "./collection.transfer.request";
@@ -20,4 +20,5 @@ __exportStar(require("./collection.errors"), exports);
20
20
  __exportStar(require("./collection.mint.request"), exports);
21
21
  __exportStar(require("./collection.nft"), exports);
22
22
  __exportStar(require("./collection.nonces"), exports);
23
+ __exportStar(require("./collection.settokenuri.request"), exports);
23
24
  __exportStar(require("./collection.transfer.request"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "privately-smartcontract-lib",
3
- "version": "1.1.1",
3
+ "version": "1.2.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {