privately-smartcontract-lib 1.2.0 → 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.
@@ -3,7 +3,8 @@ export declare enum RequestType {
3
3
  AUCTION_BID = "AUCTION_BID",
4
4
  COLLECTION_MINT = "COLLECTION_MINT",
5
5
  COLLECTION_TRANSFER = "COLLECTION_TRANSFER",
6
- COLLECTION_APPROVE = "COLLECTION_APPROVE"
6
+ COLLECTION_APPROVE = "COLLECTION_APPROVE",
7
+ COLLECTION_SET_TOKEN_URI = "COLLECTION_SET_TOKEN_URI"
7
8
  }
8
9
  export declare class RequestSignature<T> {
9
10
  readonly type: RequestType;
@@ -10,6 +10,7 @@ var RequestType;
10
10
  RequestType["COLLECTION_MINT"] = "COLLECTION_MINT";
11
11
  RequestType["COLLECTION_TRANSFER"] = "COLLECTION_TRANSFER";
12
12
  RequestType["COLLECTION_APPROVE"] = "COLLECTION_APPROVE";
13
+ RequestType["COLLECTION_SET_TOKEN_URI"] = "COLLECTION_SET_TOKEN_URI";
13
14
  })(RequestType || (exports.RequestType = RequestType = {}));
14
15
  class RequestSignature {
15
16
  type;
@@ -4,6 +4,7 @@ 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";
8
9
  /** Default address for local Hardhat deployment */
9
10
  export declare const DEFAULT_COLLECTION_ADDRESS = "0xe7f1725e7734ce288f8367e1bb143e90bb3f0512";
@@ -82,6 +83,28 @@ export declare class PrivatelyCollectionClient {
82
83
  * @returns A TransactionResponse object from ethers.
83
84
  */
84
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>;
85
108
  /**
86
109
  * Registers a listener for the "OnMint" event emitted by the contract when a new NFT is minted.
87
110
  * @param listener A callback function to be executed when the "OnMint" event is triggered.
@@ -11,6 +11,7 @@ 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
16
  /** Default address for local Hardhat deployment */
16
17
  exports.DEFAULT_COLLECTION_ADDRESS = "0xe7f1725e7734ce288f8367e1bb143e90bb3f0512";
@@ -191,6 +192,55 @@ class PrivatelyCollectionClient {
191
192
  throw collection_errors_1.CollectionError.from(error, this.contract);
192
193
  }
193
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
+ }
194
244
  /**
195
245
  * Registers a listener for the "OnMint" event emitted by the contract when a new NFT is minted.
196
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.2.0",
3
+ "version": "1.2.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {