x402z-shared-web 0.0.10 → 0.0.12

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
@@ -20,15 +20,16 @@ pnpm add x402z-shared-web
20
20
  ```ts
21
21
  import {
22
22
  createRelayer,
23
+ getBrowserEthereumProvider,
23
24
  createEncryptedAmountInput,
24
25
  getSepoliaConfig,
25
26
  } from "x402z-shared-web";
26
27
  import type { FhevmInstanceConfig } from "x402z-shared-web";
27
28
 
29
+ const provider = getBrowserEthereumProvider();
28
30
  const relayerConfig: FhevmInstanceConfig = {
29
31
  ...(getSepoliaConfig() as object),
30
- network: window.ethereum,
31
- relayerUrl: "https://relayer.testnet.zama.org",
32
+ network: provider,
32
33
  };
33
34
  const relayer = await createRelayer(relayerConfig);
34
35
  const encrypted = await createEncryptedAmountInput(
@@ -45,12 +46,18 @@ const encrypted = await createEncryptedAmountInput(
45
46
 
46
47
  ```ts
47
48
  import { ConfidentialToken } from "x402z-shared-web";
49
+ import { createWalletClient, custom } from "viem";
50
+ import { createBrowserSigner, getBrowserEthereumProvider } from "x402z-shared-web";
48
51
 
52
+ const provider = getBrowserEthereumProvider();
53
+ const signer = await createBrowserSigner(provider);
54
+ const walletClient = createWalletClient({ transport: custom(provider as any) });
49
55
  const token = new ConfidentialToken({
50
56
  rpcUrl: "https://sepolia.infura.io/v3/...",
51
57
  tokenAddress: "0xToken",
52
58
  relayer,
53
59
  walletClient,
60
+ signer,
54
61
  });
55
62
  const balance = await token.balanceOf("0xWallet");
56
63
  console.log(balance.toString());
@@ -64,13 +71,16 @@ Notes:
64
71
 
65
72
  ```ts
66
73
  import { getTransferAmounts } from "x402z-shared-web";
74
+ import { createBrowserSigner, getBrowserEthereumProvider } from "x402z-shared-web";
67
75
 
76
+ const provider = getBrowserEthereumProvider();
77
+ const signer = await createBrowserSigner(provider);
68
78
  const transfers = await getTransferAmounts({
69
79
  rpcUrl: "https://sepolia.infura.io/v3/...",
70
80
  tokenAddress: "0xToken",
71
81
  txHash: "0xTransactionHash",
72
82
  relayer,
73
- signer: { address, signTypedData },
83
+ signer,
74
84
  });
75
85
  console.log(transfers[0]?.amount?.toString());
76
86
  ```
@@ -83,12 +93,18 @@ Notes:
83
93
 
84
94
  ```ts
85
95
  import { ConfidentialToken } from "x402z-shared-web";
96
+ import { createWalletClient, custom } from "viem";
97
+ import { createBrowserSigner, getBrowserEthereumProvider } from "x402z-shared-web";
86
98
 
99
+ const provider = getBrowserEthereumProvider();
100
+ const signer = await createBrowserSigner(provider);
101
+ const walletClient = createWalletClient({ transport: custom(provider as any) });
87
102
  const token = new ConfidentialToken({
88
103
  rpcUrl: "https://sepolia.infura.io/v3/...",
89
104
  tokenAddress: "0xToken",
90
105
  relayer,
91
106
  walletClient,
107
+ signer,
92
108
  });
93
109
  const txHash = await token.setObserver("0xHolder", "0xObserver");
94
110
  console.log(txHash);
@@ -96,4 +112,6 @@ console.log(txHash);
96
112
 
97
113
  ## Notes
98
114
 
115
+ - Web builds use `@zama-fhe/relayer-sdk/web` (no CDN script tag or bundle).
116
+ - Requires an injected wallet for signing (e.g. MetaMask).
99
117
  - Scheme name: `erc7984-mind-v1`
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import * as relayerBundle from '@zama-fhe/relayer-sdk/bundle';
1
+ import * as relayerWeb from '@zama-fhe/relayer-sdk/web';
2
2
  import { WalletClient } from 'viem';
3
3
  export * from '@x402/core/types';
4
4
 
@@ -119,6 +119,71 @@ declare const confidentialTokenAbi: readonly [{
119
119
  readonly outputs: readonly [];
120
120
  readonly stateMutability: "nonpayable";
121
121
  readonly type: "function";
122
+ }, {
123
+ readonly inputs: readonly [{
124
+ readonly components: readonly [{
125
+ readonly internalType: "address";
126
+ readonly name: "holder";
127
+ readonly type: "address";
128
+ }, {
129
+ readonly internalType: "address";
130
+ readonly name: "to";
131
+ readonly type: "address";
132
+ }, {
133
+ readonly internalType: "uint48";
134
+ readonly name: "validAfter";
135
+ readonly type: "uint48";
136
+ }, {
137
+ readonly internalType: "uint48";
138
+ readonly name: "validBefore";
139
+ readonly type: "uint48";
140
+ }, {
141
+ readonly internalType: "bytes32";
142
+ readonly name: "nonce";
143
+ readonly type: "bytes32";
144
+ }, {
145
+ readonly internalType: "bytes32";
146
+ readonly name: "encryptedAmountHash";
147
+ readonly type: "bytes32";
148
+ }];
149
+ readonly internalType: "struct FHEToken.UnwrapAuthorization";
150
+ readonly name: "p";
151
+ readonly type: "tuple";
152
+ }, {
153
+ readonly internalType: "bytes";
154
+ readonly name: "encryptedAmountInput";
155
+ readonly type: "bytes";
156
+ }, {
157
+ readonly internalType: "bytes";
158
+ readonly name: "inputProof";
159
+ readonly type: "bytes";
160
+ }, {
161
+ readonly internalType: "bytes";
162
+ readonly name: "sig";
163
+ readonly type: "bytes";
164
+ }];
165
+ readonly name: "unwrapWithAuthorization";
166
+ readonly outputs: readonly [];
167
+ readonly stateMutability: "nonpayable";
168
+ readonly type: "function";
169
+ }, {
170
+ readonly inputs: readonly [{
171
+ readonly internalType: "bytes32";
172
+ readonly name: "burntAmount";
173
+ readonly type: "bytes32";
174
+ }, {
175
+ readonly internalType: "uint64";
176
+ readonly name: "burntAmountCleartext";
177
+ readonly type: "uint64";
178
+ }, {
179
+ readonly internalType: "bytes";
180
+ readonly name: "decryptionProof";
181
+ readonly type: "bytes";
182
+ }];
183
+ readonly name: "finalizeUnwrap";
184
+ readonly outputs: readonly [];
185
+ readonly stateMutability: "nonpayable";
186
+ readonly type: "function";
122
187
  }, {
123
188
  readonly anonymous: false;
124
189
  readonly inputs: readonly [{
@@ -238,6 +303,27 @@ declare function createNonce(): `0x${string}`;
238
303
  declare function hashEncryptedAmountInput(encryptedAmountInput: `0x${string}`): `0x${string}`;
239
304
  declare function normalizeAmount(amount: string | number | bigint): string;
240
305
 
306
+ type BrowserEthereumProvider = {
307
+ request: (args: {
308
+ method: string;
309
+ params?: unknown[];
310
+ }) => Promise<unknown>;
311
+ };
312
+ type BrowserSigner = {
313
+ address: `0x${string}`;
314
+ signTypedData: (args: {
315
+ domain: Record<string, unknown>;
316
+ types: Record<string, Array<{
317
+ name: string;
318
+ type: string;
319
+ }>>;
320
+ primaryType: string;
321
+ message: Record<string, unknown>;
322
+ }) => Promise<`0x${string}`>;
323
+ };
324
+ declare function getBrowserEthereumProvider(): BrowserEthereumProvider;
325
+ declare function createBrowserSigner(provider?: BrowserEthereumProvider): Promise<BrowserSigner>;
326
+
241
327
  interface RelayerInstance {
242
328
  createEncryptedInput: (contractAddress: string, senderAddress: string) => {
243
329
  add64: (amount: number) => {
@@ -270,15 +356,15 @@ interface RelayerInstance {
270
356
  decryptionProof: string;
271
357
  }>;
272
358
  }
273
- type RelayerBundleModule = typeof relayerBundle;
359
+ type RelayerWebModule = typeof relayerWeb;
274
360
  type RelayerSdkModule = {
275
- createInstance: RelayerBundleModule["createInstance"];
276
- initSDK: RelayerBundleModule["initSDK"];
277
- SepoliaConfig: RelayerBundleModule["SepoliaConfig"];
361
+ createInstance: RelayerWebModule["createInstance"];
362
+ initSDK: RelayerWebModule["initSDK"];
363
+ SepoliaConfig: RelayerWebModule["SepoliaConfig"];
278
364
  };
279
- type FhevmInstanceConfig = Parameters<RelayerBundleModule["createInstance"]>[0];
280
- declare const SepoliaConfig: relayerBundle.FhevmInstanceConfig;
281
- declare function getSepoliaConfig(): RelayerBundleModule["SepoliaConfig"];
365
+ type FhevmInstanceConfig = Parameters<RelayerWebModule["createInstance"]>[0];
366
+ declare const SepoliaConfig: relayerWeb.FhevmInstanceConfig;
367
+ declare function getSepoliaConfig(): RelayerWebModule["SepoliaConfig"];
282
368
  type RelayerSigner = {
283
369
  address: string;
284
370
  signTypedData: ((domain: Record<string, unknown>, types: Record<string, Array<{
@@ -330,27 +416,6 @@ type TransferQueryOptions = {
330
416
  };
331
417
  declare function getTransferAmounts(options: TransferQueryOptions): Promise<TransferAmount[]>;
332
418
 
333
- type ConfidentialTokenOptions = {
334
- rpcUrl: string;
335
- tokenAddress: `0x${string}`;
336
- relayer: RelayerInstance;
337
- walletClient: WalletClient;
338
- signer?: RelayerSigner;
339
- };
340
- declare class ConfidentialToken {
341
- private readonly rpcUrl;
342
- private readonly tokenAddress;
343
- private readonly relayer;
344
- private readonly walletClient;
345
- private readonly signer?;
346
- constructor(config: ConfidentialTokenOptions);
347
- balanceOf(account?: `0x${string}`): Promise<bigint>;
348
- setObserver(account: `0x${string}`, observer: `0x${string}`): Promise<`0x${string}`>;
349
- transfer(to: `0x${string}`, amount: number): Promise<`0x${string}`>;
350
- wrap(to: `0x${string}`, amount: string | number | bigint): Promise<`0x${string}`>;
351
- unwrap(from: `0x${string}`, to: `0x${string}`, amount: number): Promise<`0x${string}`>;
352
- }
353
-
354
419
  type ConfidentialPaymentAuthorization = {
355
420
  holder: `0x${string}`;
356
421
  payee: `0x${string}`;
@@ -361,6 +426,14 @@ type ConfidentialPaymentAuthorization = {
361
426
  nonce: `0x${string}`;
362
427
  encryptedAmountHash: `0x${string}`;
363
428
  };
429
+ type UnwrapAuthorization = {
430
+ holder: `0x${string}`;
431
+ to: `0x${string}`;
432
+ validAfter: number;
433
+ validBefore: number;
434
+ nonce: `0x${string}`;
435
+ encryptedAmountHash: `0x${string}`;
436
+ };
364
437
  type ConfidentialPaymentPayload = {
365
438
  authorization: ConfidentialPaymentAuthorization;
366
439
  signature: `0x${string}`;
@@ -388,4 +461,27 @@ type ConfidentialPaymentInput = {
388
461
  nonce?: `0x${string}`;
389
462
  };
390
463
 
391
- export { type ConfidentialErrorCode, type ConfidentialPaymentAuthorization, type ConfidentialPaymentInput, type ConfidentialPaymentPayload, type ConfidentialRequirementsExtra, ConfidentialToken, type ConfidentialTokenOptions, type RelayerInstance, type RelayerSdkModule, type RelayerSigner, SepoliaConfig, type TransferAmount, type TransferQueryOptions, confidentialErrorCodes, confidentialPaymentTypes, confidentialTokenAbi, createEncryptedAmountInput, createNonce, createRelayer, decryptEuint64, getSepoliaConfig, getTransferAmounts, hashEncryptedAmountInput, initSDK, normalizeAmount, publicDecrypt };
464
+ type ConfidentialTokenOptions = {
465
+ rpcUrl: string;
466
+ tokenAddress: `0x${string}`;
467
+ relayer: RelayerInstance;
468
+ walletClient: WalletClient;
469
+ signer?: RelayerSigner;
470
+ };
471
+ declare class ConfidentialToken {
472
+ private readonly rpcUrl;
473
+ private readonly tokenAddress;
474
+ private readonly relayer;
475
+ private readonly walletClient;
476
+ private readonly signer?;
477
+ constructor(config: ConfidentialTokenOptions);
478
+ balanceOf(account?: `0x${string}`): Promise<bigint>;
479
+ setObserver(account: `0x${string}`, observer: `0x${string}`): Promise<`0x${string}`>;
480
+ transfer(to: `0x${string}`, amount: number): Promise<`0x${string}`>;
481
+ wrap(to: `0x${string}`, amount: string | number | bigint): Promise<`0x${string}`>;
482
+ unwrap(from: `0x${string}`, to: `0x${string}`, amount: number): Promise<`0x${string}`>;
483
+ unwrapWithAuthorization(authorization: UnwrapAuthorization, encryptedAmountInput: `0x${string}`, inputProof: `0x${string}`, signature: `0x${string}`): Promise<`0x${string}`>;
484
+ finalizeUnwrap(burntAmount: `0x${string}`, burntAmountCleartext: string | number | bigint, decryptionProof: `0x${string}`): Promise<`0x${string}`>;
485
+ }
486
+
487
+ export { type BrowserEthereumProvider, type BrowserSigner, type ConfidentialErrorCode, type ConfidentialPaymentAuthorization, type ConfidentialPaymentInput, type ConfidentialPaymentPayload, type ConfidentialRequirementsExtra, ConfidentialToken, type ConfidentialTokenOptions, type RelayerInstance, type RelayerSdkModule, type RelayerSigner, SepoliaConfig, type TransferAmount, type TransferQueryOptions, type UnwrapAuthorization, confidentialErrorCodes, confidentialPaymentTypes, confidentialTokenAbi, createBrowserSigner, createEncryptedAmountInput, createNonce, createRelayer, decryptEuint64, getBrowserEthereumProvider, getSepoliaConfig, getTransferAmounts, hashEncryptedAmountInput, initSDK, normalizeAmount, publicDecrypt };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as relayerBundle from '@zama-fhe/relayer-sdk/bundle';
1
+ import * as relayerWeb from '@zama-fhe/relayer-sdk/web';
2
2
  import { WalletClient } from 'viem';
3
3
  export * from '@x402/core/types';
4
4
 
@@ -119,6 +119,71 @@ declare const confidentialTokenAbi: readonly [{
119
119
  readonly outputs: readonly [];
120
120
  readonly stateMutability: "nonpayable";
121
121
  readonly type: "function";
122
+ }, {
123
+ readonly inputs: readonly [{
124
+ readonly components: readonly [{
125
+ readonly internalType: "address";
126
+ readonly name: "holder";
127
+ readonly type: "address";
128
+ }, {
129
+ readonly internalType: "address";
130
+ readonly name: "to";
131
+ readonly type: "address";
132
+ }, {
133
+ readonly internalType: "uint48";
134
+ readonly name: "validAfter";
135
+ readonly type: "uint48";
136
+ }, {
137
+ readonly internalType: "uint48";
138
+ readonly name: "validBefore";
139
+ readonly type: "uint48";
140
+ }, {
141
+ readonly internalType: "bytes32";
142
+ readonly name: "nonce";
143
+ readonly type: "bytes32";
144
+ }, {
145
+ readonly internalType: "bytes32";
146
+ readonly name: "encryptedAmountHash";
147
+ readonly type: "bytes32";
148
+ }];
149
+ readonly internalType: "struct FHEToken.UnwrapAuthorization";
150
+ readonly name: "p";
151
+ readonly type: "tuple";
152
+ }, {
153
+ readonly internalType: "bytes";
154
+ readonly name: "encryptedAmountInput";
155
+ readonly type: "bytes";
156
+ }, {
157
+ readonly internalType: "bytes";
158
+ readonly name: "inputProof";
159
+ readonly type: "bytes";
160
+ }, {
161
+ readonly internalType: "bytes";
162
+ readonly name: "sig";
163
+ readonly type: "bytes";
164
+ }];
165
+ readonly name: "unwrapWithAuthorization";
166
+ readonly outputs: readonly [];
167
+ readonly stateMutability: "nonpayable";
168
+ readonly type: "function";
169
+ }, {
170
+ readonly inputs: readonly [{
171
+ readonly internalType: "bytes32";
172
+ readonly name: "burntAmount";
173
+ readonly type: "bytes32";
174
+ }, {
175
+ readonly internalType: "uint64";
176
+ readonly name: "burntAmountCleartext";
177
+ readonly type: "uint64";
178
+ }, {
179
+ readonly internalType: "bytes";
180
+ readonly name: "decryptionProof";
181
+ readonly type: "bytes";
182
+ }];
183
+ readonly name: "finalizeUnwrap";
184
+ readonly outputs: readonly [];
185
+ readonly stateMutability: "nonpayable";
186
+ readonly type: "function";
122
187
  }, {
123
188
  readonly anonymous: false;
124
189
  readonly inputs: readonly [{
@@ -238,6 +303,27 @@ declare function createNonce(): `0x${string}`;
238
303
  declare function hashEncryptedAmountInput(encryptedAmountInput: `0x${string}`): `0x${string}`;
239
304
  declare function normalizeAmount(amount: string | number | bigint): string;
240
305
 
306
+ type BrowserEthereumProvider = {
307
+ request: (args: {
308
+ method: string;
309
+ params?: unknown[];
310
+ }) => Promise<unknown>;
311
+ };
312
+ type BrowserSigner = {
313
+ address: `0x${string}`;
314
+ signTypedData: (args: {
315
+ domain: Record<string, unknown>;
316
+ types: Record<string, Array<{
317
+ name: string;
318
+ type: string;
319
+ }>>;
320
+ primaryType: string;
321
+ message: Record<string, unknown>;
322
+ }) => Promise<`0x${string}`>;
323
+ };
324
+ declare function getBrowserEthereumProvider(): BrowserEthereumProvider;
325
+ declare function createBrowserSigner(provider?: BrowserEthereumProvider): Promise<BrowserSigner>;
326
+
241
327
  interface RelayerInstance {
242
328
  createEncryptedInput: (contractAddress: string, senderAddress: string) => {
243
329
  add64: (amount: number) => {
@@ -270,15 +356,15 @@ interface RelayerInstance {
270
356
  decryptionProof: string;
271
357
  }>;
272
358
  }
273
- type RelayerBundleModule = typeof relayerBundle;
359
+ type RelayerWebModule = typeof relayerWeb;
274
360
  type RelayerSdkModule = {
275
- createInstance: RelayerBundleModule["createInstance"];
276
- initSDK: RelayerBundleModule["initSDK"];
277
- SepoliaConfig: RelayerBundleModule["SepoliaConfig"];
361
+ createInstance: RelayerWebModule["createInstance"];
362
+ initSDK: RelayerWebModule["initSDK"];
363
+ SepoliaConfig: RelayerWebModule["SepoliaConfig"];
278
364
  };
279
- type FhevmInstanceConfig = Parameters<RelayerBundleModule["createInstance"]>[0];
280
- declare const SepoliaConfig: relayerBundle.FhevmInstanceConfig;
281
- declare function getSepoliaConfig(): RelayerBundleModule["SepoliaConfig"];
365
+ type FhevmInstanceConfig = Parameters<RelayerWebModule["createInstance"]>[0];
366
+ declare const SepoliaConfig: relayerWeb.FhevmInstanceConfig;
367
+ declare function getSepoliaConfig(): RelayerWebModule["SepoliaConfig"];
282
368
  type RelayerSigner = {
283
369
  address: string;
284
370
  signTypedData: ((domain: Record<string, unknown>, types: Record<string, Array<{
@@ -330,27 +416,6 @@ type TransferQueryOptions = {
330
416
  };
331
417
  declare function getTransferAmounts(options: TransferQueryOptions): Promise<TransferAmount[]>;
332
418
 
333
- type ConfidentialTokenOptions = {
334
- rpcUrl: string;
335
- tokenAddress: `0x${string}`;
336
- relayer: RelayerInstance;
337
- walletClient: WalletClient;
338
- signer?: RelayerSigner;
339
- };
340
- declare class ConfidentialToken {
341
- private readonly rpcUrl;
342
- private readonly tokenAddress;
343
- private readonly relayer;
344
- private readonly walletClient;
345
- private readonly signer?;
346
- constructor(config: ConfidentialTokenOptions);
347
- balanceOf(account?: `0x${string}`): Promise<bigint>;
348
- setObserver(account: `0x${string}`, observer: `0x${string}`): Promise<`0x${string}`>;
349
- transfer(to: `0x${string}`, amount: number): Promise<`0x${string}`>;
350
- wrap(to: `0x${string}`, amount: string | number | bigint): Promise<`0x${string}`>;
351
- unwrap(from: `0x${string}`, to: `0x${string}`, amount: number): Promise<`0x${string}`>;
352
- }
353
-
354
419
  type ConfidentialPaymentAuthorization = {
355
420
  holder: `0x${string}`;
356
421
  payee: `0x${string}`;
@@ -361,6 +426,14 @@ type ConfidentialPaymentAuthorization = {
361
426
  nonce: `0x${string}`;
362
427
  encryptedAmountHash: `0x${string}`;
363
428
  };
429
+ type UnwrapAuthorization = {
430
+ holder: `0x${string}`;
431
+ to: `0x${string}`;
432
+ validAfter: number;
433
+ validBefore: number;
434
+ nonce: `0x${string}`;
435
+ encryptedAmountHash: `0x${string}`;
436
+ };
364
437
  type ConfidentialPaymentPayload = {
365
438
  authorization: ConfidentialPaymentAuthorization;
366
439
  signature: `0x${string}`;
@@ -388,4 +461,27 @@ type ConfidentialPaymentInput = {
388
461
  nonce?: `0x${string}`;
389
462
  };
390
463
 
391
- export { type ConfidentialErrorCode, type ConfidentialPaymentAuthorization, type ConfidentialPaymentInput, type ConfidentialPaymentPayload, type ConfidentialRequirementsExtra, ConfidentialToken, type ConfidentialTokenOptions, type RelayerInstance, type RelayerSdkModule, type RelayerSigner, SepoliaConfig, type TransferAmount, type TransferQueryOptions, confidentialErrorCodes, confidentialPaymentTypes, confidentialTokenAbi, createEncryptedAmountInput, createNonce, createRelayer, decryptEuint64, getSepoliaConfig, getTransferAmounts, hashEncryptedAmountInput, initSDK, normalizeAmount, publicDecrypt };
464
+ type ConfidentialTokenOptions = {
465
+ rpcUrl: string;
466
+ tokenAddress: `0x${string}`;
467
+ relayer: RelayerInstance;
468
+ walletClient: WalletClient;
469
+ signer?: RelayerSigner;
470
+ };
471
+ declare class ConfidentialToken {
472
+ private readonly rpcUrl;
473
+ private readonly tokenAddress;
474
+ private readonly relayer;
475
+ private readonly walletClient;
476
+ private readonly signer?;
477
+ constructor(config: ConfidentialTokenOptions);
478
+ balanceOf(account?: `0x${string}`): Promise<bigint>;
479
+ setObserver(account: `0x${string}`, observer: `0x${string}`): Promise<`0x${string}`>;
480
+ transfer(to: `0x${string}`, amount: number): Promise<`0x${string}`>;
481
+ wrap(to: `0x${string}`, amount: string | number | bigint): Promise<`0x${string}`>;
482
+ unwrap(from: `0x${string}`, to: `0x${string}`, amount: number): Promise<`0x${string}`>;
483
+ unwrapWithAuthorization(authorization: UnwrapAuthorization, encryptedAmountInput: `0x${string}`, inputProof: `0x${string}`, signature: `0x${string}`): Promise<`0x${string}`>;
484
+ finalizeUnwrap(burntAmount: `0x${string}`, burntAmountCleartext: string | number | bigint, decryptionProof: `0x${string}`): Promise<`0x${string}`>;
485
+ }
486
+
487
+ export { type BrowserEthereumProvider, type BrowserSigner, type ConfidentialErrorCode, type ConfidentialPaymentAuthorization, type ConfidentialPaymentInput, type ConfidentialPaymentPayload, type ConfidentialRequirementsExtra, ConfidentialToken, type ConfidentialTokenOptions, type RelayerInstance, type RelayerSdkModule, type RelayerSigner, SepoliaConfig, type TransferAmount, type TransferQueryOptions, type UnwrapAuthorization, confidentialErrorCodes, confidentialPaymentTypes, confidentialTokenAbi, createBrowserSigner, createEncryptedAmountInput, createNonce, createRelayer, decryptEuint64, getBrowserEthereumProvider, getSepoliaConfig, getTransferAmounts, hashEncryptedAmountInput, initSDK, normalizeAmount, publicDecrypt };
package/dist/index.js CHANGED
@@ -35,10 +35,12 @@ __export(index_exports, {
35
35
  confidentialErrorCodes: () => confidentialErrorCodes,
36
36
  confidentialPaymentTypes: () => confidentialPaymentTypes,
37
37
  confidentialTokenAbi: () => confidentialTokenAbi,
38
+ createBrowserSigner: () => createBrowserSigner,
38
39
  createEncryptedAmountInput: () => createEncryptedAmountInput,
39
40
  createNonce: () => createNonce,
40
41
  createRelayer: () => createRelayer,
41
42
  decryptEuint64: () => decryptEuint64,
43
+ getBrowserEthereumProvider: () => getBrowserEthereumProvider,
42
44
  getSepoliaConfig: () => getSepoliaConfig,
43
45
  getTransferAmounts: () => getTransferAmounts,
44
46
  hashEncryptedAmountInput: () => hashEncryptedAmountInput,
@@ -109,6 +111,41 @@ var confidentialTokenAbi = [
109
111
  stateMutability: "nonpayable",
110
112
  type: "function"
111
113
  },
114
+ {
115
+ inputs: [
116
+ {
117
+ components: [
118
+ { internalType: "address", name: "holder", type: "address" },
119
+ { internalType: "address", name: "to", type: "address" },
120
+ { internalType: "uint48", name: "validAfter", type: "uint48" },
121
+ { internalType: "uint48", name: "validBefore", type: "uint48" },
122
+ { internalType: "bytes32", name: "nonce", type: "bytes32" },
123
+ { internalType: "bytes32", name: "encryptedAmountHash", type: "bytes32" }
124
+ ],
125
+ internalType: "struct FHEToken.UnwrapAuthorization",
126
+ name: "p",
127
+ type: "tuple"
128
+ },
129
+ { internalType: "bytes", name: "encryptedAmountInput", type: "bytes" },
130
+ { internalType: "bytes", name: "inputProof", type: "bytes" },
131
+ { internalType: "bytes", name: "sig", type: "bytes" }
132
+ ],
133
+ name: "unwrapWithAuthorization",
134
+ outputs: [],
135
+ stateMutability: "nonpayable",
136
+ type: "function"
137
+ },
138
+ {
139
+ inputs: [
140
+ { internalType: "bytes32", name: "burntAmount", type: "bytes32" },
141
+ { internalType: "uint64", name: "burntAmountCleartext", type: "uint64" },
142
+ { internalType: "bytes", name: "decryptionProof", type: "bytes" }
143
+ ],
144
+ name: "finalizeUnwrap",
145
+ outputs: [],
146
+ stateMutability: "nonpayable",
147
+ type: "function"
148
+ },
112
149
  {
113
150
  anonymous: false,
114
151
  inputs: [
@@ -195,16 +232,64 @@ function normalizeAmount(amount) {
195
232
  return amount.toString();
196
233
  }
197
234
 
235
+ // src/core/signer.ts
236
+ function stringifyPayload(payload) {
237
+ return JSON.stringify(
238
+ payload,
239
+ (_, value) => typeof value === "bigint" ? value.toString() : value
240
+ );
241
+ }
242
+ function getBrowserEthereumProvider() {
243
+ const provider = globalThis.ethereum;
244
+ if (!provider) {
245
+ throw new Error("Missing window.ethereum; install a wallet like MetaMask");
246
+ }
247
+ return provider;
248
+ }
249
+ async function createBrowserSigner(provider = getBrowserEthereumProvider()) {
250
+ const accounts = await provider.request({ method: "eth_requestAccounts" });
251
+ const account = accounts?.[0];
252
+ if (!account) {
253
+ throw new Error("No wallet account available");
254
+ }
255
+ return {
256
+ address: account,
257
+ signTypedData: async (args) => {
258
+ const signature = await provider.request({
259
+ method: "eth_signTypedData_v4",
260
+ params: [
261
+ account,
262
+ stringifyPayload({
263
+ domain: args.domain,
264
+ types: {
265
+ EIP712Domain: [
266
+ { name: "name", type: "string" },
267
+ { name: "version", type: "string" },
268
+ { name: "chainId", type: "uint256" },
269
+ { name: "verifyingContract", type: "address" }
270
+ ],
271
+ ...args.types
272
+ },
273
+ primaryType: args.primaryType,
274
+ message: args.message
275
+ })
276
+ ]
277
+ });
278
+ return signature;
279
+ }
280
+ };
281
+ }
282
+
198
283
  // src/relayer/index.ts
199
284
  var import_viem2 = require("viem");
200
- var relayerBundle = __toESM(require("@zama-fhe/relayer-sdk/bundle"));
201
- var SepoliaConfig2 = relayerBundle.SepoliaConfig;
285
+ var relayerWeb = __toESM(require("@zama-fhe/relayer-sdk/web"));
286
+ var SepoliaConfig2 = relayerWeb.SepoliaConfig;
202
287
  function getSepoliaConfig() {
203
- return relayerBundle.SepoliaConfig;
288
+ return relayerWeb.SepoliaConfig;
204
289
  }
205
290
  async function createRelayer(config) {
206
291
  await initSDK2();
207
- const instance = await relayerBundle.createInstance(config);
292
+ const instance = await relayerWeb.createInstance(config);
208
293
  if (typeof config.network === "string") {
209
294
  instance.network = config.network;
210
295
  }
@@ -215,7 +300,7 @@ async function initSDK2(params) {
215
300
  if (sdkInitialized) {
216
301
  return true;
217
302
  }
218
- const result = await relayerBundle.initSDK(params);
303
+ const result = await relayerWeb.initSDK(params);
219
304
  sdkInitialized = true;
220
305
  return result;
221
306
  }
@@ -550,6 +635,43 @@ var ConfidentialToken = class {
550
635
  account: resolveWriteAccount(this.signer, this.walletClient)
551
636
  });
552
637
  }
638
+ async unwrapWithAuthorization(authorization, encryptedAmountInput, inputProof, signature) {
639
+ const tokenAddress = assertAddress(this.tokenAddress, "token address");
640
+ const holder = assertAddress(authorization.holder, "holder address");
641
+ const to = assertAddress(authorization.to, "to address");
642
+ return this.walletClient.writeContract({
643
+ address: tokenAddress,
644
+ abi: confidentialTokenAbi,
645
+ functionName: "unwrapWithAuthorization",
646
+ args: [
647
+ {
648
+ holder,
649
+ to,
650
+ validAfter: authorization.validAfter,
651
+ validBefore: authorization.validBefore,
652
+ nonce: authorization.nonce,
653
+ encryptedAmountHash: authorization.encryptedAmountHash
654
+ },
655
+ encryptedAmountInput,
656
+ inputProof,
657
+ signature
658
+ ],
659
+ chain: this.walletClient.chain ?? null,
660
+ account: resolveWriteAccount(this.signer, this.walletClient)
661
+ });
662
+ }
663
+ async finalizeUnwrap(burntAmount, burntAmountCleartext, decryptionProof) {
664
+ const tokenAddress = assertAddress(this.tokenAddress, "token address");
665
+ const normalizedAmount = BigInt(normalizeAmount(burntAmountCleartext));
666
+ return this.walletClient.writeContract({
667
+ address: tokenAddress,
668
+ abi: confidentialTokenAbi,
669
+ functionName: "finalizeUnwrap",
670
+ args: [burntAmount, normalizedAmount, decryptionProof],
671
+ chain: this.walletClient.chain ?? null,
672
+ account: resolveWriteAccount(this.signer, this.walletClient)
673
+ });
674
+ }
553
675
  };
554
676
  // Annotate the CommonJS export names for ESM import in node:
555
677
  0 && (module.exports = {
@@ -558,10 +680,12 @@ var ConfidentialToken = class {
558
680
  confidentialErrorCodes,
559
681
  confidentialPaymentTypes,
560
682
  confidentialTokenAbi,
683
+ createBrowserSigner,
561
684
  createEncryptedAmountInput,
562
685
  createNonce,
563
686
  createRelayer,
564
687
  decryptEuint64,
688
+ getBrowserEthereumProvider,
565
689
  getSepoliaConfig,
566
690
  getTransferAmounts,
567
691
  hashEncryptedAmountInput,
package/dist/index.mjs CHANGED
@@ -59,6 +59,41 @@ var confidentialTokenAbi = [
59
59
  stateMutability: "nonpayable",
60
60
  type: "function"
61
61
  },
62
+ {
63
+ inputs: [
64
+ {
65
+ components: [
66
+ { internalType: "address", name: "holder", type: "address" },
67
+ { internalType: "address", name: "to", type: "address" },
68
+ { internalType: "uint48", name: "validAfter", type: "uint48" },
69
+ { internalType: "uint48", name: "validBefore", type: "uint48" },
70
+ { internalType: "bytes32", name: "nonce", type: "bytes32" },
71
+ { internalType: "bytes32", name: "encryptedAmountHash", type: "bytes32" }
72
+ ],
73
+ internalType: "struct FHEToken.UnwrapAuthorization",
74
+ name: "p",
75
+ type: "tuple"
76
+ },
77
+ { internalType: "bytes", name: "encryptedAmountInput", type: "bytes" },
78
+ { internalType: "bytes", name: "inputProof", type: "bytes" },
79
+ { internalType: "bytes", name: "sig", type: "bytes" }
80
+ ],
81
+ name: "unwrapWithAuthorization",
82
+ outputs: [],
83
+ stateMutability: "nonpayable",
84
+ type: "function"
85
+ },
86
+ {
87
+ inputs: [
88
+ { internalType: "bytes32", name: "burntAmount", type: "bytes32" },
89
+ { internalType: "uint64", name: "burntAmountCleartext", type: "uint64" },
90
+ { internalType: "bytes", name: "decryptionProof", type: "bytes" }
91
+ ],
92
+ name: "finalizeUnwrap",
93
+ outputs: [],
94
+ stateMutability: "nonpayable",
95
+ type: "function"
96
+ },
62
97
  {
63
98
  anonymous: false,
64
99
  inputs: [
@@ -145,16 +180,64 @@ function normalizeAmount(amount) {
145
180
  return amount.toString();
146
181
  }
147
182
 
183
+ // src/core/signer.ts
184
+ function stringifyPayload(payload) {
185
+ return JSON.stringify(
186
+ payload,
187
+ (_, value) => typeof value === "bigint" ? value.toString() : value
188
+ );
189
+ }
190
+ function getBrowserEthereumProvider() {
191
+ const provider = globalThis.ethereum;
192
+ if (!provider) {
193
+ throw new Error("Missing window.ethereum; install a wallet like MetaMask");
194
+ }
195
+ return provider;
196
+ }
197
+ async function createBrowserSigner(provider = getBrowserEthereumProvider()) {
198
+ const accounts = await provider.request({ method: "eth_requestAccounts" });
199
+ const account = accounts?.[0];
200
+ if (!account) {
201
+ throw new Error("No wallet account available");
202
+ }
203
+ return {
204
+ address: account,
205
+ signTypedData: async (args) => {
206
+ const signature = await provider.request({
207
+ method: "eth_signTypedData_v4",
208
+ params: [
209
+ account,
210
+ stringifyPayload({
211
+ domain: args.domain,
212
+ types: {
213
+ EIP712Domain: [
214
+ { name: "name", type: "string" },
215
+ { name: "version", type: "string" },
216
+ { name: "chainId", type: "uint256" },
217
+ { name: "verifyingContract", type: "address" }
218
+ ],
219
+ ...args.types
220
+ },
221
+ primaryType: args.primaryType,
222
+ message: args.message
223
+ })
224
+ ]
225
+ });
226
+ return signature;
227
+ }
228
+ };
229
+ }
230
+
148
231
  // src/relayer/index.ts
149
232
  import { getAddress, toHex as toHex2 } from "viem";
150
- import * as relayerBundle from "@zama-fhe/relayer-sdk/bundle";
151
- var SepoliaConfig2 = relayerBundle.SepoliaConfig;
233
+ import * as relayerWeb from "@zama-fhe/relayer-sdk/web";
234
+ var SepoliaConfig2 = relayerWeb.SepoliaConfig;
152
235
  function getSepoliaConfig() {
153
- return relayerBundle.SepoliaConfig;
236
+ return relayerWeb.SepoliaConfig;
154
237
  }
155
238
  async function createRelayer(config) {
156
239
  await initSDK2();
157
- const instance = await relayerBundle.createInstance(config);
240
+ const instance = await relayerWeb.createInstance(config);
158
241
  if (typeof config.network === "string") {
159
242
  instance.network = config.network;
160
243
  }
@@ -165,7 +248,7 @@ async function initSDK2(params) {
165
248
  if (sdkInitialized) {
166
249
  return true;
167
250
  }
168
- const result = await relayerBundle.initSDK(params);
251
+ const result = await relayerWeb.initSDK(params);
169
252
  sdkInitialized = true;
170
253
  return result;
171
254
  }
@@ -500,6 +583,43 @@ var ConfidentialToken = class {
500
583
  account: resolveWriteAccount(this.signer, this.walletClient)
501
584
  });
502
585
  }
586
+ async unwrapWithAuthorization(authorization, encryptedAmountInput, inputProof, signature) {
587
+ const tokenAddress = assertAddress(this.tokenAddress, "token address");
588
+ const holder = assertAddress(authorization.holder, "holder address");
589
+ const to = assertAddress(authorization.to, "to address");
590
+ return this.walletClient.writeContract({
591
+ address: tokenAddress,
592
+ abi: confidentialTokenAbi,
593
+ functionName: "unwrapWithAuthorization",
594
+ args: [
595
+ {
596
+ holder,
597
+ to,
598
+ validAfter: authorization.validAfter,
599
+ validBefore: authorization.validBefore,
600
+ nonce: authorization.nonce,
601
+ encryptedAmountHash: authorization.encryptedAmountHash
602
+ },
603
+ encryptedAmountInput,
604
+ inputProof,
605
+ signature
606
+ ],
607
+ chain: this.walletClient.chain ?? null,
608
+ account: resolveWriteAccount(this.signer, this.walletClient)
609
+ });
610
+ }
611
+ async finalizeUnwrap(burntAmount, burntAmountCleartext, decryptionProof) {
612
+ const tokenAddress = assertAddress(this.tokenAddress, "token address");
613
+ const normalizedAmount = BigInt(normalizeAmount(burntAmountCleartext));
614
+ return this.walletClient.writeContract({
615
+ address: tokenAddress,
616
+ abi: confidentialTokenAbi,
617
+ functionName: "finalizeUnwrap",
618
+ args: [burntAmount, normalizedAmount, decryptionProof],
619
+ chain: this.walletClient.chain ?? null,
620
+ account: resolveWriteAccount(this.signer, this.walletClient)
621
+ });
622
+ }
503
623
  };
504
624
  export {
505
625
  ConfidentialToken,
@@ -507,10 +627,12 @@ export {
507
627
  confidentialErrorCodes,
508
628
  confidentialPaymentTypes,
509
629
  confidentialTokenAbi,
630
+ createBrowserSigner,
510
631
  createEncryptedAmountInput,
511
632
  createNonce,
512
633
  createRelayer,
513
634
  decryptEuint64,
635
+ getBrowserEthereumProvider,
514
636
  getSepoliaConfig,
515
637
  getTransferAmounts,
516
638
  hashEncryptedAmountInput,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x402z-shared-web",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",