@fluent.xyz/connect 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/dist/index.d.ts +580 -7
- package/dist/index.js +198 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createPublicClient, http, defineChain, encodeFunctionData, parseUnits,
|
|
1
|
+
import { createPublicClient, http, defineChain, formatUnits, encodeFunctionData, parseUnits, numberToHex, isHex, stringToHex, bytesToHex } from 'viem';
|
|
2
2
|
import { toCallPolicy, CallPolicyVersion, toTimestampPolicy, CallType, ParamCondition } from '@zerodev/permissions/policies';
|
|
3
3
|
export { CallType, ParamCondition } from '@zerodev/permissions/policies';
|
|
4
4
|
import { privateKeyToAccount, toAccount, generatePrivateKey } from 'viem/accounts';
|
|
@@ -35,6 +35,17 @@ var __export = (target, all) => {
|
|
|
35
35
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
+
// ../connect-sdk/src/abis/fluent-bridge.ts
|
|
39
|
+
var fluentBridgeAbi = [
|
|
40
|
+
{
|
|
41
|
+
type: "function",
|
|
42
|
+
name: "otherSideChainId",
|
|
43
|
+
stateMutability: "view",
|
|
44
|
+
inputs: [],
|
|
45
|
+
outputs: [{ name: "", type: "uint256" }]
|
|
46
|
+
}
|
|
47
|
+
];
|
|
48
|
+
|
|
38
49
|
// ../registry/data/chains/fluent-devnet.json
|
|
39
50
|
var fluent_devnet_default = {
|
|
40
51
|
id: "fluent-devnet",
|
|
@@ -723,15 +734,15 @@ var makeIssue = (params) => {
|
|
|
723
734
|
message: issueData.message
|
|
724
735
|
};
|
|
725
736
|
}
|
|
726
|
-
let
|
|
737
|
+
let errorMessage3 = "";
|
|
727
738
|
const maps = errorMaps.filter((m) => !!m).slice().reverse();
|
|
728
739
|
for (const map of maps) {
|
|
729
|
-
|
|
740
|
+
errorMessage3 = map(fullIssue, { data, defaultError: errorMessage3 }).message;
|
|
730
741
|
}
|
|
731
742
|
return {
|
|
732
743
|
...issueData,
|
|
733
744
|
path: fullPath,
|
|
734
|
-
message:
|
|
745
|
+
message: errorMessage3
|
|
735
746
|
};
|
|
736
747
|
};
|
|
737
748
|
var EMPTY_PATH = [];
|
|
@@ -4389,6 +4400,157 @@ var integrations = {
|
|
|
4389
4400
|
integrations.zerodev.supportedFluentChains.map(
|
|
4390
4401
|
(c) => c.chainId
|
|
4391
4402
|
);
|
|
4403
|
+
function getFluentChainByChainId(chainId) {
|
|
4404
|
+
return Object.values(fluentChains).find((c) => c.chainId === chainId);
|
|
4405
|
+
}
|
|
4406
|
+
function getL1ForFluentChain(fluent3) {
|
|
4407
|
+
if (!fluent3.parent) return void 0;
|
|
4408
|
+
return Object.values(l1Chains).find((l1) => l1.chainId === fluent3.parent.chainId);
|
|
4409
|
+
}
|
|
4410
|
+
|
|
4411
|
+
// ../connect-sdk/src/addresses.ts
|
|
4412
|
+
function resolveBridgeAddresses(definition) {
|
|
4413
|
+
const l1 = getL1ForFluentChain(definition);
|
|
4414
|
+
const l2Bridge = definition.contracts?.fluentBridge;
|
|
4415
|
+
return {
|
|
4416
|
+
l2: l2Bridge ? {
|
|
4417
|
+
proxy: l2Bridge.address,
|
|
4418
|
+
implementation: l2Bridge.implementation
|
|
4419
|
+
} : void 0,
|
|
4420
|
+
l1: l1?.contracts?.fluentBridge ? {
|
|
4421
|
+
proxy: l1.contracts.fluentBridge.address,
|
|
4422
|
+
implementation: l1.contracts.fluentBridge.implementation
|
|
4423
|
+
} : void 0
|
|
4424
|
+
};
|
|
4425
|
+
}
|
|
4426
|
+
function resolveL1Definition(definition) {
|
|
4427
|
+
return getL1ForFluentChain(definition);
|
|
4428
|
+
}
|
|
4429
|
+
function definitionForChain(chain) {
|
|
4430
|
+
const byId = getFluentChainByChainId(chain.id);
|
|
4431
|
+
if (byId) return byId;
|
|
4432
|
+
const known = Object.values(fluentChains).find((c) => c.chainId === chain.id);
|
|
4433
|
+
if (known) return known;
|
|
4434
|
+
throw new Error(
|
|
4435
|
+
`Unknown Fluent chain id ${chain.id}. Use a chain from @fluent.xyz/connect-sdk or register it in @fluent.xyz/registry.`
|
|
4436
|
+
);
|
|
4437
|
+
}
|
|
4438
|
+
function createFluentClient(config) {
|
|
4439
|
+
const definition = definitionForChain(config.chain);
|
|
4440
|
+
const publicClient = createPublicClient({
|
|
4441
|
+
chain: config.chain,
|
|
4442
|
+
transport: config.transport
|
|
4443
|
+
});
|
|
4444
|
+
const bridge = resolveBridgeAddresses(definition);
|
|
4445
|
+
const l2BridgeProxy = bridge.l2?.proxy ?? config.chain.contracts?.fluentBridge?.address;
|
|
4446
|
+
return {
|
|
4447
|
+
chain: config.chain,
|
|
4448
|
+
definition,
|
|
4449
|
+
public: publicClient,
|
|
4450
|
+
addresses: {
|
|
4451
|
+
bridge,
|
|
4452
|
+
peggedTokenPrecompile: definition.contracts?.peggedTokenPrecompile?.address,
|
|
4453
|
+
paymentGateway: definition.contracts?.paymentGateway?.address,
|
|
4454
|
+
universalTokenFactory: definition.contracts?.universalTokenFactory?.address
|
|
4455
|
+
},
|
|
4456
|
+
l1: resolveL1Definition(definition),
|
|
4457
|
+
readOtherSideChainId: async () => {
|
|
4458
|
+
if (!l2BridgeProxy) return void 0;
|
|
4459
|
+
try {
|
|
4460
|
+
return await publicClient.readContract({
|
|
4461
|
+
address: l2BridgeProxy,
|
|
4462
|
+
abi: fluentBridgeAbi,
|
|
4463
|
+
functionName: "otherSideChainId"
|
|
4464
|
+
});
|
|
4465
|
+
} catch {
|
|
4466
|
+
return void 0;
|
|
4467
|
+
}
|
|
4468
|
+
}
|
|
4469
|
+
};
|
|
4470
|
+
}
|
|
4471
|
+
|
|
4472
|
+
// ../connect-sdk/src/permissions.ts
|
|
4473
|
+
function withoutTrailingSlash(value) {
|
|
4474
|
+
return value.replace(/\/+$/, "");
|
|
4475
|
+
}
|
|
4476
|
+
function assertRequest(request) {
|
|
4477
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
4478
|
+
if (!request.appId.trim()) {
|
|
4479
|
+
throw new Error("appId is required");
|
|
4480
|
+
}
|
|
4481
|
+
if (!Number.isSafeInteger(request.expiry) || request.expiry <= now) {
|
|
4482
|
+
throw new Error("expiry must be a future Unix timestamp");
|
|
4483
|
+
}
|
|
4484
|
+
if (request.permissions.calls.length === 0 && request.permissions.spend.length === 0) {
|
|
4485
|
+
throw new Error("at least one call or spend permission is required");
|
|
4486
|
+
}
|
|
4487
|
+
}
|
|
4488
|
+
async function errorMessage(response) {
|
|
4489
|
+
const body = await response.json().catch(() => null);
|
|
4490
|
+
return body?.error ?? body?.message ?? `Request failed with ${response.status}`;
|
|
4491
|
+
}
|
|
4492
|
+
function createFluentPermissionClient(config) {
|
|
4493
|
+
const fetcher = config.fetch ?? globalThis.fetch;
|
|
4494
|
+
const baseUrl = withoutTrailingSlash(config.baseUrl);
|
|
4495
|
+
async function request(path, init = {}) {
|
|
4496
|
+
const sessionToken = await config.getSessionToken();
|
|
4497
|
+
if (!sessionToken) {
|
|
4498
|
+
throw new Error("Fluent session token is required");
|
|
4499
|
+
}
|
|
4500
|
+
const response = await fetcher(`${baseUrl}${path}`, {
|
|
4501
|
+
...init,
|
|
4502
|
+
headers: {
|
|
4503
|
+
Authorization: `Bearer ${sessionToken}`,
|
|
4504
|
+
"Content-Type": "application/json",
|
|
4505
|
+
...init.headers
|
|
4506
|
+
}
|
|
4507
|
+
});
|
|
4508
|
+
if (!response.ok) {
|
|
4509
|
+
throw new Error(await errorMessage(response));
|
|
4510
|
+
}
|
|
4511
|
+
return response.json();
|
|
4512
|
+
}
|
|
4513
|
+
return {
|
|
4514
|
+
async preview(grantRequest) {
|
|
4515
|
+
assertRequest(grantRequest);
|
|
4516
|
+
return request(
|
|
4517
|
+
"/v1/permission-grants/preview",
|
|
4518
|
+
{
|
|
4519
|
+
method: "POST",
|
|
4520
|
+
body: JSON.stringify({
|
|
4521
|
+
...grantRequest,
|
|
4522
|
+
clientId: config.clientId
|
|
4523
|
+
})
|
|
4524
|
+
}
|
|
4525
|
+
);
|
|
4526
|
+
},
|
|
4527
|
+
async grant(grantRequest) {
|
|
4528
|
+
assertRequest(grantRequest);
|
|
4529
|
+
return request("/v1/permission-grants", {
|
|
4530
|
+
method: "POST",
|
|
4531
|
+
body: JSON.stringify({
|
|
4532
|
+
...grantRequest,
|
|
4533
|
+
clientId: config.clientId
|
|
4534
|
+
})
|
|
4535
|
+
});
|
|
4536
|
+
},
|
|
4537
|
+
async list() {
|
|
4538
|
+
const response = await request(
|
|
4539
|
+
`/v1/permission-grants?clientId=${encodeURIComponent(config.clientId)}`
|
|
4540
|
+
);
|
|
4541
|
+
return response.grants;
|
|
4542
|
+
},
|
|
4543
|
+
revoke(grantId) {
|
|
4544
|
+
if (!grantId) {
|
|
4545
|
+
return Promise.reject(new Error("grantId is required"));
|
|
4546
|
+
}
|
|
4547
|
+
return request(
|
|
4548
|
+
`/v1/permission-grants/${encodeURIComponent(grantId)}/revoke`,
|
|
4549
|
+
{ method: "POST", body: "{}" }
|
|
4550
|
+
);
|
|
4551
|
+
}
|
|
4552
|
+
};
|
|
4553
|
+
}
|
|
4392
4554
|
var fluentTestnetTokenDefaults = {
|
|
4393
4555
|
ETH: {
|
|
4394
4556
|
chainId: 20994,
|
|
@@ -4409,7 +4571,29 @@ var fluentTestnetTokenDefaults = {
|
|
|
4409
4571
|
name: "Mock Blend",
|
|
4410
4572
|
decimals: 18,
|
|
4411
4573
|
address: "0x83Fed707A8dDDC2535aE591CF19fB6C91D542D8E"
|
|
4412
|
-
}
|
|
4574
|
+
},
|
|
4575
|
+
USDC: {
|
|
4576
|
+
chainId: 20994,
|
|
4577
|
+
symbol: "USDC",
|
|
4578
|
+
name: "USD Coin",
|
|
4579
|
+
decimals: 6,
|
|
4580
|
+
address: "0xC8Ebbf08Cb2A87aB90cC8EeC34C721764b7755e9"
|
|
4581
|
+
},
|
|
4582
|
+
USDT: {
|
|
4583
|
+
chainId: 20994,
|
|
4584
|
+
symbol: "USDT",
|
|
4585
|
+
name: "USDT",
|
|
4586
|
+
decimals: 6,
|
|
4587
|
+
address: "0xD80Ca465c268e76F0d897D44a35fC97Db75AB797"
|
|
4588
|
+
}
|
|
4589
|
+
};
|
|
4590
|
+
var fluentTestnetWidgetTokens = [
|
|
4591
|
+
fluentTestnetTokenDefaults.ETH,
|
|
4592
|
+
fluentTestnetTokenDefaults.USDnr,
|
|
4593
|
+
fluentTestnetTokenDefaults.BLEND,
|
|
4594
|
+
fluentTestnetTokenDefaults.USDC,
|
|
4595
|
+
fluentTestnetTokenDefaults.USDT
|
|
4596
|
+
];
|
|
4413
4597
|
var balanceOfAbi = [
|
|
4414
4598
|
{
|
|
4415
4599
|
type: "function",
|
|
@@ -4457,10 +4641,10 @@ async function readFluentTokenBalances(params) {
|
|
|
4457
4641
|
}
|
|
4458
4642
|
|
|
4459
4643
|
// ../connect-sdk/src/families.ts
|
|
4460
|
-
function
|
|
4644
|
+
function withoutTrailingSlash2(value) {
|
|
4461
4645
|
return value.replace(/\/+$/, "");
|
|
4462
4646
|
}
|
|
4463
|
-
async function
|
|
4647
|
+
async function errorMessage2(response) {
|
|
4464
4648
|
const body = await response.text().catch(() => "");
|
|
4465
4649
|
const parsed = body ? (() => {
|
|
4466
4650
|
try {
|
|
@@ -4473,7 +4657,7 @@ async function errorMessage(response) {
|
|
|
4473
4657
|
}
|
|
4474
4658
|
function createFluentFamiliesClient(config) {
|
|
4475
4659
|
const fetcher = config.fetch ?? globalThis.fetch;
|
|
4476
|
-
const baseUrl =
|
|
4660
|
+
const baseUrl = withoutTrailingSlash2(config.baseUrl);
|
|
4477
4661
|
return {
|
|
4478
4662
|
async getFamilies(privyId) {
|
|
4479
4663
|
const normalizedPrivyId = privyId.trim();
|
|
@@ -4484,7 +4668,7 @@ function createFluentFamiliesClient(config) {
|
|
|
4484
4668
|
endpoint.searchParams.set("privy_id", normalizedPrivyId);
|
|
4485
4669
|
const response = await fetcher(endpoint.toString());
|
|
4486
4670
|
if (!response.ok) {
|
|
4487
|
-
throw new Error(await
|
|
4671
|
+
throw new Error(await errorMessage2(response));
|
|
4488
4672
|
}
|
|
4489
4673
|
const result = await response.json();
|
|
4490
4674
|
return {
|
|
@@ -4542,9 +4726,9 @@ function l1DefinitionToViemChain(definition) {
|
|
|
4542
4726
|
}
|
|
4543
4727
|
|
|
4544
4728
|
// ../connect-sdk/src/chains.ts
|
|
4545
|
-
fluentDefinitionToViemChain(fluentChains.devnet);
|
|
4729
|
+
var fluentDevnet = fluentDefinitionToViemChain(fluentChains.devnet);
|
|
4546
4730
|
var fluentTestnet = fluentDefinitionToViemChain(fluentChains.testnet);
|
|
4547
|
-
fluentDefinitionToViemChain(fluentChains.mainnet);
|
|
4731
|
+
var fluentMainnet = fluentDefinitionToViemChain(fluentChains.mainnet);
|
|
4548
4732
|
l1DefinitionToViemChain(l1Chains.sepolia);
|
|
4549
4733
|
|
|
4550
4734
|
// ../connect-sdk/src/index.ts
|
|
@@ -4585,7 +4769,7 @@ function getOrCreateInstallationId(storage) {
|
|
|
4585
4769
|
storage?.setItem(INSTALLATION_ID_KEY, next);
|
|
4586
4770
|
return next;
|
|
4587
4771
|
}
|
|
4588
|
-
function
|
|
4772
|
+
function withoutTrailingSlash3(value) {
|
|
4589
4773
|
return value.replace(/\/+$/, "");
|
|
4590
4774
|
}
|
|
4591
4775
|
var FluentConnectSDK = class {
|
|
@@ -4623,7 +4807,7 @@ var FluentConnectSDK = class {
|
|
|
4623
4807
|
};
|
|
4624
4808
|
}
|
|
4625
4809
|
buildAuthorizeUrl(state = randomId()) {
|
|
4626
|
-
const url = new URL(
|
|
4810
|
+
const url = new URL(withoutTrailingSlash3(this.config.authorizeUrl), this.app.origin);
|
|
4627
4811
|
url.searchParams.set("origin", this.app.origin);
|
|
4628
4812
|
url.searchParams.set("installation_id", this.app.installationId);
|
|
4629
4813
|
url.searchParams.set("redirect_uri", this.config.redirectUri ?? this.app.origin);
|
|
@@ -8256,6 +8440,6 @@ function BatchOperationReviewModal({
|
|
|
8256
8440
|
);
|
|
8257
8441
|
}
|
|
8258
8442
|
|
|
8259
|
-
export { Button, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, FLUENT_GAS_PAYMENT_DEFAULT_ETH_RATES, FLUENT_GAS_PAYMENT_PRIORITY, FLUENT_WIDGET_SESSION_STORAGE_KEY, FLUENT_ZERODEV_ERC20_PAYMASTER_QUERY, FLUENT_ZERODEV_ERC20_PAYMASTER_TOKENS, FLUENT_ZERODEV_PAYMASTER_DEMO_RECIPIENT, FluentWidget, Icon, Separator, buttonVariants, createFluentBatchOp, createFluentPermissionApi, createFluentPermissionPolicyBuilders, createFluentPermissionSession, createFluentZeroDevErc20Paymaster, createFluentZeroDevErc20PaymasterApprovalCall, createFluentZeroDevErc20PaymasterClient, createFluentZeroDevErc20PaymasterRpcUrl, createFluentZeroDevPermissionSession, createFluentZeroDevRpcUrl, formatFluentGasTokenBalance, getFluentGasPaymentEthValue, getFluentGasPaymentTokens, getFluentGasPaymentValueTier, resolveFluentZeroDevErc20PaymasterToken, selectFluentGasPaymentToken, sendFluentZeroDevErc20PaymasterDemo, useFluentZeroDevAccount };
|
|
8443
|
+
export { Button, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, FLUENT_GAS_PAYMENT_DEFAULT_ETH_RATES, FLUENT_GAS_PAYMENT_PRIORITY, FLUENT_WIDGET_SESSION_STORAGE_KEY, FLUENT_ZERODEV_ERC20_PAYMASTER_QUERY, FLUENT_ZERODEV_ERC20_PAYMASTER_TOKENS, FLUENT_ZERODEV_PAYMASTER_DEMO_RECIPIENT, FluentWidget, Icon, Separator, buttonVariants, createFluentBatchOp, createFluentClient, createFluentFamiliesClient, createFluentPermissionApi, createFluentPermissionClient, createFluentPermissionPolicyBuilders, createFluentPermissionSession, createFluentZeroDevErc20Paymaster, createFluentZeroDevErc20PaymasterApprovalCall, createFluentZeroDevErc20PaymasterClient, createFluentZeroDevErc20PaymasterRpcUrl, createFluentZeroDevPermissionSession, createFluentZeroDevRpcUrl, fluent2 as fluent, fluentDevnet, fluentMainnet, fluentTestnet, fluentTestnetTokenDefaults, fluentTestnetWidgetTokens, formatFluentGasTokenBalance, getFluentGasPaymentEthValue, getFluentGasPaymentTokens, getFluentGasPaymentValueTier, readFluentTokenBalances, resolveFluentZeroDevErc20PaymasterToken, selectFluentGasPaymentToken, sendFluentZeroDevErc20PaymasterDemo, useFluentZeroDevAccount };
|
|
8260
8444
|
//# sourceMappingURL=index.js.map
|
|
8261
8445
|
//# sourceMappingURL=index.js.map
|