@fogo/sessions-sdk 0.0.17 → 0.0.19
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/cjs/connection.d.ts +47 -0
- package/cjs/connection.js +191 -0
- package/cjs/context.d.ts +14 -37
- package/cjs/context.js +13 -126
- package/cjs/index.d.ts +43 -4
- package/cjs/index.js +234 -14
- package/esm/connection.d.ts +47 -0
- package/esm/connection.js +187 -0
- package/esm/context.d.ts +14 -37
- package/esm/context.js +13 -126
- package/esm/index.d.ts +43 -4
- package/esm/index.js +226 -10
- package/package.json +7 -2
package/esm/context.js
CHANGED
|
@@ -1,132 +1,25 @@
|
|
|
1
1
|
import { AnchorProvider } from "@coral-xyz/anchor";
|
|
2
2
|
import { ChainIdProgram } from "@fogo/sessions-idls";
|
|
3
|
-
import {
|
|
4
|
-
import { createTransactionMessage, setTransactionMessageFeePayer, setTransactionMessageLifetimeUsingBlockhash, appendTransactionMessageInstructions, getBase64EncodedWireTransaction, partiallySignTransactionMessageWithSigners, pipe, createSolanaRpc, addSignersToTransactionMessage, compressTransactionMessageUsingAddressLookupTables, createSignerFromKeyPair, partiallySignTransaction, } from "@solana/kit";
|
|
5
|
-
import { PublicKey, Keypair, TransactionInstruction, VersionedTransaction, } from "@solana/web3.js";
|
|
6
|
-
import { z } from "zod";
|
|
3
|
+
import { Connection as Web3Connection, Keypair } from "@solana/web3.js";
|
|
7
4
|
// eslint-disable-next-line unicorn/no-typeof-undefined
|
|
8
5
|
const IS_BROWSER = typeof globalThis.window !== "undefined";
|
|
9
|
-
const DEFAULT_PAYMASTER = "https://paymaster.fogo.io";
|
|
10
|
-
const DEFAULT_ADDRESS_LOOKUP_TABLE_ADDRESS = "B8cUjJMqaWWTNNSTXBmeptjWswwCH1gTSCRYv4nu7kJW";
|
|
11
|
-
export var TransactionResultType;
|
|
12
|
-
(function (TransactionResultType) {
|
|
13
|
-
TransactionResultType[TransactionResultType["Success"] = 0] = "Success";
|
|
14
|
-
TransactionResultType[TransactionResultType["Failed"] = 1] = "Failed";
|
|
15
|
-
})(TransactionResultType || (TransactionResultType = {}));
|
|
16
|
-
const TransactionResult = {
|
|
17
|
-
Success: (signature) => ({
|
|
18
|
-
type: TransactionResultType.Success,
|
|
19
|
-
signature,
|
|
20
|
-
}),
|
|
21
|
-
Failed: (signature, error) => ({
|
|
22
|
-
type: TransactionResultType.Failed,
|
|
23
|
-
signature,
|
|
24
|
-
error,
|
|
25
|
-
}),
|
|
26
|
-
};
|
|
27
6
|
export const createSessionContext = async (options) => {
|
|
28
|
-
const addressLookupTables = await getAddressLookupTables(options.connection, options.addressLookupTableAddress);
|
|
29
7
|
const domain = getDomain(options.domain);
|
|
30
|
-
const sponsor = await getSponsor(
|
|
8
|
+
const sponsor = await options.connection.getSponsor(domain);
|
|
31
9
|
return {
|
|
32
|
-
|
|
33
|
-
payer: sponsor,
|
|
34
|
-
chainId: await fetchChainId(options.connection),
|
|
10
|
+
chainId: await fetchChainId(options.connection.connection),
|
|
35
11
|
domain: getDomain(options.domain),
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
? await createSignerFromKeyPair(sessionKey)
|
|
46
|
-
: undefined;
|
|
47
|
-
if (Array.isArray(instructions)) {
|
|
48
|
-
return partiallySignTransactionMessageWithSigners(pipe(createTransactionMessage({ version: 0 }), (tx) => setTransactionMessageFeePayer(fromLegacyPublicKey(sponsor), tx), (tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx), (tx) => appendTransactionMessageInstructions(instructions.map((instruction) => instruction instanceof TransactionInstruction
|
|
49
|
-
? fromLegacyTransactionInstruction(instruction)
|
|
50
|
-
: instruction), tx), (tx) => compressTransactionMessageUsingAddressLookupTables(tx, Object.fromEntries(addressLookupTables?.map((table) => [
|
|
51
|
-
fromLegacyPublicKey(table.key),
|
|
52
|
-
table.state.addresses.map((address) => fromLegacyPublicKey(address)),
|
|
53
|
-
]) ?? [])), (tx) => sessionKeySigner === undefined
|
|
54
|
-
? tx
|
|
55
|
-
: addSignersToTransactionMessage([sessionKeySigner], tx)));
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
const tx = instructions instanceof VersionedTransaction
|
|
59
|
-
? fromVersionedTransaction(instructions) // VersionedTransaction has a lifetime so it's fine to cast it so we can call partiallySignTransaction
|
|
60
|
-
: instructions;
|
|
61
|
-
return sessionKey === undefined
|
|
62
|
-
? tx
|
|
63
|
-
: partiallySignTransaction([sessionKey], tx);
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
const getSponsor = async (options, domain) => {
|
|
67
|
-
if (options.sponsor === undefined) {
|
|
68
|
-
const url = new URL("/api/sponsor_pubkey", options.paymaster ?? DEFAULT_PAYMASTER);
|
|
69
|
-
url.searchParams.set("domain", domain);
|
|
70
|
-
const response = await fetch(url);
|
|
71
|
-
if (response.status === 200) {
|
|
72
|
-
return new PublicKey(z.string().parse(await response.text()));
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
throw new PaymasterResponseError(response.status, await response.text());
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
return options.sponsor;
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
const sponsorAndSendResponseSchema = z
|
|
83
|
-
.discriminatedUnion("type", [
|
|
84
|
-
z.object({
|
|
85
|
-
type: z.literal("success"),
|
|
86
|
-
signature: z.string(),
|
|
87
|
-
}),
|
|
88
|
-
z.object({
|
|
89
|
-
type: z.literal("failed"),
|
|
90
|
-
signature: z.string(),
|
|
91
|
-
error: z.object({
|
|
92
|
-
InstructionError: z.tuple([z.number(), z.unknown()]),
|
|
12
|
+
payer: sponsor,
|
|
13
|
+
getSolanaConnection: options.connection.getSolanaConnection,
|
|
14
|
+
connection: options.connection.connection,
|
|
15
|
+
rpc: options.connection.rpc,
|
|
16
|
+
network: options.connection.network,
|
|
17
|
+
sendTransaction: (sessionKey, instructions, extraConfig) => options.connection.sendToPaymaster(domain, sponsor, sessionKey, instructions, {
|
|
18
|
+
addressLookupTable: extraConfig?.addressLookupTable ??
|
|
19
|
+
options.defaultAddressLookupTableAddress,
|
|
20
|
+
extraSigners: extraConfig?.extraSigners,
|
|
93
21
|
}),
|
|
94
|
-
}
|
|
95
|
-
])
|
|
96
|
-
.transform((data) => {
|
|
97
|
-
return data.type === "success"
|
|
98
|
-
? TransactionResult.Success(data.signature)
|
|
99
|
-
: TransactionResult.Failed(data.signature, data.error);
|
|
100
|
-
});
|
|
101
|
-
const sendToPaymaster = async (options, transaction, domain) => {
|
|
102
|
-
if (options.sendToPaymaster === undefined) {
|
|
103
|
-
const url = new URL("/api/sponsor_and_send", options.paymaster ?? DEFAULT_PAYMASTER);
|
|
104
|
-
url.searchParams.set("domain", domain);
|
|
105
|
-
const response = await fetch(url, {
|
|
106
|
-
method: "POST",
|
|
107
|
-
headers: {
|
|
108
|
-
"Content-Type": "application/json",
|
|
109
|
-
},
|
|
110
|
-
body: JSON.stringify({
|
|
111
|
-
transaction: getBase64EncodedWireTransaction(transaction),
|
|
112
|
-
}),
|
|
113
|
-
});
|
|
114
|
-
if (response.status === 200) {
|
|
115
|
-
return sponsorAndSendResponseSchema.parse(await response.json());
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
throw new PaymasterResponseError(response.status, await response.text());
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
return options.sendToPaymaster(transaction);
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
const getAddressLookupTables = async (connection, addressLookupTableAddress = DEFAULT_ADDRESS_LOOKUP_TABLE_ADDRESS) => {
|
|
126
|
-
const addressLookupTableResult = await connection.getAddressLookupTable(new PublicKey(addressLookupTableAddress));
|
|
127
|
-
return addressLookupTableResult.value
|
|
128
|
-
? [addressLookupTableResult.value]
|
|
129
|
-
: undefined;
|
|
22
|
+
};
|
|
130
23
|
};
|
|
131
24
|
const fetchChainId = async (connection) => {
|
|
132
25
|
const chainIdProgram = new ChainIdProgram(new AnchorProvider(connection, { publicKey: new Keypair().publicKey }, {})); // We mock the wallet because we don't need to sign anything
|
|
@@ -153,12 +46,6 @@ const getDomain = (requestedDomain) => {
|
|
|
153
46
|
return requestedDomain;
|
|
154
47
|
}
|
|
155
48
|
};
|
|
156
|
-
class PaymasterResponseError extends Error {
|
|
157
|
-
constructor(statusCode, message) {
|
|
158
|
-
super(`Paymaster sent a ${statusCode.toString()} response: ${message}`);
|
|
159
|
-
this.name = "PaymasterResponseError";
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
49
|
class NoChainIdAddressError extends Error {
|
|
163
50
|
constructor() {
|
|
164
51
|
super("Failed to derive chain ID address");
|
package/esm/index.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
1
|
+
import type { BaseWalletAdapter, MessageSignerWalletAdapterProps } from "@solana/wallet-adapter-base";
|
|
2
|
+
import type { TransactionError } from "@solana/web3.js";
|
|
3
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
4
|
+
import type { Chain } from "@wormhole-foundation/sdk";
|
|
3
5
|
import BN from "bn.js";
|
|
4
6
|
import { z } from "zod";
|
|
5
|
-
import type {
|
|
6
|
-
|
|
7
|
+
import type { TransactionResult } from "./connection.js";
|
|
8
|
+
import type { SessionContext } from "./context.js";
|
|
9
|
+
export { type SessionContext, createSessionContext } from "./context.js";
|
|
10
|
+
export { type TransactionResult, type Connection, Network, TransactionResultType, createSessionConnection, } from "./connection.js";
|
|
7
11
|
type EstablishSessionOptions = {
|
|
8
12
|
context: SessionContext;
|
|
9
13
|
walletPublicKey: PublicKey;
|
|
@@ -11,6 +15,7 @@ type EstablishSessionOptions = {
|
|
|
11
15
|
expires: Date;
|
|
12
16
|
extra?: Record<string, string> | undefined;
|
|
13
17
|
createUnsafeExtractableSessionKey?: boolean | undefined;
|
|
18
|
+
sessionEstablishmentLookupTable?: string | undefined;
|
|
14
19
|
} & ({
|
|
15
20
|
limits?: Map<PublicKey, bigint>;
|
|
16
21
|
unlimited?: false;
|
|
@@ -1314,6 +1319,40 @@ type SendTransferOptions = {
|
|
|
1314
1319
|
recipient: PublicKey;
|
|
1315
1320
|
};
|
|
1316
1321
|
export declare const sendTransfer: (options: SendTransferOptions) => Promise<TransactionResult>;
|
|
1322
|
+
type SendBridgeOutOptions = {
|
|
1323
|
+
context: SessionContext;
|
|
1324
|
+
sessionKey: CryptoKeyPair;
|
|
1325
|
+
sessionPublicKey: PublicKey;
|
|
1326
|
+
walletPublicKey: PublicKey;
|
|
1327
|
+
solanaWallet: MessageSignerWalletAdapterProps;
|
|
1328
|
+
amount: bigint;
|
|
1329
|
+
fromToken: WormholeToken & {
|
|
1330
|
+
chain: "Fogo";
|
|
1331
|
+
};
|
|
1332
|
+
toToken: WormholeToken & {
|
|
1333
|
+
chain: "Solana";
|
|
1334
|
+
};
|
|
1335
|
+
};
|
|
1336
|
+
type WormholeToken = {
|
|
1337
|
+
chain: Chain;
|
|
1338
|
+
mint: PublicKey;
|
|
1339
|
+
manager: PublicKey;
|
|
1340
|
+
transceiver: PublicKey;
|
|
1341
|
+
};
|
|
1342
|
+
export declare const bridgeOut: (options: SendBridgeOutOptions) => Promise<TransactionResult>;
|
|
1343
|
+
type SendBridgeInOptions = {
|
|
1344
|
+
context: SessionContext;
|
|
1345
|
+
walletPublicKey: PublicKey;
|
|
1346
|
+
solanaWallet: BaseWalletAdapter;
|
|
1347
|
+
amount: bigint;
|
|
1348
|
+
fromToken: WormholeToken & {
|
|
1349
|
+
chain: "Solana";
|
|
1350
|
+
};
|
|
1351
|
+
toToken: WormholeToken & {
|
|
1352
|
+
chain: "Fogo";
|
|
1353
|
+
};
|
|
1354
|
+
};
|
|
1355
|
+
export declare const bridgeIn: (options: SendBridgeInOptions) => Promise<import("@wormhole-foundation/sdk").CreatedTransferReceipt<"Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore", "Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore"> | import("@wormhole-foundation/sdk").SourceInitiatedTransferReceipt<"Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore", "Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore"> | import("@wormhole-foundation/sdk").FailedTransferReceipt<import("@wormhole-foundation/sdk").AttestationReceipt<keyof import("@wormhole-foundation/sdk-definitions").WormholeRegistry.ProtocolToInterfaceMapping<"Mainnet" | "Testnet" | "Devnet", "Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore">>, "Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore", "Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore"> | import("@wormhole-foundation/sdk").SourceFinalizedTransferReceipt<import("@wormhole-foundation/sdk").AttestationReceipt<keyof import("@wormhole-foundation/sdk-definitions").WormholeRegistry.ProtocolToInterfaceMapping<"Mainnet" | "Testnet" | "Devnet", "Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore">>, "Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore", "Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore"> | import("@wormhole-foundation/sdk").InReviewTransferReceipt<import("@wormhole-foundation/sdk").AttestationReceipt<keyof import("@wormhole-foundation/sdk-definitions").WormholeRegistry.ProtocolToInterfaceMapping<"Mainnet" | "Testnet" | "Devnet", "Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore">>, "Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore", "Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore"> | import("@wormhole-foundation/sdk").AttestedTransferReceipt<import("@wormhole-foundation/sdk").AttestationReceipt<keyof import("@wormhole-foundation/sdk-definitions").WormholeRegistry.ProtocolToInterfaceMapping<"Mainnet" | "Testnet" | "Devnet", "Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore">>, "Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore", "Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore"> | import("@wormhole-foundation/sdk").RefundedTransferReceipt<import("@wormhole-foundation/sdk").AttestationReceipt<keyof import("@wormhole-foundation/sdk-definitions").WormholeRegistry.ProtocolToInterfaceMapping<"Mainnet" | "Testnet" | "Devnet", "Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore">>, "Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore", "Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore"> | import("@wormhole-foundation/sdk").RedeemedTransferReceipt<import("@wormhole-foundation/sdk").AttestationReceipt<keyof import("@wormhole-foundation/sdk-definitions").WormholeRegistry.ProtocolToInterfaceMapping<"Mainnet" | "Testnet" | "Devnet", "Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore">>, "Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore", "Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore"> | import("@wormhole-foundation/sdk").DestinationQueuedTransferReceipt<import("@wormhole-foundation/sdk").AttestationReceipt<keyof import("@wormhole-foundation/sdk-definitions").WormholeRegistry.ProtocolToInterfaceMapping<"Mainnet" | "Testnet" | "Devnet", "Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore">>, "Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore", "Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore"> | import("@wormhole-foundation/sdk").CompletedTransferReceipt<import("@wormhole-foundation/sdk").AttestationReceipt<keyof import("@wormhole-foundation/sdk-definitions").WormholeRegistry.ProtocolToInterfaceMapping<"Mainnet" | "Testnet" | "Devnet", "Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore">>, "Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore", "Fogo" | "Solana" | "Ethereum" | "Bsc" | "Polygon" | "Avalanche" | "Algorand" | "Fantom" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Pythnet" | "Btc" | "Base" | "Sei" | "Scroll" | "Mantle" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Mezo" | "Sonic" | "Converge" | "Plume" | "XRPLEVM" | "Plasma" | "CreditCoin" | "Stacks" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia" | "HyperCore">>;
|
|
1317
1356
|
/**
|
|
1318
1357
|
* Create a login token signed with the session key
|
|
1319
1358
|
* @param session - The session to create a login token for
|
package/esm/index.js
CHANGED
|
@@ -7,13 +7,20 @@ import { sha256 } from "@noble/hashes/sha2";
|
|
|
7
7
|
import { fromLegacyPublicKey } from "@solana/compat";
|
|
8
8
|
import { generateKeyPair, getAddressFromPublicKey, getProgramDerivedAddress, signatureBytes, verifySignature, } from "@solana/kit";
|
|
9
9
|
import { createAssociatedTokenAccountIdempotentInstruction, getAssociatedTokenAddressSync, getMint, } from "@solana/spl-token";
|
|
10
|
-
import { Ed25519Program, PublicKey } from "@solana/web3.js";
|
|
10
|
+
import { Connection, Ed25519Program, Keypair, PublicKey, } from "@solana/web3.js";
|
|
11
|
+
import { Wormhole, wormhole, routes } from "@wormhole-foundation/sdk";
|
|
12
|
+
import solanaSdk from "@wormhole-foundation/sdk/solana";
|
|
13
|
+
import { contracts } from "@wormhole-foundation/sdk-base";
|
|
14
|
+
import { nttExecutorRoute } from "@wormhole-foundation/sdk-route-ntt";
|
|
15
|
+
import { utils } from "@wormhole-foundation/sdk-solana-core";
|
|
16
|
+
import { NTT } from "@wormhole-foundation/sdk-solana-ntt";
|
|
11
17
|
import BN from "bn.js";
|
|
12
18
|
import bs58 from "bs58";
|
|
13
19
|
import { z } from "zod";
|
|
14
|
-
import { TransactionResultType } from "./
|
|
20
|
+
import { Network, TransactionResultType } from "./connection.js";
|
|
15
21
|
import { importKey, signMessageWithKey, verifyMessageWithKey, } from "./crypto.js";
|
|
16
|
-
export { createSessionContext
|
|
22
|
+
export { createSessionContext } from "./context.js";
|
|
23
|
+
export { Network, TransactionResultType, createSessionConnection, } from "./connection.js";
|
|
17
24
|
const MESSAGE_HEADER = `Fogo Sessions:
|
|
18
25
|
Signing this intent will allow this app to interact with your on-chain balances. Please make sure you trust this app and the domain in the message matches the domain of the current web application.
|
|
19
26
|
`;
|
|
@@ -23,6 +30,12 @@ const CURRENT_MAJOR = "0";
|
|
|
23
30
|
const CURRENT_MINOR = "3";
|
|
24
31
|
const CURRENT_INTENT_TRANSFER_MAJOR = "0";
|
|
25
32
|
const CURRENT_INTENT_TRANSFER_MINOR = "1";
|
|
33
|
+
const CURRENT_BRIDGE_OUT_MAJOR = "0";
|
|
34
|
+
const CURRENT_BRIDGE_OUT_MINOR = "1";
|
|
35
|
+
const SESSION_ESTABLISHMENT_LOOKUP_TABLE_ADDRESS = {
|
|
36
|
+
[Network.Testnet]: "B8cUjJMqaWWTNNSTXBmeptjWswwCH1gTSCRYv4nu7kJW",
|
|
37
|
+
[Network.Mainnet]: undefined,
|
|
38
|
+
};
|
|
26
39
|
export const establishSession = async (options) => {
|
|
27
40
|
const sessionKey = options.createUnsafeExtractableSessionKey
|
|
28
41
|
? await crypto.subtle.generateKey("Ed25519", true, ["sign", "verify"])
|
|
@@ -31,7 +44,7 @@ export const establishSession = async (options) => {
|
|
|
31
44
|
return sendSessionEstablishTransaction(options, sessionKey, await Promise.all([
|
|
32
45
|
buildIntentInstruction(options, sessionKey),
|
|
33
46
|
buildStartSessionInstruction(options, sessionKey),
|
|
34
|
-
]));
|
|
47
|
+
]), options.sessionEstablishmentLookupTable);
|
|
35
48
|
}
|
|
36
49
|
else {
|
|
37
50
|
const filteredLimits = new Map(options.limits?.entries().filter(([, amount]) => amount > 0n));
|
|
@@ -46,11 +59,14 @@ export const establishSession = async (options) => {
|
|
|
46
59
|
...buildCreateAssociatedTokenAccountInstructions(options, tokenInfo),
|
|
47
60
|
intentInstruction,
|
|
48
61
|
startSessionInstruction,
|
|
49
|
-
]);
|
|
62
|
+
], options.sessionEstablishmentLookupTable);
|
|
50
63
|
}
|
|
51
64
|
};
|
|
52
|
-
const sendSessionEstablishTransaction = async (options, sessionKey, instructions) => {
|
|
53
|
-
const result = await options.context.sendTransaction(sessionKey, instructions
|
|
65
|
+
const sendSessionEstablishTransaction = async (options, sessionKey, instructions, sessionEstablishmentLookupTable) => {
|
|
66
|
+
const result = await options.context.sendTransaction(sessionKey, instructions, {
|
|
67
|
+
addressLookupTable: sessionEstablishmentLookupTable ??
|
|
68
|
+
SESSION_ESTABLISHMENT_LOOKUP_TABLE_ADDRESS[options.context.network],
|
|
69
|
+
});
|
|
54
70
|
switch (result.type) {
|
|
55
71
|
case TransactionResultType.Success: {
|
|
56
72
|
const session = await createSession(options.context, options.walletPublicKey, sessionKey);
|
|
@@ -409,6 +425,13 @@ export const getDomainRecordAddress = (domain) => {
|
|
|
409
425
|
const hash = sha256(domain);
|
|
410
426
|
return PublicKey.findProgramAddressSync([Buffer.from("domain-record"), hash], new PublicKey(DomainRegistryIdl.address))[0];
|
|
411
427
|
};
|
|
428
|
+
const BRIDGING_ADDRESS_LOOKUP_TABLE = {
|
|
429
|
+
[Network.Testnet]: {
|
|
430
|
+
// USDC
|
|
431
|
+
ELNbJ1RtERV2fjtuZjbTscDekWhVzkQ1LjmiPsxp5uND: "4FCi6LptexBdZtaePsoCMeb1XpCijxnWu96g5LsSb6WP",
|
|
432
|
+
},
|
|
433
|
+
[Network.Mainnet]: undefined,
|
|
434
|
+
};
|
|
412
435
|
const buildStartSessionInstruction = async (options, sessionKey, tokens) => {
|
|
413
436
|
const instruction = new SessionManagerProgram(new AnchorProvider(options.context.connection, {}, {})).methods
|
|
414
437
|
.startSession()
|
|
@@ -490,7 +513,7 @@ export const sendTransfer = async (options) => {
|
|
|
490
513
|
};
|
|
491
514
|
const buildTransferIntentInstruction = async (program, options, symbol) => {
|
|
492
515
|
const [nonce, { decimals }] = await Promise.all([
|
|
493
|
-
getNonce(program, options.walletPublicKey),
|
|
516
|
+
getNonce(program, options.walletPublicKey, NonceType.Transfer),
|
|
494
517
|
getMint(options.context.connection, options.mint),
|
|
495
518
|
]);
|
|
496
519
|
const message = new TextEncoder().encode([
|
|
@@ -511,13 +534,206 @@ const buildTransferIntentInstruction = async (program, options, symbol) => {
|
|
|
511
534
|
message: await addOffchainMessagePrefixToMessageIfNeeded(options.walletPublicKey, intentSignature, message),
|
|
512
535
|
});
|
|
513
536
|
};
|
|
514
|
-
const
|
|
537
|
+
const BRIDGE_OUT_MESSAGE_HEADER = `Fogo Bridge Transfer:
|
|
538
|
+
Signing this intent will bridge out the tokens as described below.
|
|
539
|
+
`;
|
|
540
|
+
export const bridgeOut = async (options) => {
|
|
541
|
+
const { wh, route, transferRequest, transferParams, decimals } = await buildWormholeTransfer(options, options.context.connection);
|
|
542
|
+
// @ts-expect-error the wormhole client types are incorrect and do not
|
|
543
|
+
// properly represent the runtime representation.
|
|
544
|
+
const quote = await route.fetchExecutorQuote(transferRequest, transferParams);
|
|
545
|
+
const program = new IntentTransferProgram(new AnchorProvider(options.context.connection, {}, {}));
|
|
546
|
+
const umi = createUmi(options.context.connection.rpcEndpoint);
|
|
547
|
+
const metaplexMint = metaplexPublicKey(options.fromToken.mint.toBase58());
|
|
548
|
+
const metadataAddress = findMetadataPda(umi, { mint: metaplexMint })[0];
|
|
549
|
+
const outboxItem = Keypair.generate();
|
|
550
|
+
const [metadata, nttPdas] = await Promise.all([
|
|
551
|
+
safeFetchMetadata(umi, metadataAddress),
|
|
552
|
+
getNttPdas(options, wh, program, outboxItem.publicKey, new PublicKey(quote.payeeAddress)),
|
|
553
|
+
]);
|
|
554
|
+
const bridgeInstruction = await program.methods
|
|
555
|
+
.bridgeNttTokens({
|
|
556
|
+
execAmount: new BN(quote.estimatedCost.toString()),
|
|
557
|
+
relayInstructions: Buffer.from(quote.relayInstructions),
|
|
558
|
+
signedQuoteBytes: Buffer.from(quote.signedQuote),
|
|
559
|
+
})
|
|
560
|
+
.accounts({
|
|
561
|
+
sponsor: options.context.payer,
|
|
562
|
+
mint: options.fromToken.mint,
|
|
563
|
+
metadata:
|
|
564
|
+
// eslint-disable-next-line unicorn/no-null
|
|
565
|
+
metadata?.symbol === undefined ? null : new PublicKey(metadataAddress),
|
|
566
|
+
source: getAssociatedTokenAddressSync(options.fromToken.mint, options.walletPublicKey),
|
|
567
|
+
ntt: nttPdas,
|
|
568
|
+
})
|
|
569
|
+
.instruction();
|
|
570
|
+
return options.context.sendTransaction(options.sessionKey, [
|
|
571
|
+
await buildBridgeOutIntent(program, options, decimals, metadata?.symbol),
|
|
572
|
+
bridgeInstruction,
|
|
573
|
+
], {
|
|
574
|
+
extraSigners: [outboxItem],
|
|
575
|
+
addressLookupTable: BRIDGING_ADDRESS_LOOKUP_TABLE[options.context.network]?.[options.fromToken.mint.toBase58()],
|
|
576
|
+
});
|
|
577
|
+
};
|
|
578
|
+
// Here we use the Wormhole SDKs to produce the wormhole pdas that are needed
|
|
579
|
+
// for the bridge out transaction. Currently this is using wormhole SDK apis
|
|
580
|
+
// that are _technically_ public but it seems likely these are not considered to
|
|
581
|
+
// be truly public. It might be better to extract the pdas by using the sdk to
|
|
582
|
+
// generate (but not send) a transaction, and taking the pdas from that. That
|
|
583
|
+
// may be something to revisit in the future if we find that the wormhole sdk
|
|
584
|
+
// upgrades in ways that break these calls.
|
|
585
|
+
const getNttPdas = async (options, wh, program, outboxItemPublicKey, quotePayeeAddress) => {
|
|
586
|
+
const pdas = NTT.pdas(options.fromToken.manager);
|
|
587
|
+
const solana = wh.getChain("Solana");
|
|
588
|
+
const coreBridgeContract = contracts.coreBridge.get(wh.network, "Fogo");
|
|
589
|
+
if (coreBridgeContract === undefined) {
|
|
590
|
+
throw new Error("Core bridge contract address not returned by wormhole!");
|
|
591
|
+
}
|
|
592
|
+
const transceiverPdas = NTT.transceiverPdas(options.fromToken.manager);
|
|
593
|
+
const [intentTransferSetterPda] = PublicKey.findProgramAddressSync([Buffer.from("intent_transfer")], program.programId);
|
|
594
|
+
const wormholePdas = utils.getWormholeDerivedAccounts(options.fromToken.manager, coreBridgeContract);
|
|
595
|
+
return {
|
|
596
|
+
emitter: transceiverPdas.emitterAccount(),
|
|
597
|
+
nttConfig: pdas.configAccount(),
|
|
598
|
+
nttCustody: await NTT.custodyAccountAddress(pdas, options.fromToken.mint),
|
|
599
|
+
nttInboxRateLimit: pdas.inboxRateLimitAccount(solana.chain),
|
|
600
|
+
nttManager: options.fromToken.manager,
|
|
601
|
+
nttOutboxItem: outboxItemPublicKey,
|
|
602
|
+
nttOutboxRateLimit: pdas.outboxRateLimitAccount(),
|
|
603
|
+
nttPeer: pdas.peerAccount(solana.chain),
|
|
604
|
+
nttSessionAuthority: pdas.sessionAuthority(intentTransferSetterPda, NTT.transferArgs(options.amount, Wormhole.chainAddress("Solana", options.walletPublicKey.toBase58()), false)),
|
|
605
|
+
nttTokenAuthority: pdas.tokenAuthority(),
|
|
606
|
+
payeeNttWithExecutor: quotePayeeAddress,
|
|
607
|
+
transceiver: options.fromToken.transceiver,
|
|
608
|
+
wormholeBridge: wormholePdas.wormholeBridge,
|
|
609
|
+
wormholeFeeCollector: wormholePdas.wormholeFeeCollector,
|
|
610
|
+
wormholeMessage: transceiverPdas.wormholeMessageAccount(outboxItemPublicKey),
|
|
611
|
+
wormholeSequence: wormholePdas.wormholeSequence,
|
|
612
|
+
};
|
|
613
|
+
};
|
|
614
|
+
const buildBridgeOutIntent = async (program, options, decimals, symbol) => {
|
|
615
|
+
const nonce = await getNonce(program, options.walletPublicKey, NonceType.Bridge);
|
|
616
|
+
const message = new TextEncoder().encode([
|
|
617
|
+
BRIDGE_OUT_MESSAGE_HEADER,
|
|
618
|
+
serializeKV({
|
|
619
|
+
version: `${CURRENT_BRIDGE_OUT_MAJOR}.${CURRENT_BRIDGE_OUT_MINOR}`,
|
|
620
|
+
from_chain_id: options.context.chainId,
|
|
621
|
+
to_chain_id: "solana",
|
|
622
|
+
token: symbol ?? options.fromToken.mint.toBase58(),
|
|
623
|
+
amount: amountToString(options.amount, decimals),
|
|
624
|
+
recipient_address: options.walletPublicKey.toBase58(),
|
|
625
|
+
nonce: nonce === null ? "1" : nonce.nonce.add(new BN(1)).toString(),
|
|
626
|
+
}),
|
|
627
|
+
].join("\n"));
|
|
628
|
+
const intentSignature = signatureBytes(await options.solanaWallet.signMessage(message));
|
|
629
|
+
return Ed25519Program.createInstructionWithPublicKey({
|
|
630
|
+
publicKey: options.walletPublicKey.toBytes(),
|
|
631
|
+
signature: intentSignature,
|
|
632
|
+
message: await addOffchainMessagePrefixToMessageIfNeeded(options.walletPublicKey, intentSignature, message),
|
|
633
|
+
});
|
|
634
|
+
};
|
|
635
|
+
export const bridgeIn = async (options) => {
|
|
636
|
+
const solanaConnection = await options.context.getSolanaConnection();
|
|
637
|
+
const { route, transferRequest, transferParams } = await buildWormholeTransfer(options, solanaConnection);
|
|
638
|
+
// @ts-expect-error the wormhole client types are incorrect and do not
|
|
639
|
+
// properly represent the runtime representation.
|
|
640
|
+
const quote = await route.quote(transferRequest, transferParams);
|
|
641
|
+
if (quote.success) {
|
|
642
|
+
return await routes.checkAndCompleteTransfer(route, await route.initiate(transferRequest, {
|
|
643
|
+
address: () => options.walletPublicKey.toBase58(),
|
|
644
|
+
chain: () => "Solana",
|
|
645
|
+
signAndSend: (transactions) => Promise.all(transactions.map(({ transaction }) => options.solanaWallet.sendTransaction(
|
|
646
|
+
// Hooray for Wormhole's incomplete typing eh?
|
|
647
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
|
|
648
|
+
transaction.transaction, solanaConnection,
|
|
649
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
650
|
+
{ signers: transaction.signers, skipPreflight: true }))),
|
|
651
|
+
}, quote, Wormhole.chainAddress("Fogo", options.walletPublicKey.toBase58())));
|
|
652
|
+
}
|
|
653
|
+
else {
|
|
654
|
+
throw quote.error;
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
const buildWormholeTransfer = async (options, connection) => {
|
|
658
|
+
const [wh, { decimals }] = await Promise.all([
|
|
659
|
+
wormhole(NETWORK_TO_WORMHOLE_NETWORK[options.context.network], [solanaSdk]),
|
|
660
|
+
getMint(connection, options.fromToken.mint),
|
|
661
|
+
]);
|
|
662
|
+
const Route = nttExecutorRoute({
|
|
663
|
+
ntt: {
|
|
664
|
+
tokens: {
|
|
665
|
+
USDC: [
|
|
666
|
+
{
|
|
667
|
+
chain: options.fromToken.chain,
|
|
668
|
+
manager: options.fromToken.manager.toBase58(),
|
|
669
|
+
token: options.fromToken.mint.toBase58(),
|
|
670
|
+
transceiver: [
|
|
671
|
+
{
|
|
672
|
+
address: options.fromToken.transceiver.toBase58(),
|
|
673
|
+
type: "wormhole",
|
|
674
|
+
},
|
|
675
|
+
],
|
|
676
|
+
},
|
|
677
|
+
{
|
|
678
|
+
chain: options.toToken.chain,
|
|
679
|
+
manager: options.toToken.manager.toBase58(),
|
|
680
|
+
token: options.toToken.mint.toBase58(),
|
|
681
|
+
transceiver: [
|
|
682
|
+
{
|
|
683
|
+
address: options.toToken.transceiver.toBase58(),
|
|
684
|
+
type: "wormhole",
|
|
685
|
+
},
|
|
686
|
+
],
|
|
687
|
+
},
|
|
688
|
+
],
|
|
689
|
+
},
|
|
690
|
+
},
|
|
691
|
+
});
|
|
692
|
+
const route = new Route(wh);
|
|
693
|
+
const transferRequest = await routes.RouteTransferRequest.create(wh, {
|
|
694
|
+
source: Wormhole.tokenId(options.fromToken.chain, options.fromToken.mint.toBase58()),
|
|
695
|
+
destination: Wormhole.tokenId(options.toToken.chain, options.toToken.mint.toBase58()),
|
|
696
|
+
});
|
|
697
|
+
const validated = await route.validate(transferRequest, {
|
|
698
|
+
amount: amountToString(options.amount, decimals),
|
|
699
|
+
options: route.getDefaultOptions(),
|
|
700
|
+
});
|
|
701
|
+
if (validated.valid) {
|
|
702
|
+
return {
|
|
703
|
+
wh,
|
|
704
|
+
route,
|
|
705
|
+
transferRequest,
|
|
706
|
+
transferParams: validated.params,
|
|
707
|
+
decimals,
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
else {
|
|
711
|
+
throw validated.error;
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
const NETWORK_TO_WORMHOLE_NETWORK = {
|
|
715
|
+
[Network.Mainnet]: "Mainnet",
|
|
716
|
+
[Network.Testnet]: "Testnet",
|
|
717
|
+
};
|
|
718
|
+
const getNonce = async (program, walletPublicKey, nonceType) => {
|
|
515
719
|
const [noncePda] = await getProgramDerivedAddress({
|
|
516
720
|
programAddress: fromLegacyPublicKey(program.programId),
|
|
517
|
-
seeds: [
|
|
721
|
+
seeds: [
|
|
722
|
+
Buffer.from(NONCE_TYPE_TO_SEED[nonceType]),
|
|
723
|
+
walletPublicKey.toBuffer(),
|
|
724
|
+
],
|
|
518
725
|
});
|
|
519
726
|
return program.account.nonce.fetchNullable(noncePda);
|
|
520
727
|
};
|
|
728
|
+
var NonceType;
|
|
729
|
+
(function (NonceType) {
|
|
730
|
+
NonceType[NonceType["Transfer"] = 0] = "Transfer";
|
|
731
|
+
NonceType[NonceType["Bridge"] = 1] = "Bridge";
|
|
732
|
+
})(NonceType || (NonceType = {}));
|
|
733
|
+
const NONCE_TYPE_TO_SEED = {
|
|
734
|
+
[NonceType.Transfer]: "nonce",
|
|
735
|
+
[NonceType.Bridge]: "bridge_ntt_nonce",
|
|
736
|
+
};
|
|
521
737
|
const loginTokenPayloadSchema = z.object({
|
|
522
738
|
iat: z.number(),
|
|
523
739
|
sessionPublicKey: z.string(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fogo/sessions-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"description": "A set of utilities for integrating with Fogo sessions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fogo",
|
|
@@ -36,9 +36,14 @@
|
|
|
36
36
|
"@solana/kit": "^4.0.0",
|
|
37
37
|
"@solana/spl-token": "^0.4.13",
|
|
38
38
|
"@solana/web3.js": "^1.92.3",
|
|
39
|
+
"@wormhole-foundation/sdk": "^3.10.0",
|
|
40
|
+
"@wormhole-foundation/sdk-base": "^3.11.0",
|
|
41
|
+
"@wormhole-foundation/sdk-route-ntt": "^4.0.1",
|
|
42
|
+
"@wormhole-foundation/sdk-solana-core": "^3.10.0",
|
|
43
|
+
"@wormhole-foundation/sdk-solana-ntt": "^4.0.1",
|
|
39
44
|
"bn.js": "^5.1.2",
|
|
40
45
|
"bs58": "^6.0.0",
|
|
41
46
|
"zod": "^3.25.62",
|
|
42
|
-
"@fogo/sessions-idls": "^0.0.
|
|
47
|
+
"@fogo/sessions-idls": "^0.0.8"
|
|
43
48
|
}
|
|
44
49
|
}
|