x402z-shared-web 0.0.9 → 0.0.10
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 +11 -5
- package/dist/index.d.mts +15 -15
- package/dist/index.d.ts +15 -15
- package/dist/index.js +25 -27
- package/dist/index.mjs +15 -26
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,12 +21,16 @@ pnpm add x402z-shared-web
|
|
|
21
21
|
import {
|
|
22
22
|
createRelayer,
|
|
23
23
|
createEncryptedAmountInput,
|
|
24
|
-
|
|
25
|
-
SepoliaConfig,
|
|
24
|
+
getSepoliaConfig,
|
|
26
25
|
} from "x402z-shared-web";
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
26
|
+
import type { FhevmInstanceConfig } from "x402z-shared-web";
|
|
27
|
+
|
|
28
|
+
const relayerConfig: FhevmInstanceConfig = {
|
|
29
|
+
...(getSepoliaConfig() as object),
|
|
30
|
+
network: window.ethereum,
|
|
31
|
+
relayerUrl: "https://relayer.testnet.zama.org",
|
|
32
|
+
};
|
|
33
|
+
const relayer = await createRelayer(relayerConfig);
|
|
30
34
|
const encrypted = await createEncryptedAmountInput(
|
|
31
35
|
relayer,
|
|
32
36
|
"0xToken",
|
|
@@ -35,6 +39,8 @@ const encrypted = await createEncryptedAmountInput(
|
|
|
35
39
|
);
|
|
36
40
|
```
|
|
37
41
|
|
|
42
|
+
`createRelayer` calls `initSDK()` for you the first time.
|
|
43
|
+
|
|
38
44
|
## Token helper (Browser)
|
|
39
45
|
|
|
40
46
|
```ts
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as relayerBundle from '@zama-fhe/relayer-sdk/bundle';
|
|
1
2
|
import { WalletClient } from 'viem';
|
|
2
3
|
export * from '@x402/core/types';
|
|
3
4
|
|
|
@@ -252,12 +253,10 @@ interface RelayerInstance {
|
|
|
252
253
|
};
|
|
253
254
|
createEIP712: (publicKey: string, contractAddresses: string[], startTimestamp: string, durationDays: string) => {
|
|
254
255
|
domain: Record<string, unknown>;
|
|
255
|
-
types: {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}>;
|
|
260
|
-
};
|
|
256
|
+
types: Record<string, Array<{
|
|
257
|
+
name: string;
|
|
258
|
+
type: string;
|
|
259
|
+
}>>;
|
|
261
260
|
message: Record<string, unknown>;
|
|
262
261
|
};
|
|
263
262
|
userDecrypt: (handles: Array<{
|
|
@@ -271,14 +270,15 @@ interface RelayerInstance {
|
|
|
271
270
|
decryptionProof: string;
|
|
272
271
|
}>;
|
|
273
272
|
}
|
|
273
|
+
type RelayerBundleModule = typeof relayerBundle;
|
|
274
274
|
type RelayerSdkModule = {
|
|
275
|
-
createInstance:
|
|
276
|
-
initSDK:
|
|
277
|
-
SepoliaConfig:
|
|
275
|
+
createInstance: RelayerBundleModule["createInstance"];
|
|
276
|
+
initSDK: RelayerBundleModule["initSDK"];
|
|
277
|
+
SepoliaConfig: RelayerBundleModule["SepoliaConfig"];
|
|
278
278
|
};
|
|
279
|
-
|
|
280
|
-
declare
|
|
281
|
-
declare function getSepoliaConfig():
|
|
279
|
+
type FhevmInstanceConfig = Parameters<RelayerBundleModule["createInstance"]>[0];
|
|
280
|
+
declare const SepoliaConfig: relayerBundle.FhevmInstanceConfig;
|
|
281
|
+
declare function getSepoliaConfig(): RelayerBundleModule["SepoliaConfig"];
|
|
282
282
|
type RelayerSigner = {
|
|
283
283
|
address: string;
|
|
284
284
|
signTypedData: ((domain: Record<string, unknown>, types: Record<string, Array<{
|
|
@@ -294,8 +294,8 @@ type RelayerSigner = {
|
|
|
294
294
|
message: Record<string, unknown>;
|
|
295
295
|
}) => Promise<string>);
|
|
296
296
|
};
|
|
297
|
-
declare function createRelayer(config:
|
|
298
|
-
declare function initSDK(params?:
|
|
297
|
+
declare function createRelayer(config: FhevmInstanceConfig): Promise<RelayerInstance>;
|
|
298
|
+
declare function initSDK(params?: Parameters<RelayerSdkModule["initSDK"]>[0]): Promise<boolean>;
|
|
299
299
|
declare function createEncryptedAmountInput(relayer: RelayerInstance, contractAddress: string, senderAddress: string, amount: number): Promise<{
|
|
300
300
|
handle: `0x${string}`;
|
|
301
301
|
inputProof: `0x${string}`;
|
|
@@ -388,4 +388,4 @@ type ConfidentialPaymentInput = {
|
|
|
388
388
|
nonce?: `0x${string}`;
|
|
389
389
|
};
|
|
390
390
|
|
|
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,
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as relayerBundle from '@zama-fhe/relayer-sdk/bundle';
|
|
1
2
|
import { WalletClient } from 'viem';
|
|
2
3
|
export * from '@x402/core/types';
|
|
3
4
|
|
|
@@ -252,12 +253,10 @@ interface RelayerInstance {
|
|
|
252
253
|
};
|
|
253
254
|
createEIP712: (publicKey: string, contractAddresses: string[], startTimestamp: string, durationDays: string) => {
|
|
254
255
|
domain: Record<string, unknown>;
|
|
255
|
-
types: {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}>;
|
|
260
|
-
};
|
|
256
|
+
types: Record<string, Array<{
|
|
257
|
+
name: string;
|
|
258
|
+
type: string;
|
|
259
|
+
}>>;
|
|
261
260
|
message: Record<string, unknown>;
|
|
262
261
|
};
|
|
263
262
|
userDecrypt: (handles: Array<{
|
|
@@ -271,14 +270,15 @@ interface RelayerInstance {
|
|
|
271
270
|
decryptionProof: string;
|
|
272
271
|
}>;
|
|
273
272
|
}
|
|
273
|
+
type RelayerBundleModule = typeof relayerBundle;
|
|
274
274
|
type RelayerSdkModule = {
|
|
275
|
-
createInstance:
|
|
276
|
-
initSDK:
|
|
277
|
-
SepoliaConfig:
|
|
275
|
+
createInstance: RelayerBundleModule["createInstance"];
|
|
276
|
+
initSDK: RelayerBundleModule["initSDK"];
|
|
277
|
+
SepoliaConfig: RelayerBundleModule["SepoliaConfig"];
|
|
278
278
|
};
|
|
279
|
-
|
|
280
|
-
declare
|
|
281
|
-
declare function getSepoliaConfig():
|
|
279
|
+
type FhevmInstanceConfig = Parameters<RelayerBundleModule["createInstance"]>[0];
|
|
280
|
+
declare const SepoliaConfig: relayerBundle.FhevmInstanceConfig;
|
|
281
|
+
declare function getSepoliaConfig(): RelayerBundleModule["SepoliaConfig"];
|
|
282
282
|
type RelayerSigner = {
|
|
283
283
|
address: string;
|
|
284
284
|
signTypedData: ((domain: Record<string, unknown>, types: Record<string, Array<{
|
|
@@ -294,8 +294,8 @@ type RelayerSigner = {
|
|
|
294
294
|
message: Record<string, unknown>;
|
|
295
295
|
}) => Promise<string>);
|
|
296
296
|
};
|
|
297
|
-
declare function createRelayer(config:
|
|
298
|
-
declare function initSDK(params?:
|
|
297
|
+
declare function createRelayer(config: FhevmInstanceConfig): Promise<RelayerInstance>;
|
|
298
|
+
declare function initSDK(params?: Parameters<RelayerSdkModule["initSDK"]>[0]): Promise<boolean>;
|
|
299
299
|
declare function createEncryptedAmountInput(relayer: RelayerInstance, contractAddress: string, senderAddress: string, amount: number): Promise<{
|
|
300
300
|
handle: `0x${string}`;
|
|
301
301
|
inputProof: `0x${string}`;
|
|
@@ -388,4 +388,4 @@ type ConfidentialPaymentInput = {
|
|
|
388
388
|
nonce?: `0x${string}`;
|
|
389
389
|
};
|
|
390
390
|
|
|
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,
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,17 +17,24 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
21
31
|
var index_exports = {};
|
|
22
32
|
__export(index_exports, {
|
|
23
33
|
ConfidentialToken: () => ConfidentialToken,
|
|
24
|
-
SepoliaConfig: () =>
|
|
34
|
+
SepoliaConfig: () => SepoliaConfig2,
|
|
25
35
|
confidentialErrorCodes: () => confidentialErrorCodes,
|
|
26
36
|
confidentialPaymentTypes: () => confidentialPaymentTypes,
|
|
27
37
|
confidentialTokenAbi: () => confidentialTokenAbi,
|
|
28
|
-
configureRelayerSdk: () => configureRelayerSdk,
|
|
29
38
|
createEncryptedAmountInput: () => createEncryptedAmountInput,
|
|
30
39
|
createNonce: () => createNonce,
|
|
31
40
|
createRelayer: () => createRelayer,
|
|
@@ -33,7 +42,7 @@ __export(index_exports, {
|
|
|
33
42
|
getSepoliaConfig: () => getSepoliaConfig,
|
|
34
43
|
getTransferAmounts: () => getTransferAmounts,
|
|
35
44
|
hashEncryptedAmountInput: () => hashEncryptedAmountInput,
|
|
36
|
-
initSDK: () =>
|
|
45
|
+
initSDK: () => initSDK2,
|
|
37
46
|
normalizeAmount: () => normalizeAmount,
|
|
38
47
|
publicDecrypt: () => publicDecrypt
|
|
39
48
|
});
|
|
@@ -188,37 +197,27 @@ function normalizeAmount(amount) {
|
|
|
188
197
|
|
|
189
198
|
// src/relayer/index.ts
|
|
190
199
|
var import_viem2 = require("viem");
|
|
191
|
-
var
|
|
192
|
-
var SepoliaConfig;
|
|
193
|
-
async function getRelayerSdk() {
|
|
194
|
-
if (relayerSdk) {
|
|
195
|
-
return relayerSdk;
|
|
196
|
-
}
|
|
197
|
-
throw new Error(
|
|
198
|
-
"Relayer SDK not configured. Call configureRelayerSdk() with the CDN module before initSDK/createRelayer."
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
|
-
function configureRelayerSdk(sdk) {
|
|
202
|
-
relayerSdk = sdk;
|
|
203
|
-
SepoliaConfig = sdk.SepoliaConfig;
|
|
204
|
-
}
|
|
200
|
+
var relayerBundle = __toESM(require("@zama-fhe/relayer-sdk/bundle"));
|
|
201
|
+
var SepoliaConfig2 = relayerBundle.SepoliaConfig;
|
|
205
202
|
function getSepoliaConfig() {
|
|
206
|
-
|
|
207
|
-
throw new Error("SepoliaConfig is not available; call configureRelayerSdk or initSDK first");
|
|
208
|
-
}
|
|
209
|
-
return SepoliaConfig;
|
|
203
|
+
return relayerBundle.SepoliaConfig;
|
|
210
204
|
}
|
|
211
205
|
async function createRelayer(config) {
|
|
212
|
-
|
|
213
|
-
const instance = await
|
|
206
|
+
await initSDK2();
|
|
207
|
+
const instance = await relayerBundle.createInstance(config);
|
|
214
208
|
if (typeof config.network === "string") {
|
|
215
209
|
instance.network = config.network;
|
|
216
210
|
}
|
|
217
211
|
return instance;
|
|
218
212
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
213
|
+
var sdkInitialized = false;
|
|
214
|
+
async function initSDK2(params) {
|
|
215
|
+
if (sdkInitialized) {
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
const result = await relayerBundle.initSDK(params);
|
|
219
|
+
sdkInitialized = true;
|
|
220
|
+
return result;
|
|
222
221
|
}
|
|
223
222
|
async function createEncryptedAmountInput(relayer, contractAddress, senderAddress, amount) {
|
|
224
223
|
const normalizedContract = (0, import_viem2.getAddress)(contractAddress);
|
|
@@ -559,7 +558,6 @@ var ConfidentialToken = class {
|
|
|
559
558
|
confidentialErrorCodes,
|
|
560
559
|
confidentialPaymentTypes,
|
|
561
560
|
confidentialTokenAbi,
|
|
562
|
-
configureRelayerSdk,
|
|
563
561
|
createEncryptedAmountInput,
|
|
564
562
|
createNonce,
|
|
565
563
|
createRelayer,
|
package/dist/index.mjs
CHANGED
|
@@ -147,37 +147,27 @@ function normalizeAmount(amount) {
|
|
|
147
147
|
|
|
148
148
|
// src/relayer/index.ts
|
|
149
149
|
import { getAddress, toHex as toHex2 } from "viem";
|
|
150
|
-
|
|
151
|
-
var SepoliaConfig;
|
|
152
|
-
async function getRelayerSdk() {
|
|
153
|
-
if (relayerSdk) {
|
|
154
|
-
return relayerSdk;
|
|
155
|
-
}
|
|
156
|
-
throw new Error(
|
|
157
|
-
"Relayer SDK not configured. Call configureRelayerSdk() with the CDN module before initSDK/createRelayer."
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
function configureRelayerSdk(sdk) {
|
|
161
|
-
relayerSdk = sdk;
|
|
162
|
-
SepoliaConfig = sdk.SepoliaConfig;
|
|
163
|
-
}
|
|
150
|
+
import * as relayerBundle from "@zama-fhe/relayer-sdk/bundle";
|
|
151
|
+
var SepoliaConfig2 = relayerBundle.SepoliaConfig;
|
|
164
152
|
function getSepoliaConfig() {
|
|
165
|
-
|
|
166
|
-
throw new Error("SepoliaConfig is not available; call configureRelayerSdk or initSDK first");
|
|
167
|
-
}
|
|
168
|
-
return SepoliaConfig;
|
|
153
|
+
return relayerBundle.SepoliaConfig;
|
|
169
154
|
}
|
|
170
155
|
async function createRelayer(config) {
|
|
171
|
-
|
|
172
|
-
const instance = await
|
|
156
|
+
await initSDK2();
|
|
157
|
+
const instance = await relayerBundle.createInstance(config);
|
|
173
158
|
if (typeof config.network === "string") {
|
|
174
159
|
instance.network = config.network;
|
|
175
160
|
}
|
|
176
161
|
return instance;
|
|
177
162
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
163
|
+
var sdkInitialized = false;
|
|
164
|
+
async function initSDK2(params) {
|
|
165
|
+
if (sdkInitialized) {
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
const result = await relayerBundle.initSDK(params);
|
|
169
|
+
sdkInitialized = true;
|
|
170
|
+
return result;
|
|
181
171
|
}
|
|
182
172
|
async function createEncryptedAmountInput(relayer, contractAddress, senderAddress, amount) {
|
|
183
173
|
const normalizedContract = getAddress(contractAddress);
|
|
@@ -513,11 +503,10 @@ var ConfidentialToken = class {
|
|
|
513
503
|
};
|
|
514
504
|
export {
|
|
515
505
|
ConfidentialToken,
|
|
516
|
-
SepoliaConfig,
|
|
506
|
+
SepoliaConfig2 as SepoliaConfig,
|
|
517
507
|
confidentialErrorCodes,
|
|
518
508
|
confidentialPaymentTypes,
|
|
519
509
|
confidentialTokenAbi,
|
|
520
|
-
configureRelayerSdk,
|
|
521
510
|
createEncryptedAmountInput,
|
|
522
511
|
createNonce,
|
|
523
512
|
createRelayer,
|
|
@@ -525,7 +514,7 @@ export {
|
|
|
525
514
|
getSepoliaConfig,
|
|
526
515
|
getTransferAmounts,
|
|
527
516
|
hashEncryptedAmountInput,
|
|
528
|
-
initSDK,
|
|
517
|
+
initSDK2 as initSDK,
|
|
529
518
|
normalizeAmount,
|
|
530
519
|
publicDecrypt
|
|
531
520
|
};
|