x402z-shared 0.0.7 → 0.0.9

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/README.md CHANGED
@@ -8,35 +8,22 @@ Shared utilities for the erc7984-mind-v1 x402 scheme.
8
8
  pnpm add x402z-shared
9
9
  ```
10
10
 
11
- ## Relayer helpers (Node)
11
+ ## Folder map
12
12
 
13
- ```ts
14
- import {
15
- createRelayerInstance,
16
- createEncryptedAmountInput,
17
- SepoliaConfig,
18
- } from "x402z-shared";
13
+ - `src/core/`: ABI, constants, types, utils
14
+ - `src/relayer/`: relayer helpers
15
+ - `src/token/`: token, balance, observer, transfer helpers
16
+ - `src/index.ts`: public exports
19
17
 
20
- ```
21
-
22
- ## Relayer helpers (Browser)
18
+ ## Relayer helpers (Node)
23
19
 
24
20
  ```ts
25
21
  import {
26
- createRelayerInstance,
22
+ createRelayer,
27
23
  createEncryptedAmountInput,
28
- initSDK,
29
24
  SepoliaConfig,
30
- } from "x402z-shared/web";
25
+ } from "x402z-shared";
31
26
 
32
- await initSDK();
33
- const relayer = await createRelayerInstance(SepoliaConfig);
34
- const encrypted = await createEncryptedAmountInput(
35
- relayer,
36
- "0xToken",
37
- "0xFacilitator",
38
- 1000,
39
- );
40
27
  ```
41
28
 
42
29
  ## Token helper (Node)
@@ -61,9 +48,9 @@ Notes:
61
48
  ## Transfer amount helper (Node)
62
49
 
63
50
  ```ts
64
- import { viewConfidentialTransferAmounts } from "x402z-shared";
51
+ import { getTransferAmounts } from "x402z-shared";
65
52
 
66
- const transfers = await viewConfidentialTransferAmounts({
53
+ const transfers = await getTransferAmounts({
67
54
  rpcUrl: "https://sepolia.infura.io/v3/...",
68
55
  tokenAddress: "0xToken",
69
56
  txHash: "0xTransactionHash",
@@ -94,26 +81,7 @@ const txHash = await token.setObserver("0xHolder", "0xObserver");
94
81
  console.log(txHash);
95
82
  ```
96
83
 
97
- ## Token helper (Browser)
98
-
99
- ```ts
100
- import { ConfidentialTokenWeb } from "x402z-shared/web";
101
-
102
- const token = new ConfidentialTokenWeb({
103
- rpcUrl: "https://sepolia.infura.io/v3/...",
104
- tokenAddress: "0xToken",
105
- relayer,
106
- walletClient,
107
- });
108
- const txHash = await token.setObserver("0xHolder", "0xObserver");
109
- console.log(txHash);
110
- ```
111
-
112
- ## Transfer amount helper (Browser)
113
-
114
- ```ts
115
- import { viewConfidentialTransferAmounts } from "x402z-shared/web";
116
- ```
117
84
  ## Notes
118
85
 
119
86
  - Scheme name: `erc7984-mind-v1`
87
+ - For browser usage, use `x402z-shared-web`.
package/dist/index.d.mts CHANGED
@@ -1,9 +1,243 @@
1
- import { c as confidentialTokenAbi } from './types-I3K7qzdc.mjs';
2
- export { C as ConfidentialErrorCode, e as ConfidentialPaymentAuthorization, i as ConfidentialPaymentInput, f as ConfidentialPaymentPayload, g as ConfidentialRequirementsExtra, b as confidentialErrorCodes, a as confidentialPaymentTypes, d as createNonce, h as hashEncryptedAmountInput, n as normalizeAmount } from './types-I3K7qzdc.mjs';
3
1
  import { FhevmInstanceConfig, createInstance } from '@zama-fhe/relayer-sdk/node';
4
2
  export { FhevmInstanceConfig, SepoliaConfig } from '@zama-fhe/relayer-sdk/node';
5
3
  export * from '@x402/core/types';
6
4
 
5
+ declare const confidentialTokenAbi: readonly [{
6
+ readonly inputs: readonly [{
7
+ readonly internalType: "address";
8
+ readonly name: "to";
9
+ readonly type: "address";
10
+ }, {
11
+ readonly internalType: "bytes32";
12
+ readonly name: "encryptedAmountInput";
13
+ readonly type: "bytes32";
14
+ }, {
15
+ readonly internalType: "bytes";
16
+ readonly name: "inputProof";
17
+ readonly type: "bytes";
18
+ }];
19
+ readonly name: "confidentialTransfer";
20
+ readonly outputs: readonly [{
21
+ readonly internalType: "euint64";
22
+ readonly name: "transferred";
23
+ readonly type: "bytes32";
24
+ }];
25
+ readonly stateMutability: "nonpayable";
26
+ readonly type: "function";
27
+ }, {
28
+ readonly inputs: readonly [{
29
+ readonly components: readonly [{
30
+ readonly internalType: "address";
31
+ readonly name: "holder";
32
+ readonly type: "address";
33
+ }, {
34
+ readonly internalType: "address";
35
+ readonly name: "payee";
36
+ readonly type: "address";
37
+ }, {
38
+ readonly internalType: "uint256";
39
+ readonly name: "maxClearAmount";
40
+ readonly type: "uint256";
41
+ }, {
42
+ readonly internalType: "bytes32";
43
+ readonly name: "resourceHash";
44
+ readonly type: "bytes32";
45
+ }, {
46
+ readonly internalType: "uint48";
47
+ readonly name: "validAfter";
48
+ readonly type: "uint48";
49
+ }, {
50
+ readonly internalType: "uint48";
51
+ readonly name: "validBefore";
52
+ readonly type: "uint48";
53
+ }, {
54
+ readonly internalType: "bytes32";
55
+ readonly name: "nonce";
56
+ readonly type: "bytes32";
57
+ }, {
58
+ readonly internalType: "bytes32";
59
+ readonly name: "encryptedAmountHash";
60
+ readonly type: "bytes32";
61
+ }];
62
+ readonly internalType: "struct FHEToken.ConfidentialPayment";
63
+ readonly name: "p";
64
+ readonly type: "tuple";
65
+ }, {
66
+ readonly internalType: "externalEuint64";
67
+ readonly name: "encryptedAmountInput";
68
+ readonly type: "bytes32";
69
+ }, {
70
+ readonly internalType: "bytes";
71
+ readonly name: "inputProof";
72
+ readonly type: "bytes";
73
+ }, {
74
+ readonly internalType: "bytes";
75
+ readonly name: "sig";
76
+ readonly type: "bytes";
77
+ }];
78
+ readonly name: "confidentialTransferWithAuthorization";
79
+ readonly outputs: readonly [{
80
+ readonly internalType: "euint64";
81
+ readonly name: "transferred";
82
+ readonly type: "bytes32";
83
+ }];
84
+ readonly stateMutability: "nonpayable";
85
+ readonly type: "function";
86
+ }, {
87
+ readonly inputs: readonly [{
88
+ readonly internalType: "address";
89
+ readonly name: "to";
90
+ readonly type: "address";
91
+ }, {
92
+ readonly internalType: "uint256";
93
+ readonly name: "amount";
94
+ readonly type: "uint256";
95
+ }];
96
+ readonly name: "wrap";
97
+ readonly outputs: readonly [];
98
+ readonly stateMutability: "nonpayable";
99
+ readonly type: "function";
100
+ }, {
101
+ readonly inputs: readonly [{
102
+ readonly internalType: "address";
103
+ readonly name: "from";
104
+ readonly type: "address";
105
+ }, {
106
+ readonly internalType: "address";
107
+ readonly name: "to";
108
+ readonly type: "address";
109
+ }, {
110
+ readonly internalType: "bytes32";
111
+ readonly name: "encryptedAmountInput";
112
+ readonly type: "bytes32";
113
+ }, {
114
+ readonly internalType: "bytes";
115
+ readonly name: "inputProof";
116
+ readonly type: "bytes";
117
+ }];
118
+ readonly name: "unwrap";
119
+ readonly outputs: readonly [];
120
+ readonly stateMutability: "nonpayable";
121
+ readonly type: "function";
122
+ }, {
123
+ readonly anonymous: false;
124
+ readonly inputs: readonly [{
125
+ readonly indexed: true;
126
+ readonly internalType: "address";
127
+ readonly name: "holder";
128
+ readonly type: "address";
129
+ }, {
130
+ readonly indexed: true;
131
+ readonly internalType: "address";
132
+ readonly name: "payee";
133
+ readonly type: "address";
134
+ }, {
135
+ readonly indexed: false;
136
+ readonly internalType: "uint256";
137
+ readonly name: "maxClearAmount";
138
+ readonly type: "uint256";
139
+ }, {
140
+ readonly indexed: true;
141
+ readonly internalType: "bytes32";
142
+ readonly name: "resourceHash";
143
+ readonly type: "bytes32";
144
+ }, {
145
+ readonly indexed: false;
146
+ readonly internalType: "bytes32";
147
+ readonly name: "nonce";
148
+ readonly type: "bytes32";
149
+ }, {
150
+ readonly indexed: false;
151
+ readonly internalType: "bytes32";
152
+ readonly name: "transferredAmount";
153
+ readonly type: "bytes32";
154
+ }];
155
+ readonly name: "ConfidentialPaymentExecuted";
156
+ readonly type: "event";
157
+ }, {
158
+ readonly inputs: readonly [{
159
+ readonly internalType: "address";
160
+ readonly name: "";
161
+ readonly type: "address";
162
+ }, {
163
+ readonly internalType: "bytes32";
164
+ readonly name: "";
165
+ readonly type: "bytes32";
166
+ }];
167
+ readonly name: "usedNonces";
168
+ readonly outputs: readonly [{
169
+ readonly internalType: "bool";
170
+ readonly name: "";
171
+ readonly type: "bool";
172
+ }];
173
+ readonly stateMutability: "view";
174
+ readonly type: "function";
175
+ }, {
176
+ readonly inputs: readonly [{
177
+ readonly internalType: "address";
178
+ readonly name: "account";
179
+ readonly type: "address";
180
+ }];
181
+ readonly name: "observer";
182
+ readonly outputs: readonly [{
183
+ readonly internalType: "address";
184
+ readonly name: "";
185
+ readonly type: "address";
186
+ }];
187
+ readonly stateMutability: "view";
188
+ readonly type: "function";
189
+ }, {
190
+ readonly inputs: readonly [{
191
+ readonly internalType: "address";
192
+ readonly name: "account";
193
+ readonly type: "address";
194
+ }, {
195
+ readonly internalType: "address";
196
+ readonly name: "newObserver";
197
+ readonly type: "address";
198
+ }];
199
+ readonly name: "setObserver";
200
+ readonly outputs: readonly [];
201
+ readonly stateMutability: "nonpayable";
202
+ readonly type: "function";
203
+ }];
204
+
205
+ declare const confidentialPaymentTypes: {
206
+ readonly ConfidentialPayment: readonly [{
207
+ readonly name: "holder";
208
+ readonly type: "address";
209
+ }, {
210
+ readonly name: "payee";
211
+ readonly type: "address";
212
+ }, {
213
+ readonly name: "maxClearAmount";
214
+ readonly type: "uint256";
215
+ }, {
216
+ readonly name: "resourceHash";
217
+ readonly type: "bytes32";
218
+ }, {
219
+ readonly name: "validAfter";
220
+ readonly type: "uint48";
221
+ }, {
222
+ readonly name: "validBefore";
223
+ readonly type: "uint48";
224
+ }, {
225
+ readonly name: "nonce";
226
+ readonly type: "bytes32";
227
+ }, {
228
+ readonly name: "encryptedAmountHash";
229
+ readonly type: "bytes32";
230
+ }];
231
+ };
232
+ declare const confidentialErrorCodes: {
233
+ readonly observerNotAuthorized: "observer_not_authorized";
234
+ };
235
+ type ConfidentialErrorCode = (typeof confidentialErrorCodes)[keyof typeof confidentialErrorCodes];
236
+
237
+ declare function createNonce(): `0x${string}`;
238
+ declare function hashEncryptedAmountInput(encryptedAmountInput: `0x${string}`): `0x${string}`;
239
+ declare function normalizeAmount(amount: string | number | bigint): string;
240
+
7
241
  type RelayerInstance = Awaited<ReturnType<typeof createInstance>>;
8
242
  type RelayerSigner = {
9
243
  address: string;
@@ -21,13 +255,13 @@ type RelayerSigner = {
21
255
  }) => Promise<string>);
22
256
  };
23
257
 
24
- declare function createRelayerInstance(config: FhevmInstanceConfig): Promise<RelayerInstance>;
258
+ declare function createRelayer(config: FhevmInstanceConfig): Promise<RelayerInstance>;
25
259
 
26
260
  declare function createEncryptedAmountInput(relayer: RelayerInstance, contractAddress: string, senderAddress: string, amount: number): Promise<{
27
261
  handle: `0x${string}`;
28
262
  inputProof: `0x${string}`;
29
263
  }>;
30
- declare function userDecryptEuint64(relayer: RelayerInstance, handle: string, contractAddress: string, signer: RelayerSigner, options?: {
264
+ declare function decryptEuint64(relayer: RelayerInstance, handle: string, contractAddress: string, signer: RelayerSigner, options?: {
31
265
  durationDays?: string;
32
266
  startTimestamp?: string;
33
267
  }): Promise<bigint>;
@@ -36,7 +270,7 @@ declare function publicDecrypt(relayer: RelayerInstance, handles: string[]): Pro
36
270
  decryptionProof: string;
37
271
  }>;
38
272
 
39
- type ConfidentialTransferAmount = {
273
+ type TransferAmount = {
40
274
  holder: `0x${string}`;
41
275
  payee: `0x${string}`;
42
276
  maxClearAmount: bigint;
@@ -45,7 +279,7 @@ type ConfidentialTransferAmount = {
45
279
  handle: `0x${string}`;
46
280
  amount?: bigint;
47
281
  };
48
- type ViewConfidentialTransferOptions = {
282
+ type TransferQueryOptions = {
49
283
  rpcUrl: string;
50
284
  tokenAddress: `0x${string}`;
51
285
  txHash: `0x${string}`;
@@ -55,7 +289,7 @@ type ViewConfidentialTransferOptions = {
55
289
  signer?: RelayerSigner;
56
290
  decrypt?: boolean;
57
291
  };
58
- declare function viewConfidentialTransferAmounts(options: ViewConfidentialTransferOptions): Promise<ConfidentialTransferAmount[]>;
292
+ declare function getTransferAmounts(options: TransferQueryOptions): Promise<TransferAmount[]>;
59
293
 
60
294
  type TokenWriteSigner = RelayerSigner & {
61
295
  writeContract?: (args: {
@@ -65,7 +299,7 @@ type TokenWriteSigner = RelayerSigner & {
65
299
  args: readonly unknown[];
66
300
  }) => Promise<`0x${string}`>;
67
301
  };
68
- type ConfidentialTokenConfig = {
302
+ type ConfidentialTokenOptions = {
69
303
  rpcUrl: string;
70
304
  tokenAddress: `0x${string}`;
71
305
  relayer: RelayerInstance;
@@ -76,7 +310,7 @@ declare class ConfidentialToken {
76
310
  private readonly tokenAddress;
77
311
  private readonly relayer;
78
312
  private readonly signer;
79
- constructor(config: ConfidentialTokenConfig);
313
+ constructor(config: ConfidentialTokenOptions);
80
314
  balanceOf(account?: `0x${string}`): Promise<bigint>;
81
315
  setObserver(account: `0x${string}`, observer: `0x${string}`): Promise<`0x${string}`>;
82
316
  transfer(to: `0x${string}`, amount: number): Promise<`0x${string}`>;
@@ -84,4 +318,41 @@ declare class ConfidentialToken {
84
318
  unwrap(from: `0x${string}`, to: `0x${string}`, amount: number): Promise<`0x${string}`>;
85
319
  }
86
320
 
87
- export { ConfidentialToken, type ConfidentialTokenConfig, type ConfidentialTransferAmount, type RelayerInstance, type RelayerSigner, type ViewConfidentialTransferOptions, ConfidentialToken as confidentialToken, confidentialTokenAbi, createEncryptedAmountInput, createRelayerInstance, publicDecrypt, userDecryptEuint64, viewConfidentialTransferAmounts };
321
+ type ConfidentialPaymentAuthorization = {
322
+ holder: `0x${string}`;
323
+ payee: `0x${string}`;
324
+ maxClearAmount: string;
325
+ resourceHash: `0x${string}`;
326
+ validAfter: string;
327
+ validBefore: string;
328
+ nonce: `0x${string}`;
329
+ encryptedAmountHash: `0x${string}`;
330
+ };
331
+ type ConfidentialPaymentPayload = {
332
+ authorization: ConfidentialPaymentAuthorization;
333
+ signature: `0x${string}`;
334
+ encryptedAmountInput: `0x${string}`;
335
+ inputProof: `0x${string}`;
336
+ };
337
+ type ConfidentialRequirementsExtra = {
338
+ eip712: {
339
+ name: string;
340
+ version: string;
341
+ };
342
+ confidential?: {
343
+ maxClearAmount?: string;
344
+ resourceHash?: `0x${string}`;
345
+ batcherAddress?: `0x${string}`;
346
+ };
347
+ };
348
+ type ConfidentialPaymentInput = {
349
+ encryptedAmountInput: `0x${string}`;
350
+ inputProof: `0x${string}`;
351
+ maxClearAmount?: string;
352
+ resourceHash?: `0x${string}`;
353
+ validAfter?: number;
354
+ validBefore?: number;
355
+ nonce?: `0x${string}`;
356
+ };
357
+
358
+ export { type ConfidentialErrorCode, type ConfidentialPaymentAuthorization, type ConfidentialPaymentInput, type ConfidentialPaymentPayload, type ConfidentialRequirementsExtra, ConfidentialToken, type ConfidentialTokenOptions, type RelayerInstance, type RelayerSigner, type TransferAmount, type TransferQueryOptions, confidentialErrorCodes, confidentialPaymentTypes, confidentialTokenAbi, createEncryptedAmountInput, createNonce, createRelayer, decryptEuint64, getTransferAmounts, hashEncryptedAmountInput, normalizeAmount, publicDecrypt };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,243 @@
1
- import { c as confidentialTokenAbi } from './types-I3K7qzdc.js';
2
- export { C as ConfidentialErrorCode, e as ConfidentialPaymentAuthorization, i as ConfidentialPaymentInput, f as ConfidentialPaymentPayload, g as ConfidentialRequirementsExtra, b as confidentialErrorCodes, a as confidentialPaymentTypes, d as createNonce, h as hashEncryptedAmountInput, n as normalizeAmount } from './types-I3K7qzdc.js';
3
1
  import { FhevmInstanceConfig, createInstance } from '@zama-fhe/relayer-sdk/node';
4
2
  export { FhevmInstanceConfig, SepoliaConfig } from '@zama-fhe/relayer-sdk/node';
5
3
  export * from '@x402/core/types';
6
4
 
5
+ declare const confidentialTokenAbi: readonly [{
6
+ readonly inputs: readonly [{
7
+ readonly internalType: "address";
8
+ readonly name: "to";
9
+ readonly type: "address";
10
+ }, {
11
+ readonly internalType: "bytes32";
12
+ readonly name: "encryptedAmountInput";
13
+ readonly type: "bytes32";
14
+ }, {
15
+ readonly internalType: "bytes";
16
+ readonly name: "inputProof";
17
+ readonly type: "bytes";
18
+ }];
19
+ readonly name: "confidentialTransfer";
20
+ readonly outputs: readonly [{
21
+ readonly internalType: "euint64";
22
+ readonly name: "transferred";
23
+ readonly type: "bytes32";
24
+ }];
25
+ readonly stateMutability: "nonpayable";
26
+ readonly type: "function";
27
+ }, {
28
+ readonly inputs: readonly [{
29
+ readonly components: readonly [{
30
+ readonly internalType: "address";
31
+ readonly name: "holder";
32
+ readonly type: "address";
33
+ }, {
34
+ readonly internalType: "address";
35
+ readonly name: "payee";
36
+ readonly type: "address";
37
+ }, {
38
+ readonly internalType: "uint256";
39
+ readonly name: "maxClearAmount";
40
+ readonly type: "uint256";
41
+ }, {
42
+ readonly internalType: "bytes32";
43
+ readonly name: "resourceHash";
44
+ readonly type: "bytes32";
45
+ }, {
46
+ readonly internalType: "uint48";
47
+ readonly name: "validAfter";
48
+ readonly type: "uint48";
49
+ }, {
50
+ readonly internalType: "uint48";
51
+ readonly name: "validBefore";
52
+ readonly type: "uint48";
53
+ }, {
54
+ readonly internalType: "bytes32";
55
+ readonly name: "nonce";
56
+ readonly type: "bytes32";
57
+ }, {
58
+ readonly internalType: "bytes32";
59
+ readonly name: "encryptedAmountHash";
60
+ readonly type: "bytes32";
61
+ }];
62
+ readonly internalType: "struct FHEToken.ConfidentialPayment";
63
+ readonly name: "p";
64
+ readonly type: "tuple";
65
+ }, {
66
+ readonly internalType: "externalEuint64";
67
+ readonly name: "encryptedAmountInput";
68
+ readonly type: "bytes32";
69
+ }, {
70
+ readonly internalType: "bytes";
71
+ readonly name: "inputProof";
72
+ readonly type: "bytes";
73
+ }, {
74
+ readonly internalType: "bytes";
75
+ readonly name: "sig";
76
+ readonly type: "bytes";
77
+ }];
78
+ readonly name: "confidentialTransferWithAuthorization";
79
+ readonly outputs: readonly [{
80
+ readonly internalType: "euint64";
81
+ readonly name: "transferred";
82
+ readonly type: "bytes32";
83
+ }];
84
+ readonly stateMutability: "nonpayable";
85
+ readonly type: "function";
86
+ }, {
87
+ readonly inputs: readonly [{
88
+ readonly internalType: "address";
89
+ readonly name: "to";
90
+ readonly type: "address";
91
+ }, {
92
+ readonly internalType: "uint256";
93
+ readonly name: "amount";
94
+ readonly type: "uint256";
95
+ }];
96
+ readonly name: "wrap";
97
+ readonly outputs: readonly [];
98
+ readonly stateMutability: "nonpayable";
99
+ readonly type: "function";
100
+ }, {
101
+ readonly inputs: readonly [{
102
+ readonly internalType: "address";
103
+ readonly name: "from";
104
+ readonly type: "address";
105
+ }, {
106
+ readonly internalType: "address";
107
+ readonly name: "to";
108
+ readonly type: "address";
109
+ }, {
110
+ readonly internalType: "bytes32";
111
+ readonly name: "encryptedAmountInput";
112
+ readonly type: "bytes32";
113
+ }, {
114
+ readonly internalType: "bytes";
115
+ readonly name: "inputProof";
116
+ readonly type: "bytes";
117
+ }];
118
+ readonly name: "unwrap";
119
+ readonly outputs: readonly [];
120
+ readonly stateMutability: "nonpayable";
121
+ readonly type: "function";
122
+ }, {
123
+ readonly anonymous: false;
124
+ readonly inputs: readonly [{
125
+ readonly indexed: true;
126
+ readonly internalType: "address";
127
+ readonly name: "holder";
128
+ readonly type: "address";
129
+ }, {
130
+ readonly indexed: true;
131
+ readonly internalType: "address";
132
+ readonly name: "payee";
133
+ readonly type: "address";
134
+ }, {
135
+ readonly indexed: false;
136
+ readonly internalType: "uint256";
137
+ readonly name: "maxClearAmount";
138
+ readonly type: "uint256";
139
+ }, {
140
+ readonly indexed: true;
141
+ readonly internalType: "bytes32";
142
+ readonly name: "resourceHash";
143
+ readonly type: "bytes32";
144
+ }, {
145
+ readonly indexed: false;
146
+ readonly internalType: "bytes32";
147
+ readonly name: "nonce";
148
+ readonly type: "bytes32";
149
+ }, {
150
+ readonly indexed: false;
151
+ readonly internalType: "bytes32";
152
+ readonly name: "transferredAmount";
153
+ readonly type: "bytes32";
154
+ }];
155
+ readonly name: "ConfidentialPaymentExecuted";
156
+ readonly type: "event";
157
+ }, {
158
+ readonly inputs: readonly [{
159
+ readonly internalType: "address";
160
+ readonly name: "";
161
+ readonly type: "address";
162
+ }, {
163
+ readonly internalType: "bytes32";
164
+ readonly name: "";
165
+ readonly type: "bytes32";
166
+ }];
167
+ readonly name: "usedNonces";
168
+ readonly outputs: readonly [{
169
+ readonly internalType: "bool";
170
+ readonly name: "";
171
+ readonly type: "bool";
172
+ }];
173
+ readonly stateMutability: "view";
174
+ readonly type: "function";
175
+ }, {
176
+ readonly inputs: readonly [{
177
+ readonly internalType: "address";
178
+ readonly name: "account";
179
+ readonly type: "address";
180
+ }];
181
+ readonly name: "observer";
182
+ readonly outputs: readonly [{
183
+ readonly internalType: "address";
184
+ readonly name: "";
185
+ readonly type: "address";
186
+ }];
187
+ readonly stateMutability: "view";
188
+ readonly type: "function";
189
+ }, {
190
+ readonly inputs: readonly [{
191
+ readonly internalType: "address";
192
+ readonly name: "account";
193
+ readonly type: "address";
194
+ }, {
195
+ readonly internalType: "address";
196
+ readonly name: "newObserver";
197
+ readonly type: "address";
198
+ }];
199
+ readonly name: "setObserver";
200
+ readonly outputs: readonly [];
201
+ readonly stateMutability: "nonpayable";
202
+ readonly type: "function";
203
+ }];
204
+
205
+ declare const confidentialPaymentTypes: {
206
+ readonly ConfidentialPayment: readonly [{
207
+ readonly name: "holder";
208
+ readonly type: "address";
209
+ }, {
210
+ readonly name: "payee";
211
+ readonly type: "address";
212
+ }, {
213
+ readonly name: "maxClearAmount";
214
+ readonly type: "uint256";
215
+ }, {
216
+ readonly name: "resourceHash";
217
+ readonly type: "bytes32";
218
+ }, {
219
+ readonly name: "validAfter";
220
+ readonly type: "uint48";
221
+ }, {
222
+ readonly name: "validBefore";
223
+ readonly type: "uint48";
224
+ }, {
225
+ readonly name: "nonce";
226
+ readonly type: "bytes32";
227
+ }, {
228
+ readonly name: "encryptedAmountHash";
229
+ readonly type: "bytes32";
230
+ }];
231
+ };
232
+ declare const confidentialErrorCodes: {
233
+ readonly observerNotAuthorized: "observer_not_authorized";
234
+ };
235
+ type ConfidentialErrorCode = (typeof confidentialErrorCodes)[keyof typeof confidentialErrorCodes];
236
+
237
+ declare function createNonce(): `0x${string}`;
238
+ declare function hashEncryptedAmountInput(encryptedAmountInput: `0x${string}`): `0x${string}`;
239
+ declare function normalizeAmount(amount: string | number | bigint): string;
240
+
7
241
  type RelayerInstance = Awaited<ReturnType<typeof createInstance>>;
8
242
  type RelayerSigner = {
9
243
  address: string;
@@ -21,13 +255,13 @@ type RelayerSigner = {
21
255
  }) => Promise<string>);
22
256
  };
23
257
 
24
- declare function createRelayerInstance(config: FhevmInstanceConfig): Promise<RelayerInstance>;
258
+ declare function createRelayer(config: FhevmInstanceConfig): Promise<RelayerInstance>;
25
259
 
26
260
  declare function createEncryptedAmountInput(relayer: RelayerInstance, contractAddress: string, senderAddress: string, amount: number): Promise<{
27
261
  handle: `0x${string}`;
28
262
  inputProof: `0x${string}`;
29
263
  }>;
30
- declare function userDecryptEuint64(relayer: RelayerInstance, handle: string, contractAddress: string, signer: RelayerSigner, options?: {
264
+ declare function decryptEuint64(relayer: RelayerInstance, handle: string, contractAddress: string, signer: RelayerSigner, options?: {
31
265
  durationDays?: string;
32
266
  startTimestamp?: string;
33
267
  }): Promise<bigint>;
@@ -36,7 +270,7 @@ declare function publicDecrypt(relayer: RelayerInstance, handles: string[]): Pro
36
270
  decryptionProof: string;
37
271
  }>;
38
272
 
39
- type ConfidentialTransferAmount = {
273
+ type TransferAmount = {
40
274
  holder: `0x${string}`;
41
275
  payee: `0x${string}`;
42
276
  maxClearAmount: bigint;
@@ -45,7 +279,7 @@ type ConfidentialTransferAmount = {
45
279
  handle: `0x${string}`;
46
280
  amount?: bigint;
47
281
  };
48
- type ViewConfidentialTransferOptions = {
282
+ type TransferQueryOptions = {
49
283
  rpcUrl: string;
50
284
  tokenAddress: `0x${string}`;
51
285
  txHash: `0x${string}`;
@@ -55,7 +289,7 @@ type ViewConfidentialTransferOptions = {
55
289
  signer?: RelayerSigner;
56
290
  decrypt?: boolean;
57
291
  };
58
- declare function viewConfidentialTransferAmounts(options: ViewConfidentialTransferOptions): Promise<ConfidentialTransferAmount[]>;
292
+ declare function getTransferAmounts(options: TransferQueryOptions): Promise<TransferAmount[]>;
59
293
 
60
294
  type TokenWriteSigner = RelayerSigner & {
61
295
  writeContract?: (args: {
@@ -65,7 +299,7 @@ type TokenWriteSigner = RelayerSigner & {
65
299
  args: readonly unknown[];
66
300
  }) => Promise<`0x${string}`>;
67
301
  };
68
- type ConfidentialTokenConfig = {
302
+ type ConfidentialTokenOptions = {
69
303
  rpcUrl: string;
70
304
  tokenAddress: `0x${string}`;
71
305
  relayer: RelayerInstance;
@@ -76,7 +310,7 @@ declare class ConfidentialToken {
76
310
  private readonly tokenAddress;
77
311
  private readonly relayer;
78
312
  private readonly signer;
79
- constructor(config: ConfidentialTokenConfig);
313
+ constructor(config: ConfidentialTokenOptions);
80
314
  balanceOf(account?: `0x${string}`): Promise<bigint>;
81
315
  setObserver(account: `0x${string}`, observer: `0x${string}`): Promise<`0x${string}`>;
82
316
  transfer(to: `0x${string}`, amount: number): Promise<`0x${string}`>;
@@ -84,4 +318,41 @@ declare class ConfidentialToken {
84
318
  unwrap(from: `0x${string}`, to: `0x${string}`, amount: number): Promise<`0x${string}`>;
85
319
  }
86
320
 
87
- export { ConfidentialToken, type ConfidentialTokenConfig, type ConfidentialTransferAmount, type RelayerInstance, type RelayerSigner, type ViewConfidentialTransferOptions, ConfidentialToken as confidentialToken, confidentialTokenAbi, createEncryptedAmountInput, createRelayerInstance, publicDecrypt, userDecryptEuint64, viewConfidentialTransferAmounts };
321
+ type ConfidentialPaymentAuthorization = {
322
+ holder: `0x${string}`;
323
+ payee: `0x${string}`;
324
+ maxClearAmount: string;
325
+ resourceHash: `0x${string}`;
326
+ validAfter: string;
327
+ validBefore: string;
328
+ nonce: `0x${string}`;
329
+ encryptedAmountHash: `0x${string}`;
330
+ };
331
+ type ConfidentialPaymentPayload = {
332
+ authorization: ConfidentialPaymentAuthorization;
333
+ signature: `0x${string}`;
334
+ encryptedAmountInput: `0x${string}`;
335
+ inputProof: `0x${string}`;
336
+ };
337
+ type ConfidentialRequirementsExtra = {
338
+ eip712: {
339
+ name: string;
340
+ version: string;
341
+ };
342
+ confidential?: {
343
+ maxClearAmount?: string;
344
+ resourceHash?: `0x${string}`;
345
+ batcherAddress?: `0x${string}`;
346
+ };
347
+ };
348
+ type ConfidentialPaymentInput = {
349
+ encryptedAmountInput: `0x${string}`;
350
+ inputProof: `0x${string}`;
351
+ maxClearAmount?: string;
352
+ resourceHash?: `0x${string}`;
353
+ validAfter?: number;
354
+ validBefore?: number;
355
+ nonce?: `0x${string}`;
356
+ };
357
+
358
+ export { type ConfidentialErrorCode, type ConfidentialPaymentAuthorization, type ConfidentialPaymentInput, type ConfidentialPaymentPayload, type ConfidentialRequirementsExtra, ConfidentialToken, type ConfidentialTokenOptions, type RelayerInstance, type RelayerSigner, type TransferAmount, type TransferQueryOptions, confidentialErrorCodes, confidentialPaymentTypes, confidentialTokenAbi, createEncryptedAmountInput, createNonce, createRelayer, decryptEuint64, getTransferAmounts, hashEncryptedAmountInput, normalizeAmount, publicDecrypt };
package/dist/index.js CHANGED
@@ -24,20 +24,19 @@ __export(index_exports, {
24
24
  SepoliaConfig: () => import_node.SepoliaConfig,
25
25
  confidentialErrorCodes: () => confidentialErrorCodes,
26
26
  confidentialPaymentTypes: () => confidentialPaymentTypes,
27
- confidentialToken: () => ConfidentialToken,
28
27
  confidentialTokenAbi: () => confidentialTokenAbi,
29
28
  createEncryptedAmountInput: () => createEncryptedAmountInput,
30
29
  createNonce: () => createNonce,
31
- createRelayerInstance: () => createRelayerInstance,
30
+ createRelayer: () => createRelayer,
31
+ decryptEuint64: () => decryptEuint64,
32
+ getTransferAmounts: () => getTransferAmounts,
32
33
  hashEncryptedAmountInput: () => hashEncryptedAmountInput,
33
34
  normalizeAmount: () => normalizeAmount,
34
- publicDecrypt: () => publicDecrypt,
35
- userDecryptEuint64: () => userDecryptEuint64,
36
- viewConfidentialTransferAmounts: () => viewConfidentialTransferAmounts
35
+ publicDecrypt: () => publicDecrypt
37
36
  });
38
37
  module.exports = __toCommonJS(index_exports);
39
38
 
40
- // src/abi.ts
39
+ // src/core/abi.ts
41
40
  var confidentialTokenAbi = [
42
41
  {
43
42
  inputs: [
@@ -140,7 +139,7 @@ var confidentialTokenAbi = [
140
139
  }
141
140
  ];
142
141
 
143
- // src/constants.ts
142
+ // src/core/constants.ts
144
143
  var confidentialPaymentTypes = {
145
144
  ConfidentialPayment: [
146
145
  { name: "holder", type: "address" },
@@ -157,7 +156,7 @@ var confidentialErrorCodes = {
157
156
  observerNotAuthorized: "observer_not_authorized"
158
157
  };
159
158
 
160
- // src/utils.ts
159
+ // src/core/utils.ts
161
160
  var import_viem = require("viem");
162
161
  function createNonce() {
163
162
  const cryptoObj = typeof globalThis.crypto !== "undefined" ? globalThis.crypto : globalThis.crypto;
@@ -184,10 +183,10 @@ function normalizeAmount(amount) {
184
183
  return amount.toString();
185
184
  }
186
185
 
187
- // src/relayer.ts
186
+ // src/relayer/index.ts
188
187
  var import_node = require("@zama-fhe/relayer-sdk/node");
189
188
  var import_viem2 = require("viem");
190
- async function createRelayerInstance(config) {
189
+ async function createRelayer(config) {
191
190
  const instance = await (0, import_node.createInstance)(config);
192
191
  if (typeof config.network === "string") {
193
192
  instance.network = config.network;
@@ -205,7 +204,7 @@ async function createEncryptedAmountInput(relayer, contractAddress, senderAddres
205
204
  inputProof
206
205
  };
207
206
  }
208
- async function userDecryptEuint64(relayer, handle, contractAddress, signer, options) {
207
+ async function decryptEuint64(relayer, handle, contractAddress, signer, options) {
209
208
  const keypair = relayer.generateKeypair();
210
209
  const startTimestamp = options?.startTimestamp ?? Math.floor(Date.now() / 1e3).toString();
211
210
  const durationDays = options?.durationDays ?? "10";
@@ -239,9 +238,9 @@ async function publicDecrypt(relayer, handles) {
239
238
  };
240
239
  }
241
240
 
242
- // src/transfer.ts
241
+ // src/token/transfer.ts
243
242
  var import_viem3 = require("viem");
244
- async function viewConfidentialTransferAmounts(options) {
243
+ async function getTransferAmounts(options) {
245
244
  if (!(0, import_viem3.isAddress)(options.tokenAddress)) {
246
245
  throw new Error(`Invalid token address: ${options.tokenAddress}`);
247
246
  }
@@ -314,7 +313,7 @@ async function viewConfidentialTransferAmounts(options) {
314
313
  throw new Error(confidentialErrorCodes.observerNotAuthorized);
315
314
  }
316
315
  }
317
- entry.amount = await userDecryptEuint64(
316
+ entry.amount = await decryptEuint64(
318
317
  options.relayer,
319
318
  entry.handle,
320
319
  tokenAddress,
@@ -331,13 +330,13 @@ async function viewConfidentialTransferAmounts(options) {
331
330
  return transfers;
332
331
  }
333
332
 
334
- // src/token.ts
333
+ // src/token/token.ts
335
334
  var import_viem6 = require("viem");
336
335
 
337
- // src/balance.ts
336
+ // src/token/balance.ts
338
337
  var import_viem4 = require("viem");
339
338
  var ZERO_HANDLE = "0x" + "00".repeat(32);
340
- async function viewConfidentialBalance(options) {
339
+ async function readBalance(options) {
341
340
  if (!(0, import_viem4.isAddress)(options.tokenAddress)) {
342
341
  throw new Error(`Invalid token address: ${options.tokenAddress}`);
343
342
  }
@@ -383,7 +382,7 @@ async function viewConfidentialBalance(options) {
383
382
  if (handle === ZERO_HANDLE) {
384
383
  return { handle, balance: 0n };
385
384
  }
386
- const balance = await userDecryptEuint64(
385
+ const balance = await decryptEuint64(
387
386
  options.relayer,
388
387
  handle,
389
388
  options.tokenAddress,
@@ -392,7 +391,7 @@ async function viewConfidentialBalance(options) {
392
391
  return { handle, balance };
393
392
  }
394
393
 
395
- // src/observer.ts
394
+ // src/token/observer.ts
396
395
  var import_viem5 = require("viem");
397
396
  async function setObserver(options) {
398
397
  if (!(0, import_viem5.isAddress)(options.tokenAddress)) {
@@ -425,7 +424,7 @@ async function setObserver(options) {
425
424
  });
426
425
  }
427
426
 
428
- // src/token.ts
427
+ // src/token/token.ts
429
428
  function assertAddress(value, label) {
430
429
  if (!(0, import_viem6.isAddress)(value)) {
431
430
  throw new Error(`Invalid ${label}: ${value}`);
@@ -446,7 +445,7 @@ var ConfidentialToken = class {
446
445
  this.signer = config.signer;
447
446
  }
448
447
  async balanceOf(account) {
449
- const result = await viewConfidentialBalance({
448
+ const result = await readBalance({
450
449
  rpcUrl: this.rpcUrl,
451
450
  tokenAddress: this.tokenAddress,
452
451
  account,
@@ -528,14 +527,13 @@ var ConfidentialToken = class {
528
527
  SepoliaConfig,
529
528
  confidentialErrorCodes,
530
529
  confidentialPaymentTypes,
531
- confidentialToken,
532
530
  confidentialTokenAbi,
533
531
  createEncryptedAmountInput,
534
532
  createNonce,
535
- createRelayerInstance,
533
+ createRelayer,
534
+ decryptEuint64,
535
+ getTransferAmounts,
536
536
  hashEncryptedAmountInput,
537
537
  normalizeAmount,
538
- publicDecrypt,
539
- userDecryptEuint64,
540
- viewConfidentialTransferAmounts
538
+ publicDecrypt
541
539
  });
package/dist/index.mjs CHANGED
@@ -1,16 +1,154 @@
1
- import {
2
- confidentialErrorCodes,
3
- confidentialPaymentTypes,
4
- confidentialTokenAbi,
5
- createNonce,
6
- hashEncryptedAmountInput,
7
- normalizeAmount
8
- } from "./chunk-7OLOM2AQ.mjs";
1
+ // src/core/abi.ts
2
+ var confidentialTokenAbi = [
3
+ {
4
+ inputs: [
5
+ { internalType: "address", name: "to", type: "address" },
6
+ { internalType: "bytes32", name: "encryptedAmountInput", type: "bytes32" },
7
+ { internalType: "bytes", name: "inputProof", type: "bytes" }
8
+ ],
9
+ name: "confidentialTransfer",
10
+ outputs: [{ internalType: "euint64", name: "transferred", type: "bytes32" }],
11
+ stateMutability: "nonpayable",
12
+ type: "function"
13
+ },
14
+ {
15
+ inputs: [
16
+ {
17
+ components: [
18
+ { internalType: "address", name: "holder", type: "address" },
19
+ { internalType: "address", name: "payee", type: "address" },
20
+ { internalType: "uint256", name: "maxClearAmount", type: "uint256" },
21
+ { internalType: "bytes32", name: "resourceHash", type: "bytes32" },
22
+ { internalType: "uint48", name: "validAfter", type: "uint48" },
23
+ { internalType: "uint48", name: "validBefore", type: "uint48" },
24
+ { internalType: "bytes32", name: "nonce", type: "bytes32" },
25
+ { internalType: "bytes32", name: "encryptedAmountHash", type: "bytes32" }
26
+ ],
27
+ internalType: "struct FHEToken.ConfidentialPayment",
28
+ name: "p",
29
+ type: "tuple"
30
+ },
31
+ { internalType: "externalEuint64", name: "encryptedAmountInput", type: "bytes32" },
32
+ { internalType: "bytes", name: "inputProof", type: "bytes" },
33
+ { internalType: "bytes", name: "sig", type: "bytes" }
34
+ ],
35
+ name: "confidentialTransferWithAuthorization",
36
+ outputs: [{ internalType: "euint64", name: "transferred", type: "bytes32" }],
37
+ stateMutability: "nonpayable",
38
+ type: "function"
39
+ },
40
+ {
41
+ inputs: [
42
+ { internalType: "address", name: "to", type: "address" },
43
+ { internalType: "uint256", name: "amount", type: "uint256" }
44
+ ],
45
+ name: "wrap",
46
+ outputs: [],
47
+ stateMutability: "nonpayable",
48
+ type: "function"
49
+ },
50
+ {
51
+ inputs: [
52
+ { internalType: "address", name: "from", type: "address" },
53
+ { internalType: "address", name: "to", type: "address" },
54
+ { internalType: "bytes32", name: "encryptedAmountInput", type: "bytes32" },
55
+ { internalType: "bytes", name: "inputProof", type: "bytes" }
56
+ ],
57
+ name: "unwrap",
58
+ outputs: [],
59
+ stateMutability: "nonpayable",
60
+ type: "function"
61
+ },
62
+ {
63
+ anonymous: false,
64
+ inputs: [
65
+ { indexed: true, internalType: "address", name: "holder", type: "address" },
66
+ { indexed: true, internalType: "address", name: "payee", type: "address" },
67
+ { indexed: false, internalType: "uint256", name: "maxClearAmount", type: "uint256" },
68
+ { indexed: true, internalType: "bytes32", name: "resourceHash", type: "bytes32" },
69
+ { indexed: false, internalType: "bytes32", name: "nonce", type: "bytes32" },
70
+ { indexed: false, internalType: "bytes32", name: "transferredAmount", type: "bytes32" }
71
+ ],
72
+ name: "ConfidentialPaymentExecuted",
73
+ type: "event"
74
+ },
75
+ {
76
+ inputs: [
77
+ { internalType: "address", name: "", type: "address" },
78
+ { internalType: "bytes32", name: "", type: "bytes32" }
79
+ ],
80
+ name: "usedNonces",
81
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
82
+ stateMutability: "view",
83
+ type: "function"
84
+ },
85
+ {
86
+ inputs: [{ internalType: "address", name: "account", type: "address" }],
87
+ name: "observer",
88
+ outputs: [{ internalType: "address", name: "", type: "address" }],
89
+ stateMutability: "view",
90
+ type: "function"
91
+ },
92
+ {
93
+ inputs: [
94
+ { internalType: "address", name: "account", type: "address" },
95
+ { internalType: "address", name: "newObserver", type: "address" }
96
+ ],
97
+ name: "setObserver",
98
+ outputs: [],
99
+ stateMutability: "nonpayable",
100
+ type: "function"
101
+ }
102
+ ];
103
+
104
+ // src/core/constants.ts
105
+ var confidentialPaymentTypes = {
106
+ ConfidentialPayment: [
107
+ { name: "holder", type: "address" },
108
+ { name: "payee", type: "address" },
109
+ { name: "maxClearAmount", type: "uint256" },
110
+ { name: "resourceHash", type: "bytes32" },
111
+ { name: "validAfter", type: "uint48" },
112
+ { name: "validBefore", type: "uint48" },
113
+ { name: "nonce", type: "bytes32" },
114
+ { name: "encryptedAmountHash", type: "bytes32" }
115
+ ]
116
+ };
117
+ var confidentialErrorCodes = {
118
+ observerNotAuthorized: "observer_not_authorized"
119
+ };
120
+
121
+ // src/core/utils.ts
122
+ import { encodeAbiParameters, keccak256, toHex } from "viem";
123
+ function createNonce() {
124
+ const cryptoObj = typeof globalThis.crypto !== "undefined" ? globalThis.crypto : globalThis.crypto;
125
+ if (!cryptoObj) {
126
+ throw new Error("Crypto API not available");
127
+ }
128
+ return toHex(cryptoObj.getRandomValues(new Uint8Array(32)));
129
+ }
130
+ function hashEncryptedAmountInput(encryptedAmountInput) {
131
+ return keccak256(
132
+ encodeAbiParameters([{ type: "bytes32" }], [encryptedAmountInput])
133
+ );
134
+ }
135
+ function normalizeAmount(amount) {
136
+ if (typeof amount === "string") {
137
+ return amount;
138
+ }
139
+ if (typeof amount === "number") {
140
+ if (!Number.isFinite(amount)) {
141
+ throw new Error("Invalid amount");
142
+ }
143
+ return Math.trunc(amount).toString();
144
+ }
145
+ return amount.toString();
146
+ }
9
147
 
10
- // src/relayer.ts
148
+ // src/relayer/index.ts
11
149
  import { createInstance, SepoliaConfig } from "@zama-fhe/relayer-sdk/node";
12
- import { getAddress, toHex } from "viem";
13
- async function createRelayerInstance(config) {
150
+ import { getAddress, toHex as toHex2 } from "viem";
151
+ async function createRelayer(config) {
14
152
  const instance = await createInstance(config);
15
153
  if (typeof config.network === "string") {
16
154
  instance.network = config.network;
@@ -21,14 +159,14 @@ async function createEncryptedAmountInput(relayer, contractAddress, senderAddres
21
159
  const normalizedContract = getAddress(contractAddress);
22
160
  const normalizedSender = getAddress(senderAddress);
23
161
  const encrypted = await relayer.createEncryptedInput(normalizedContract, normalizedSender).add64(amount).encrypt();
24
- const handle = typeof encrypted.handles[0] === "string" ? encrypted.handles[0] : toHex(encrypted.handles[0]);
25
- const inputProof = typeof encrypted.inputProof === "string" ? encrypted.inputProof : toHex(encrypted.inputProof);
162
+ const handle = typeof encrypted.handles[0] === "string" ? encrypted.handles[0] : toHex2(encrypted.handles[0]);
163
+ const inputProof = typeof encrypted.inputProof === "string" ? encrypted.inputProof : toHex2(encrypted.inputProof);
26
164
  return {
27
165
  handle,
28
166
  inputProof
29
167
  };
30
168
  }
31
- async function userDecryptEuint64(relayer, handle, contractAddress, signer, options) {
169
+ async function decryptEuint64(relayer, handle, contractAddress, signer, options) {
32
170
  const keypair = relayer.generateKeypair();
33
171
  const startTimestamp = options?.startTimestamp ?? Math.floor(Date.now() / 1e3).toString();
34
172
  const durationDays = options?.durationDays ?? "10";
@@ -62,9 +200,9 @@ async function publicDecrypt(relayer, handles) {
62
200
  };
63
201
  }
64
202
 
65
- // src/transfer.ts
203
+ // src/token/transfer.ts
66
204
  import { createPublicClient, decodeEventLog, getAddress as getAddress2, http, isAddress, isHex, isAddressEqual } from "viem";
67
- async function viewConfidentialTransferAmounts(options) {
205
+ async function getTransferAmounts(options) {
68
206
  if (!isAddress(options.tokenAddress)) {
69
207
  throw new Error(`Invalid token address: ${options.tokenAddress}`);
70
208
  }
@@ -137,7 +275,7 @@ async function viewConfidentialTransferAmounts(options) {
137
275
  throw new Error(confidentialErrorCodes.observerNotAuthorized);
138
276
  }
139
277
  }
140
- entry.amount = await userDecryptEuint64(
278
+ entry.amount = await decryptEuint64(
141
279
  options.relayer,
142
280
  entry.handle,
143
281
  tokenAddress,
@@ -154,13 +292,13 @@ async function viewConfidentialTransferAmounts(options) {
154
292
  return transfers;
155
293
  }
156
294
 
157
- // src/token.ts
295
+ // src/token/token.ts
158
296
  import { getAddress as getAddress5, isAddress as isAddress4 } from "viem";
159
297
 
160
- // src/balance.ts
298
+ // src/token/balance.ts
161
299
  import { createPublicClient as createPublicClient2, getAddress as getAddress3, http as http2, isAddress as isAddress2, isAddressEqual as isAddressEqual2 } from "viem";
162
300
  var ZERO_HANDLE = "0x" + "00".repeat(32);
163
- async function viewConfidentialBalance(options) {
301
+ async function readBalance(options) {
164
302
  if (!isAddress2(options.tokenAddress)) {
165
303
  throw new Error(`Invalid token address: ${options.tokenAddress}`);
166
304
  }
@@ -206,7 +344,7 @@ async function viewConfidentialBalance(options) {
206
344
  if (handle === ZERO_HANDLE) {
207
345
  return { handle, balance: 0n };
208
346
  }
209
- const balance = await userDecryptEuint64(
347
+ const balance = await decryptEuint64(
210
348
  options.relayer,
211
349
  handle,
212
350
  options.tokenAddress,
@@ -215,7 +353,7 @@ async function viewConfidentialBalance(options) {
215
353
  return { handle, balance };
216
354
  }
217
355
 
218
- // src/observer.ts
356
+ // src/token/observer.ts
219
357
  import { createPublicClient as createPublicClient3, getAddress as getAddress4, http as http3, isAddress as isAddress3 } from "viem";
220
358
  async function setObserver(options) {
221
359
  if (!isAddress3(options.tokenAddress)) {
@@ -248,7 +386,7 @@ async function setObserver(options) {
248
386
  });
249
387
  }
250
388
 
251
- // src/token.ts
389
+ // src/token/token.ts
252
390
  function assertAddress(value, label) {
253
391
  if (!isAddress4(value)) {
254
392
  throw new Error(`Invalid ${label}: ${value}`);
@@ -269,7 +407,7 @@ var ConfidentialToken = class {
269
407
  this.signer = config.signer;
270
408
  }
271
409
  async balanceOf(account) {
272
- const result = await viewConfidentialBalance({
410
+ const result = await readBalance({
273
411
  rpcUrl: this.rpcUrl,
274
412
  tokenAddress: this.tokenAddress,
275
413
  account,
@@ -350,14 +488,13 @@ export {
350
488
  SepoliaConfig,
351
489
  confidentialErrorCodes,
352
490
  confidentialPaymentTypes,
353
- ConfidentialToken as confidentialToken,
354
491
  confidentialTokenAbi,
355
492
  createEncryptedAmountInput,
356
493
  createNonce,
357
- createRelayerInstance,
494
+ createRelayer,
495
+ decryptEuint64,
496
+ getTransferAmounts,
358
497
  hashEncryptedAmountInput,
359
498
  normalizeAmount,
360
- publicDecrypt,
361
- userDecryptEuint64,
362
- viewConfidentialTransferAmounts
499
+ publicDecrypt
363
500
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x402z-shared",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -12,17 +12,12 @@
12
12
  "types": "./dist/index.d.ts",
13
13
  "import": "./dist/index.mjs",
14
14
  "require": "./dist/index.js"
15
- },
16
- "./web": {
17
- "types": "./dist/web.d.ts",
18
- "import": "./dist/web.mjs",
19
- "require": "./dist/web.js"
20
15
  }
21
16
  },
22
17
  "dependencies": {
23
18
  "@x402/core": "^2.0.0",
24
19
  "viem": "^2.39.3",
25
- "@zama-fhe/relayer-sdk": "^0.3.0-5"
20
+ "@zama-fhe/relayer-sdk": "0.3.0-8"
26
21
  },
27
22
  "devDependencies": {
28
23
  "jest": "^29.7.0",
@@ -30,7 +25,7 @@
30
25
  "@types/jest": "^29.5.12"
31
26
  },
32
27
  "scripts": {
33
- "build": "tsup src/index.ts src/web.ts --format cjs,esm --dts",
28
+ "build": "tsup src/index.ts --format cjs,esm --dts",
34
29
  "test": "jest"
35
30
  }
36
31
  }