privately-smartcontract-lib 1.0.6 → 1.1.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.
@@ -1,8 +0,0 @@
1
- import { TypedDataField } from "ethers";
2
- export interface CoinApproveRequest {
3
- owner: string;
4
- spender: string;
5
- amount: bigint;
6
- nonce: bigint;
7
- }
8
- export declare const APPROVE_REQUEST_TYPE: Record<string, TypedDataField[]>;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.APPROVE_REQUEST_TYPE = void 0;
4
- exports.APPROVE_REQUEST_TYPE = {
5
- ApproveRequest: [
6
- { name: "owner", type: "address" },
7
- { name: "spender", type: "address" },
8
- { name: "amount", type: "uint256" },
9
- { name: "nonce", type: "uint256" }
10
- ]
11
- };
@@ -1,120 +0,0 @@
1
- import { Contract, Network, Signer, TransactionResponse } from "ethers";
2
- import { RequestSignature } from "../../common/request-signature";
3
- import { CoinApproveRequest } from "./coin.approve.request";
4
- import { OnMintListener, OnTransferListener } from "./coin.events";
5
- import { CoinTransferRequest } from "./coin.transfer.request";
6
- /**
7
- * CoinClient class to interact with the PrivatelyCoin smart contract
8
- */
9
- export declare class PrivatelyCoinClient {
10
- readonly contract: Contract;
11
- private readonly signer;
12
- private readonly domain;
13
- /**
14
- * Constructs a CoinClient instance to interact with the token contract
15
- * @param signer The transaction signer (wallet with private key)
16
- * @param network Network configuration for blockchain connection
17
- */
18
- constructor(signer: Signer, network: Network);
19
- /**
20
- * Retrieves the address of the current deployed contract.
21
- * @returns The contract address.
22
- */
23
- getContractAddress(): string;
24
- /**
25
- * Creates a signed transfer request for meta-transaction execution
26
- * @param to Recipient address
27
- * @param amount Token amount to transfer
28
- * @returns Promise containing transfer request and EIP-712 signature
29
- */
30
- createTransferRequest(to: string, amount: bigint): Promise<RequestSignature<CoinTransferRequest>>;
31
- /**
32
- * Relays a signed transfer request to execute as a meta-transaction
33
- * @param request Signed transfer request object
34
- * @param signature EIP-712 signature of the request
35
- * @returns Blockchain transaction response
36
- */
37
- relayTransferRequest(request: CoinTransferRequest, signature: string): Promise<TransactionResponse>;
38
- /**
39
- * Creates a signed allowance approval request for meta-transaction execution
40
- * @param spender Authorized spending address
41
- * @param amount Approved token amount
42
- * @returns Promise containing approval request and EIP-712 signature
43
- */
44
- createApproveRequest(spender: string, amount: bigint): Promise<RequestSignature<CoinApproveRequest>>;
45
- /**
46
- * Relays a signed approval request to execute as a meta-transaction
47
- * @param request Signed approval request object
48
- * @param signature EIP-712 signature of the request
49
- * @returns Blockchain transaction response
50
- * @throws If signature verification fails or nonce mismatch occurs
51
- */
52
- relayApproveRequest(request: CoinApproveRequest, signature: string): Promise<TransactionResponse>;
53
- /**
54
- * Mints new tokens (requires minter role)
55
- * @param to Recipient address
56
- * @param amount Amount to mint
57
- * @returns Blockchain transaction response
58
- */
59
- mint(to: string, amount: bigint): Promise<TransactionResponse>;
60
- /**
61
- * Executes standard ERC20 token transfer
62
- * @param to Recipient address
63
- * @param amount Amount to transfer
64
- * @returns Blockchain transaction response
65
- */
66
- transfer(to: string, amount: bigint): Promise<TransactionResponse>;
67
- /**
68
- * Approves spending allowance for a spender address
69
- * @param spender Authorized spending address
70
- * @param amount Approved amount
71
- * @returns Blockchain transaction response
72
- */
73
- approve(spender: string, amount: bigint): Promise<TransactionResponse>;
74
- /**
75
- * Gets remaining approved spending allowance
76
- * @param owner Token owner address
77
- * @param spender Authorized spender address
78
- * @returns Remaining allowed amount
79
- */
80
- allowance(owner: string, spender: string): Promise<bigint>;
81
- /**
82
- * Transfers tokens from an approved address
83
- * @param from Source address (must have allowance)
84
- * @param to Recipient address
85
- * @param amount Amount to transfer
86
- * @returns Blockchain transaction response
87
- */
88
- transferFrom(from: string, to: string, amount: bigint): Promise<TransactionResponse>;
89
- /**
90
- * Retrieves total token supply
91
- * @returns Total circulating token amount
92
- */
93
- totalSupply(): Promise<bigint>;
94
- /**
95
- * Gets token balance for a specific address
96
- * @param user Address to check
97
- * @returns Current token balance
98
- */
99
- getUserBalance(user: string): Promise<bigint>;
100
- /**
101
- * Retrieves current balance for the signer's address
102
- * @returns Current token balance for signer
103
- */
104
- getBalance(): Promise<bigint>;
105
- /**
106
- * Registers a listener for the "OnMint" event emitted by the contract when new coins are minted.
107
- * @param listener A callback function to be executed when the "OnMint" event is triggered.
108
- */
109
- onMintEvent(listener: OnMintListener): void;
110
- /**
111
- * Subscribes a listener to the "OnTransfer" event emitted by the contract when a transaction is executed.
112
- * @param listener A callback function to be executed when the "OnTransfer" event is triggered.
113
- */
114
- onTransferEvent(listener: OnTransferListener): void;
115
- /**
116
- * Retrieves the current nonce for transfer and approve requests
117
- * @returns Current nonces for signer's address
118
- */
119
- private getNonces;
120
- }
@@ -1,246 +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.PrivatelyCoinClient = void 0;
7
- const ethers_1 = require("ethers");
8
- const PrivatelyCoin_json_1 = __importDefault(require("../../../PrivatelyCoin.json"));
9
- const request_signature_1 = require("../../common/request-signature");
10
- const coin_approve_request_1 = require("./coin.approve.request");
11
- const coin_errors_1 = require("./coin.errors");
12
- const coin_transfer_request_1 = require("./coin.transfer.request");
13
- const COIN_CONTRACT_ADDRESS = "0x5fbdb2315678afecb367f032d93f642f64180aa3";
14
- /**
15
- * CoinClient class to interact with the PrivatelyCoin smart contract
16
- */
17
- class PrivatelyCoinClient {
18
- contract;
19
- signer;
20
- domain;
21
- /**
22
- * Constructs a CoinClient instance to interact with the token contract
23
- * @param signer The transaction signer (wallet with private key)
24
- * @param network Network configuration for blockchain connection
25
- */
26
- constructor(signer, network) {
27
- this.signer = signer;
28
- this.contract = new ethers_1.Contract(COIN_CONTRACT_ADDRESS, PrivatelyCoin_json_1.default.abi, signer);
29
- const name = PrivatelyCoin_json_1.default.contractName;
30
- this.domain = {
31
- name,
32
- version: "1.0.0",
33
- chainId: network.chainId,
34
- verifyingContract: COIN_CONTRACT_ADDRESS
35
- };
36
- }
37
- /**
38
- * Retrieves the address of the current deployed contract.
39
- * @returns The contract address.
40
- */
41
- getContractAddress() {
42
- return COIN_CONTRACT_ADDRESS;
43
- }
44
- /**
45
- * Creates a signed transfer request for meta-transaction execution
46
- * @param to Recipient address
47
- * @param amount Token amount to transfer
48
- * @returns Promise containing transfer request and EIP-712 signature
49
- */
50
- async createTransferRequest(to, amount) {
51
- const from = await this.signer.getAddress();
52
- const nonce = (await this.getNonces()).transferNonce;
53
- const request = {
54
- from: from,
55
- to: to,
56
- amount: amount,
57
- nonce: nonce
58
- };
59
- const signature = await this.signer.signTypedData(this.domain, coin_transfer_request_1.TRANSFER_REQUEST_TYPE, request);
60
- return new request_signature_1.RequestSignature(request_signature_1.RequestType.COIN_TRANSFER, signature, request);
61
- }
62
- /**
63
- * Relays a signed transfer request to execute as a meta-transaction
64
- * @param request Signed transfer request object
65
- * @param signature EIP-712 signature of the request
66
- * @returns Blockchain transaction response
67
- */
68
- async relayTransferRequest(request, signature) {
69
- try {
70
- return await this.contract.metaTransfer(request.from, request.to, request.amount, signature);
71
- }
72
- catch (error) {
73
- throw coin_errors_1.CoinError.from(error, this.contract);
74
- }
75
- }
76
- /**
77
- * Creates a signed allowance approval request for meta-transaction execution
78
- * @param spender Authorized spending address
79
- * @param amount Approved token amount
80
- * @returns Promise containing approval request and EIP-712 signature
81
- */
82
- async createApproveRequest(spender, amount) {
83
- const owner = await this.signer.getAddress();
84
- const nonce = (await this.getNonces()).approveNonce;
85
- const request = {
86
- owner: owner,
87
- spender: spender,
88
- amount: amount,
89
- nonce: nonce
90
- };
91
- const signature = await this.signer.signTypedData(this.domain, coin_approve_request_1.APPROVE_REQUEST_TYPE, request);
92
- return new request_signature_1.RequestSignature(request_signature_1.RequestType.COIN_APPROVE, signature, request);
93
- }
94
- /**
95
- * Relays a signed approval request to execute as a meta-transaction
96
- * @param request Signed approval request object
97
- * @param signature EIP-712 signature of the request
98
- * @returns Blockchain transaction response
99
- * @throws If signature verification fails or nonce mismatch occurs
100
- */
101
- async relayApproveRequest(request, signature) {
102
- try {
103
- return await this.contract.metaApprove(request.owner, request.spender, request.amount, signature);
104
- }
105
- catch (error) {
106
- throw coin_errors_1.CoinError.from(error, this.contract);
107
- }
108
- }
109
- /**
110
- * Mints new tokens (requires minter role)
111
- * @param to Recipient address
112
- * @param amount Amount to mint
113
- * @returns Blockchain transaction response
114
- */
115
- async mint(to, amount) {
116
- try {
117
- return await this.contract.mint(to, amount);
118
- }
119
- catch (error) {
120
- throw coin_errors_1.CoinError.from(error, this.contract);
121
- }
122
- }
123
- /**
124
- * Executes standard ERC20 token transfer
125
- * @param to Recipient address
126
- * @param amount Amount to transfer
127
- * @returns Blockchain transaction response
128
- */
129
- async transfer(to, amount) {
130
- try {
131
- return await this.contract.transfer(to, amount);
132
- }
133
- catch (error) {
134
- throw coin_errors_1.CoinError.from(error, this.contract);
135
- }
136
- }
137
- /**
138
- * Approves spending allowance for a spender address
139
- * @param spender Authorized spending address
140
- * @param amount Approved amount
141
- * @returns Blockchain transaction response
142
- */
143
- async approve(spender, amount) {
144
- try {
145
- return await this.contract.approve(spender, amount);
146
- }
147
- catch (error) {
148
- throw coin_errors_1.CoinError.from(error, this.contract);
149
- }
150
- }
151
- /**
152
- * Gets remaining approved spending allowance
153
- * @param owner Token owner address
154
- * @param spender Authorized spender address
155
- * @returns Remaining allowed amount
156
- */
157
- async allowance(owner, spender) {
158
- try {
159
- return await this.contract.allowance(owner, spender);
160
- }
161
- catch (error) {
162
- throw coin_errors_1.CoinError.from(error, this.contract);
163
- }
164
- }
165
- /**
166
- * Transfers tokens from an approved address
167
- * @param from Source address (must have allowance)
168
- * @param to Recipient address
169
- * @param amount Amount to transfer
170
- * @returns Blockchain transaction response
171
- */
172
- async transferFrom(from, to, amount) {
173
- try {
174
- return await this.contract.transferFrom(from, to, amount);
175
- }
176
- catch (error) {
177
- throw coin_errors_1.CoinError.from(error, this.contract);
178
- }
179
- }
180
- /**
181
- * Retrieves total token supply
182
- * @returns Total circulating token amount
183
- */
184
- async totalSupply() {
185
- try {
186
- return await this.contract.totalSupply();
187
- }
188
- catch (error) {
189
- throw coin_errors_1.CoinError.from(error, this.contract);
190
- }
191
- }
192
- /**
193
- * Gets token balance for a specific address
194
- * @param user Address to check
195
- * @returns Current token balance
196
- */
197
- async getUserBalance(user) {
198
- try {
199
- return this.contract.balanceOf(user);
200
- }
201
- catch (error) {
202
- throw coin_errors_1.CoinError.from(error, this.contract);
203
- }
204
- }
205
- /**
206
- * Retrieves current balance for the signer's address
207
- * @returns Current token balance for signer
208
- */
209
- async getBalance() {
210
- const selfAddress = await this.signer.getAddress();
211
- return this.getUserBalance(selfAddress);
212
- }
213
- /**
214
- * Registers a listener for the "OnMint" event emitted by the contract when new coins are minted.
215
- * @param listener A callback function to be executed when the "OnMint" event is triggered.
216
- */
217
- onMintEvent(listener) {
218
- void this.contract.on("OnMint", (to, amount, finalBalance, event) => {
219
- listener(to, amount, finalBalance, event);
220
- });
221
- }
222
- /**
223
- * Subscribes a listener to the "OnTransfer" event emitted by the contract when a transaction is executed.
224
- * @param listener A callback function to be executed when the "OnTransfer" event is triggered.
225
- */
226
- onTransferEvent(listener) {
227
- void this.contract.on("OnTransfer", (from, to, amount, fromFinalBalance, toFinalBalance, event) => {
228
- listener(from, to, amount, fromFinalBalance, toFinalBalance, event);
229
- });
230
- }
231
- /**
232
- * Retrieves the current nonce for transfer and approve requests
233
- * @returns Current nonces for signer's address
234
- */
235
- async getNonces() {
236
- const selfAddress = await this.signer.getAddress();
237
- try {
238
- const nonces = await this.contract.getNonces(selfAddress);
239
- return { transferNonce: nonces.transferNonce, approveNonce: nonces.approveNonce };
240
- }
241
- catch (error) {
242
- throw coin_errors_1.CoinError.from(error, this.contract);
243
- }
244
- }
245
- }
246
- exports.PrivatelyCoinClient = PrivatelyCoinClient;
@@ -1,6 +0,0 @@
1
- import { Contract } from "ethers";
2
- import { PrivatelyError } from "../../common/privately.error";
3
- export declare class CoinError extends PrivatelyError {
4
- constructor(message: string | object);
5
- static from(error: any, contract?: Contract): CoinError;
6
- }
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CoinError = void 0;
4
- const privately_error_1 = require("../../common/privately.error");
5
- class CoinError extends privately_error_1.PrivatelyError {
6
- constructor(message) {
7
- super(`CoinError: ${typeof message === 'object' ? JSON.stringify(message) : message}`);
8
- this.name = "CoinError";
9
- }
10
- static from(error, contract) {
11
- try {
12
- const message = (0, privately_error_1.parseContractError)(error, contract?.interface);
13
- return new CoinError(message);
14
- }
15
- catch (parseError) {
16
- return new CoinError({
17
- originalError: error,
18
- parseError
19
- });
20
- }
21
- }
22
- }
23
- exports.CoinError = CoinError;
@@ -1,3 +0,0 @@
1
- import { Log } from "ethers";
2
- export type OnMintListener = (to: string, amount: bigint, finalBalance: bigint, event: Log) => void;
3
- export type OnTransferListener = (from: string, to: string, amount: bigint, fromFinalBalance: bigint, toFinalBalance: bigint, event: Log) => void;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +0,0 @@
1
- export interface CoinNonces {
2
- transferNonce: bigint;
3
- approveNonce: bigint;
4
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,8 +0,0 @@
1
- import { TypedDataField } from "ethers";
2
- export interface CoinTransferRequest {
3
- from: string;
4
- to: string;
5
- amount: bigint;
6
- nonce: bigint;
7
- }
8
- export declare const TRANSFER_REQUEST_TYPE: Record<string, TypedDataField[]>;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TRANSFER_REQUEST_TYPE = void 0;
4
- exports.TRANSFER_REQUEST_TYPE = {
5
- TransferRequest: [
6
- { name: "from", type: "address" },
7
- { name: "to", type: "address" },
8
- { name: "amount", type: "uint256" },
9
- { name: "nonce", type: "uint256" }
10
- ]
11
- };
@@ -1,5 +0,0 @@
1
- export * from "./coin.approve.request";
2
- export * from "./coin.client";
3
- export * from "./coin.errors";
4
- export * from "./coin.nonces";
5
- export * from "./coin.transfer.request";
@@ -1,21 +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("./coin.approve.request"), exports);
18
- __exportStar(require("./coin.client"), exports);
19
- __exportStar(require("./coin.errors"), exports);
20
- __exportStar(require("./coin.nonces"), exports);
21
- __exportStar(require("./coin.transfer.request"), exports);