privately-smartcontract-lib 1.0.6 → 1.1.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.
Files changed (64) hide show
  1. package/MockUSDC.json +342 -0
  2. package/package.json +4 -4
  3. package/PrivatelyCoin.json +0 -863
  4. package/dist/PrivatelyAuctionSystem.json +0 -734
  5. package/dist/PrivatelyCoin.json +0 -863
  6. package/dist/PrivatelyCollection.json +0 -865
  7. package/dist/client.d.ts +0 -38
  8. package/dist/client.js +0 -67
  9. package/dist/common/index.d.ts +0 -2
  10. package/dist/common/index.js +0 -18
  11. package/dist/common/privately.error.d.ts +0 -5
  12. package/dist/common/privately.error.js +0 -47
  13. package/dist/common/request-signature.d.ts +0 -17
  14. package/dist/common/request-signature.js +0 -38
  15. package/dist/index.d.ts +0 -5
  16. package/dist/index.js +0 -21
  17. package/dist/modules/auctions/auctions.auction.d.ts +0 -12
  18. package/dist/modules/auctions/auctions.auction.js +0 -29
  19. package/dist/modules/auctions/auctions.bid.reqest.d.ts +0 -12
  20. package/dist/modules/auctions/auctions.bid.reqest.js +0 -11
  21. package/dist/modules/auctions/auctions.client.d.ts +0 -147
  22. package/dist/modules/auctions/auctions.client.js +0 -312
  23. package/dist/modules/auctions/auctions.create.request.d.ts +0 -13
  24. package/dist/modules/auctions/auctions.create.request.js +0 -12
  25. package/dist/modules/auctions/auctions.errors.d.ts +0 -6
  26. package/dist/modules/auctions/auctions.errors.js +0 -14
  27. package/dist/modules/auctions/auctions.events.d.ts +0 -5
  28. package/dist/modules/auctions/auctions.events.js +0 -2
  29. package/dist/modules/auctions/auctions.nonces.d.ts +0 -4
  30. package/dist/modules/auctions/auctions.nonces.js +0 -2
  31. package/dist/modules/auctions/index.d.ts +0 -6
  32. package/dist/modules/auctions/index.js +0 -22
  33. package/dist/modules/coin/coin.approve.request.d.ts +0 -8
  34. package/dist/modules/coin/coin.approve.request.js +0 -11
  35. package/dist/modules/coin/coin.client.d.ts +0 -120
  36. package/dist/modules/coin/coin.client.js +0 -246
  37. package/dist/modules/coin/coin.errors.d.ts +0 -6
  38. package/dist/modules/coin/coin.errors.js +0 -23
  39. package/dist/modules/coin/coin.events.d.ts +0 -3
  40. package/dist/modules/coin/coin.events.js +0 -2
  41. package/dist/modules/coin/coin.nonces.d.ts +0 -4
  42. package/dist/modules/coin/coin.nonces.js +0 -2
  43. package/dist/modules/coin/coin.transfer.request.d.ts +0 -8
  44. package/dist/modules/coin/coin.transfer.request.js +0 -11
  45. package/dist/modules/coin/index.d.ts +0 -5
  46. package/dist/modules/coin/index.js +0 -21
  47. package/dist/modules/collection/collection.approve.request.d.ts +0 -8
  48. package/dist/modules/collection/collection.approve.request.js +0 -11
  49. package/dist/modules/collection/collection.client.d.ts +0 -97
  50. package/dist/modules/collection/collection.client.js +0 -224
  51. package/dist/modules/collection/collection.errors.d.ts +0 -6
  52. package/dist/modules/collection/collection.errors.js +0 -14
  53. package/dist/modules/collection/collection.events.d.ts +0 -3
  54. package/dist/modules/collection/collection.events.js +0 -2
  55. package/dist/modules/collection/collection.mint.request.d.ts +0 -9
  56. package/dist/modules/collection/collection.mint.request.js +0 -12
  57. package/dist/modules/collection/collection.nft.d.ts +0 -8
  58. package/dist/modules/collection/collection.nft.js +0 -21
  59. package/dist/modules/collection/collection.nonces.d.ts +0 -5
  60. package/dist/modules/collection/collection.nonces.js +0 -2
  61. package/dist/modules/collection/collection.transfer.request.d.ts +0 -12
  62. package/dist/modules/collection/collection.transfer.request.js +0 -11
  63. package/dist/modules/collection/index.d.ts +0 -7
  64. package/dist/modules/collection/index.js +0 -23
@@ -1,224 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.PrivatelyCollectionClient = void 0;
7
- const ethers_1 = require("ethers");
8
- const PrivatelyCollection_json_1 = __importDefault(require("../../../PrivatelyCollection.json"));
9
- const request_signature_1 = require("../../common/request-signature");
10
- const collection_approve_request_1 = require("./collection.approve.request");
11
- const collection_errors_1 = require("./collection.errors");
12
- const collection_mint_request_1 = require("./collection.mint.request");
13
- const collection_nft_1 = require("./collection.nft");
14
- const collection_transfer_request_1 = require("./collection.transfer.request");
15
- const COLLECTION_ADDRESS = "0xe7f1725e7734ce288f8367e1bb143e90bb3f0512";
16
- class PrivatelyCollectionClient {
17
- contract;
18
- signer;
19
- domain;
20
- constructor(signer, network) {
21
- this.signer = signer;
22
- this.contract = new ethers_1.Contract(COLLECTION_ADDRESS, PrivatelyCollection_json_1.default.abi, signer);
23
- const name = PrivatelyCollection_json_1.default.contractName;
24
- this.domain = {
25
- name,
26
- version: "1.0.0",
27
- chainId: network.chainId,
28
- verifyingContract: COLLECTION_ADDRESS
29
- };
30
- }
31
- /**
32
- * Retrieves a list of all NFT token IDs currently stored in the contract.
33
- * @returns An array of token IDs as bigint.
34
- */
35
- async getSupplyCollection() {
36
- try {
37
- return await this.contract.getAllCollection();
38
- }
39
- catch (error) {
40
- throw collection_errors_1.CollectionError.from(error, this.contract);
41
- }
42
- }
43
- /**
44
- * Retrieves the list of NFT token IDs owned by a specific user.
45
- * @param owner The address of the user whose Collection should be retrieved.
46
- * @returns An array of token IDs as bigint.
47
- */
48
- async getUserCollection(owner) {
49
- try {
50
- const collection = await this.contract.getCollectionOfUser(owner);
51
- return await collection_nft_1.PrivatelyNFT.map(collection, this);
52
- }
53
- catch (error) {
54
- throw collection_errors_1.CollectionError.from(error, this.contract);
55
- }
56
- }
57
- /**
58
- * Retrieves the list of NFT token IDs owned by the client's signer address.
59
- * @returns An array of token IDs as bigint.
60
- */
61
- async getCollection() {
62
- const myAddress = await this.signer.getAddress();
63
- try {
64
- const collection = await this.contract.getCollectionOfUser(myAddress);
65
- return await collection_nft_1.PrivatelyNFT.map(collection, this);
66
- }
67
- catch (error) {
68
- throw collection_errors_1.CollectionError.from(error, this.contract);
69
- }
70
- }
71
- /**
72
- * Fetches the metadata for a specific NFT token ID.
73
- * @param tokenId The ID of the NFT (as BigNumberish).
74
- * @returns A PrivatelyNFT object containing the NFT's metadata.
75
- */
76
- async getData(tokenId) {
77
- try {
78
- const data = await this.contract.getData(tokenId);
79
- return new collection_nft_1.PrivatelyNFT(tokenId, data.title, data.author, data.uri);
80
- }
81
- catch (error) {
82
- throw collection_errors_1.CollectionError.from(error, this.contract);
83
- }
84
- }
85
- /**
86
- * Creates and signs a MintRequest using EIP-712 structured data.
87
- * This request can later be relayed to the contract via `relayMintRequest`.
88
- * @param title The NFT title.
89
- * @param tokenURI The URI for the NFT metadata.
90
- * @returns An object containing the mint request struct and its EIP-712 signature.
91
- */
92
- async createMintRequest(title, tokenURI) {
93
- if (!title.trim())
94
- throw new collection_errors_1.CollectionError("Title cannot be empty");
95
- if (!tokenURI.trim())
96
- throw new collection_errors_1.CollectionError("Token URI cannot be empty");
97
- const userAddress = await this.signer.getAddress();
98
- const nonce = (await this.getNonces()).mintNonce;
99
- const request = {
100
- user: userAddress,
101
- title: title,
102
- author: userAddress,
103
- tokenURI: tokenURI,
104
- nonce: nonce
105
- };
106
- const signature = await this.signer.signTypedData(this.domain, collection_mint_request_1.COLLECTION_MINT_REQUEST_TYPE, request);
107
- return new request_signature_1.RequestSignature(request_signature_1.RequestType.COLLECTION_MINT, signature, request);
108
- }
109
- /**
110
- * Relays a signed mint request to the blockchain.
111
- * The relayer (caller of this function) is responsible for the transaction's gas cost.
112
- * @param request The MintRequest object containing user, title, author, tokenURI, and nonce.
113
- * @param signature The EIP-712 signature that authorizes this mint.
114
- * @returns A TransactionResponse object from ethers.
115
- */
116
- async relayMintRequest(request, signature) {
117
- try {
118
- return await this.contract.metaMint(request.user, request.title, request.tokenURI, signature);
119
- }
120
- catch (error) {
121
- throw collection_errors_1.CollectionError.from(error, this.contract);
122
- }
123
- }
124
- /**
125
- * Creates and signs a TransferRequest using EIP-712 structured data.
126
- * This request can later be relayed to the contract via `relayTransferRequest`.
127
- * @param to The address to which the NFT should be transferred.
128
- * @param tokenId The ID of the NFT (BigNumberish).
129
- * @returns An object containing the transfer request struct and its EIP-712 signature.
130
- */
131
- async createTransferRequest(to, tokenId) {
132
- const from = await this.signer.getAddress();
133
- const nonce = (await this.getNonces()).transferNonce;
134
- const request = {
135
- from,
136
- to,
137
- tokenId,
138
- nonce
139
- };
140
- const signature = await this.signer.signTypedData(this.domain, collection_transfer_request_1.COLLECTION_TRANSFER_REQUEST_TYPE, request);
141
- return new request_signature_1.RequestSignature(request_signature_1.RequestType.COLLECTION_TRANSFER, signature, request);
142
- }
143
- /**
144
- * Relays a signed transfer request to the blockchain.
145
- * The relayer (caller of this function) is responsible for the transaction's gas cost.
146
- * @param request The TransferRequest object containing from, to, tokenId, and nonce.
147
- * @param signature The EIP-712 signature that authorizes this transfer.
148
- * @returns A TransactionResponse object from ethers.
149
- */
150
- async relayTransferRequest(request, signature) {
151
- try {
152
- return await this.contract.metaTransfer(request.from, request.to, request.tokenId, signature);
153
- }
154
- catch (error) {
155
- throw collection_errors_1.CollectionError.from(error, this.contract);
156
- }
157
- }
158
- /**
159
- * Creates and signs an ApproveRequest using EIP-712 structured data.
160
- * @param spender The address to which the approval should be granted.
161
- * @param tokenId The ID of the NFT (BigNumberish).
162
- * @returns An object containing the approval request struct and its EIP-712 signature.
163
- */
164
- async createApproveRequest(spender, tokenId) {
165
- const owner = await this.signer.getAddress();
166
- const nonce = (await this.getNonces()).approveNonce;
167
- const request = {
168
- owner,
169
- spender,
170
- tokenId,
171
- nonce
172
- };
173
- const signature = await this.signer.signTypedData(this.domain, collection_approve_request_1.COLLECTION_APPROVE_REQUEST_TYPE, request);
174
- return new request_signature_1.RequestSignature(request_signature_1.RequestType.COLLECTION_APPROVE, signature, request);
175
- }
176
- /**
177
- * Relays a signed approval request to the blockchain.
178
- * The relayer (caller of this function) is responsible for the transaction's gas cost.
179
- * @param request The ApproveRequest object containing owner, spender, tokenId, and nonce.
180
- * @param signature The EIP-712 signature that authorizes this approval.
181
- * @returns A TransactionResponse object from ethers.
182
- */
183
- async relayApproveRequest(request, signature) {
184
- try {
185
- return await this.contract.metaApprove(request.owner, request.spender, request.tokenId, signature);
186
- }
187
- catch (error) {
188
- throw collection_errors_1.CollectionError.from(error, this.contract);
189
- }
190
- }
191
- /**
192
- * Registers a listener for the "OnMint" event emitted by the contract when a new NFT is minted.
193
- * @param listener A callback function to be executed when the "OnMint" event is triggered.
194
- */
195
- onMintEvent(listener) {
196
- void this.contract.on("OnMint", (to, amount, event) => {
197
- listener(to, amount, event);
198
- });
199
- }
200
- /**
201
- * Subscribes a listener to the "OnTransfer" event emitted by the contract when a NFT transfer is executed.
202
- * @param listener A callback function to be executed when the "OnTransfer" event is triggered.
203
- */
204
- onTransferEvent(listener) {
205
- void this.contract.on("OnTransfer", (from, to, amount, event) => {
206
- listener(from, to, amount, event);
207
- });
208
- }
209
- /**
210
- * Retrieves current nonce for meta-transactions
211
- * @returns Current nonce for signer's address
212
- */
213
- async getNonces() {
214
- const selfAddress = await this.signer.getAddress();
215
- try {
216
- const nonces = await this.contract.getNonces(selfAddress);
217
- return { mintNonce: nonces.mintNonce, transferNonce: nonces.transferNonce, approveNonce: nonces.approveNonce };
218
- }
219
- catch (error) {
220
- throw collection_errors_1.CollectionError.from(error, this.contract);
221
- }
222
- }
223
- }
224
- exports.PrivatelyCollectionClient = PrivatelyCollectionClient;
@@ -1,6 +0,0 @@
1
- import { Contract } from "ethers";
2
- import { PrivatelyError } from "../../common/privately.error";
3
- export declare class CollectionError extends PrivatelyError {
4
- constructor(message: string);
5
- static from(error: any, contract?: Contract): CollectionError;
6
- }
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CollectionError = void 0;
4
- const privately_error_1 = require("../../common/privately.error");
5
- class CollectionError extends privately_error_1.PrivatelyError {
6
- constructor(message) {
7
- super(`CollectionError: ${message}`);
8
- this.name = "CollectionError";
9
- }
10
- static from(error, contract) {
11
- return new CollectionError((0, privately_error_1.parseContractError)(error, contract?.interface));
12
- }
13
- }
14
- exports.CollectionError = CollectionError;
@@ -1,3 +0,0 @@
1
- import { Log } from "ethers";
2
- export type OnMintListener = (to: string, amount: bigint, event: Log) => void;
3
- export type OnTransferListener = (from: string, to: string, amount: bigint, event: Log) => void;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,9 +0,0 @@
1
- import { TypedDataField } from "ethers";
2
- export interface CollectionMintRequest {
3
- user: string;
4
- title: string;
5
- author: string;
6
- tokenURI: string;
7
- nonce: bigint;
8
- }
9
- export declare const COLLECTION_MINT_REQUEST_TYPE: Record<string, TypedDataField[]>;
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.COLLECTION_MINT_REQUEST_TYPE = void 0;
4
- exports.COLLECTION_MINT_REQUEST_TYPE = {
5
- MintRequest: [
6
- { name: "user", type: "address" },
7
- { name: "title", type: "string" },
8
- { name: "author", type: "address" },
9
- { name: "tokenURI", type: "string" },
10
- { name: "nonce", type: "uint256" }
11
- ]
12
- };
@@ -1,8 +0,0 @@
1
- export declare class PrivatelyNFT {
2
- id: bigint;
3
- title: string;
4
- author: string;
5
- url: string;
6
- constructor(id: bigint, title: string, author: string, url: string);
7
- static map(list: bigint[], client: any): Promise<PrivatelyNFT[]>;
8
- }
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PrivatelyNFT = void 0;
4
- class PrivatelyNFT {
5
- id;
6
- title;
7
- author;
8
- url;
9
- constructor(id, title, author, url) {
10
- this.id = id;
11
- this.title = title;
12
- this.author = author;
13
- this.url = url;
14
- }
15
- static async map(list, client) {
16
- return await Promise.all(list.map(async (id) => {
17
- return await client.getData(id);
18
- }));
19
- }
20
- }
21
- exports.PrivatelyNFT = PrivatelyNFT;
@@ -1,5 +0,0 @@
1
- export interface CollectionNonces {
2
- mintNonce: bigint;
3
- transferNonce: bigint;
4
- approveNonce: bigint;
5
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,12 +0,0 @@
1
- export interface CollectionTransferRequest {
2
- from: string;
3
- to: string;
4
- tokenId: bigint;
5
- nonce: bigint;
6
- }
7
- export declare const COLLECTION_TRANSFER_REQUEST_TYPE: {
8
- TransferRequest: {
9
- name: string;
10
- type: string;
11
- }[];
12
- };
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.COLLECTION_TRANSFER_REQUEST_TYPE = void 0;
4
- exports.COLLECTION_TRANSFER_REQUEST_TYPE = {
5
- TransferRequest: [
6
- { name: "from", type: "address" },
7
- { name: "to", type: "address" },
8
- { name: "tokenId", type: "uint256" },
9
- { name: "nonce", type: "uint256" }
10
- ]
11
- };
@@ -1,7 +0,0 @@
1
- export * from "./collection.approve.request";
2
- export * from "./collection.client";
3
- export * from "./collection.errors";
4
- export * from "./collection.mint.request";
5
- export * from "./collection.nft";
6
- export * from "./collection.nonces";
7
- export * from "./collection.transfer.request";
@@ -1,23 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./collection.approve.request"), exports);
18
- __exportStar(require("./collection.client"), exports);
19
- __exportStar(require("./collection.errors"), exports);
20
- __exportStar(require("./collection.mint.request"), exports);
21
- __exportStar(require("./collection.nft"), exports);
22
- __exportStar(require("./collection.nonces"), exports);
23
- __exportStar(require("./collection.transfer.request"), exports);