@fogo/sessions-sdk 0.0.28 → 0.0.29
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/index.d.ts +18 -7
- package/cjs/index.js +36 -96
- package/esm/index.d.ts +18 -7
- package/esm/index.js +37 -97
- package/package.json +2 -2
package/cjs/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { TransactionError } from "@solana/web3.js";
|
|
1
|
+
import type { TransactionError, VersionedTransaction } from "@solana/web3.js";
|
|
3
2
|
import { Connection, PublicKey } from "@solana/web3.js";
|
|
4
3
|
import type { Chain } from "@wormhole-foundation/sdk";
|
|
5
4
|
import BN from "bn.js";
|
|
@@ -11,7 +10,10 @@ export { type TransactionResult, type Connection, type TransactionOrInstructions
|
|
|
11
10
|
type EstablishSessionOptions = {
|
|
12
11
|
context: SessionContext;
|
|
13
12
|
walletPublicKey: PublicKey;
|
|
14
|
-
signMessage: (message: Uint8Array) => Promise<
|
|
13
|
+
signMessage: (message: Uint8Array) => Promise<{
|
|
14
|
+
signedMessage: Uint8Array;
|
|
15
|
+
signature: Uint8Array;
|
|
16
|
+
}>;
|
|
15
17
|
expires: Date;
|
|
16
18
|
extra?: Record<string, string> | undefined;
|
|
17
19
|
createUnsafeExtractableSessionKey?: boolean | undefined;
|
|
@@ -26,7 +28,10 @@ export declare const establishSession: (options: EstablishSessionOptions) => Pro
|
|
|
26
28
|
export declare const replaceSession: (options: {
|
|
27
29
|
context: SessionContext;
|
|
28
30
|
session: Session;
|
|
29
|
-
signMessage: (message: Uint8Array) => Promise<
|
|
31
|
+
signMessage: (message: Uint8Array) => Promise<{
|
|
32
|
+
signedMessage: Uint8Array;
|
|
33
|
+
signature: Uint8Array;
|
|
34
|
+
}>;
|
|
30
35
|
expires: Date;
|
|
31
36
|
extra?: Record<string, string> | undefined;
|
|
32
37
|
} & ({
|
|
@@ -2243,7 +2248,10 @@ export declare const getBridgeOutFee: (context: SessionContext) => Promise<{
|
|
|
2243
2248
|
type SendTransferOptions = {
|
|
2244
2249
|
context: SessionContext;
|
|
2245
2250
|
walletPublicKey: PublicKey;
|
|
2246
|
-
signMessage: (message: Uint8Array) => Promise<
|
|
2251
|
+
signMessage: (message: Uint8Array) => Promise<{
|
|
2252
|
+
signedMessage: Uint8Array;
|
|
2253
|
+
signature: Uint8Array;
|
|
2254
|
+
}>;
|
|
2247
2255
|
mint: PublicKey;
|
|
2248
2256
|
amount: bigint;
|
|
2249
2257
|
recipient: PublicKey;
|
|
@@ -2255,7 +2263,10 @@ type SendBridgeOutOptions = {
|
|
|
2255
2263
|
sessionKey: CryptoKeyPair;
|
|
2256
2264
|
sessionPublicKey: PublicKey;
|
|
2257
2265
|
walletPublicKey: PublicKey;
|
|
2258
|
-
|
|
2266
|
+
signMessage: (message: Uint8Array) => Promise<{
|
|
2267
|
+
signedMessage: Uint8Array;
|
|
2268
|
+
signature: Uint8Array;
|
|
2269
|
+
}>;
|
|
2259
2270
|
amount: bigint;
|
|
2260
2271
|
fromToken: WormholeToken & {
|
|
2261
2272
|
chain: "Fogo";
|
|
@@ -2275,7 +2286,7 @@ export declare const bridgeOut: (options: SendBridgeOutOptions) => Promise<Trans
|
|
|
2275
2286
|
type SendBridgeInOptions = {
|
|
2276
2287
|
context: SessionContext;
|
|
2277
2288
|
walletPublicKey: PublicKey;
|
|
2278
|
-
|
|
2289
|
+
signTransaction: (transaction: VersionedTransaction) => Promise<VersionedTransaction>;
|
|
2279
2290
|
amount: bigint;
|
|
2280
2291
|
fromToken: WormholeToken & {
|
|
2281
2292
|
chain: "Solana";
|
package/cjs/index.js
CHANGED
|
@@ -53,7 +53,7 @@ const establishSession = async (options) => {
|
|
|
53
53
|
: await (0, kit_1.generateKeyPair)();
|
|
54
54
|
if (options.unlimited) {
|
|
55
55
|
return sendSessionEstablishTransaction(options, sessionKey, await Promise.all([
|
|
56
|
-
|
|
56
|
+
buildStartSessionIntentInstruction(options, sessionKey),
|
|
57
57
|
buildStartSessionInstruction(options, sessionKey),
|
|
58
58
|
]), options.sessionEstablishmentLookupTable);
|
|
59
59
|
}
|
|
@@ -63,7 +63,7 @@ const establishSession = async (options) => {
|
|
|
63
63
|
? await getTokenInfo(options.context, filteredLimits)
|
|
64
64
|
: [];
|
|
65
65
|
const [intentInstruction, startSessionInstruction] = await Promise.all([
|
|
66
|
-
|
|
66
|
+
buildStartSessionIntentInstruction(options, sessionKey, tokenInfo),
|
|
67
67
|
buildStartSessionInstruction(options, sessionKey, tokenInfo),
|
|
68
68
|
]);
|
|
69
69
|
return sendSessionEstablishTransaction(options, sessionKey, [intentInstruction, startSessionInstruction], options.sessionEstablishmentLookupTable);
|
|
@@ -374,64 +374,23 @@ const getTokenInfo = async (context, limits) => {
|
|
|
374
374
|
};
|
|
375
375
|
}));
|
|
376
376
|
};
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
}
|
|
388
|
-
else {
|
|
389
|
-
// Source: https://github.com/anza-xyz/solana-sdk/blob/master/offchain-message/src/lib.rs#L162
|
|
390
|
-
const messageWithOffchainMessagePrefix = Uint8Array.from([
|
|
391
|
-
// eslint-disable-next-line unicorn/number-literal-case
|
|
392
|
-
0xff,
|
|
393
|
-
...new TextEncoder().encode("solana offchain"),
|
|
394
|
-
0,
|
|
395
|
-
1,
|
|
396
|
-
...serializeU16LE(message.length),
|
|
397
|
-
...message,
|
|
398
|
-
]);
|
|
399
|
-
if (await (0, kit_1.verifySignature)(publicKey, signature, messageWithOffchainMessagePrefix)) {
|
|
400
|
-
return messageWithOffchainMessagePrefix;
|
|
401
|
-
}
|
|
402
|
-
else {
|
|
403
|
-
throw new Error("The signature provided by the browser wallet is not valid");
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
};
|
|
407
|
-
const buildIntentInstruction = async (options, sessionKey, tokens) => {
|
|
408
|
-
const message = await buildMessage({
|
|
409
|
-
chainId: options.context.chainId,
|
|
410
|
-
domain: options.context.domain,
|
|
411
|
-
sessionKey,
|
|
412
|
-
expires: options.expires,
|
|
413
|
-
tokens,
|
|
414
|
-
extra: options.extra,
|
|
415
|
-
});
|
|
416
|
-
const intentSignature = (0, kit_1.signatureBytes)(await options.signMessage(message));
|
|
377
|
+
const buildStartSessionIntentInstruction = async (options, sessionKey, tokens) => buildIntentInstruction(options, MESSAGE_HEADER, {
|
|
378
|
+
version: `${CURRENT_MAJOR}.${CURRENT_MINOR}`,
|
|
379
|
+
chain_id: options.context.chainId,
|
|
380
|
+
domain: options.context.domain,
|
|
381
|
+
expires: options.expires.toISOString(),
|
|
382
|
+
session_key: await (0, kit_1.getAddressFromPublicKey)(sessionKey.publicKey),
|
|
383
|
+
tokens: serializeTokenList(tokens),
|
|
384
|
+
});
|
|
385
|
+
const buildIntentInstruction = async (options, header, body, extra) => {
|
|
386
|
+
const message = new TextEncoder().encode([header, serializeKV(body), extra && serializeExtra(extra)].join("\n"));
|
|
387
|
+
const { signature, signedMessage } = await options.signMessage(message);
|
|
417
388
|
return web3_js_1.Ed25519Program.createInstructionWithPublicKey({
|
|
418
389
|
publicKey: options.walletPublicKey.toBytes(),
|
|
419
|
-
signature
|
|
420
|
-
message:
|
|
390
|
+
signature,
|
|
391
|
+
message: signedMessage,
|
|
421
392
|
});
|
|
422
393
|
};
|
|
423
|
-
const buildMessage = async (body) => new TextEncoder().encode([
|
|
424
|
-
MESSAGE_HEADER,
|
|
425
|
-
serializeKV({
|
|
426
|
-
version: `${CURRENT_MAJOR}.${CURRENT_MINOR}`,
|
|
427
|
-
chain_id: body.chainId,
|
|
428
|
-
domain: body.domain,
|
|
429
|
-
expires: body.expires.toISOString(),
|
|
430
|
-
session_key: await (0, kit_1.getAddressFromPublicKey)(body.sessionKey.publicKey),
|
|
431
|
-
tokens: serializeTokenList(body.tokens),
|
|
432
|
-
}),
|
|
433
|
-
body.extra && serializeExtra(body.extra),
|
|
434
|
-
].join("\n"));
|
|
435
394
|
const serializeExtra = (extra) => {
|
|
436
395
|
for (const [key, value] of Object.entries(extra)) {
|
|
437
396
|
if (!/^[a-z]+(_[a-z0-9]+)*$/.test(key)) {
|
|
@@ -618,24 +577,15 @@ const buildTransferIntentInstruction = async (program, options, symbol, feeToken
|
|
|
618
577
|
getNonce(program, options.walletPublicKey, NonceType.Transfer),
|
|
619
578
|
(0, spl_token_1.getMint)(options.context.connection, options.mint),
|
|
620
579
|
]);
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
fee_amount: feeAmount,
|
|
631
|
-
nonce: nonce === null ? "1" : nonce.nonce.add(new bn_js_1.default(1)).toString(),
|
|
632
|
-
}),
|
|
633
|
-
].join("\n"));
|
|
634
|
-
const intentSignature = (0, kit_1.signatureBytes)(await options.signMessage(message));
|
|
635
|
-
return web3_js_1.Ed25519Program.createInstructionWithPublicKey({
|
|
636
|
-
publicKey: options.walletPublicKey.toBytes(),
|
|
637
|
-
signature: intentSignature,
|
|
638
|
-
message: await addOffchainMessagePrefixToMessageIfNeeded(options.walletPublicKey, intentSignature, message),
|
|
580
|
+
return buildIntentInstruction(options, TRANSFER_MESSAGE_HEADER, {
|
|
581
|
+
version: `${CURRENT_INTENT_TRANSFER_MAJOR}.${CURRENT_INTENT_TRANSFER_MINOR}`,
|
|
582
|
+
chain_id: options.context.chainId,
|
|
583
|
+
token: symbol ?? options.mint.toBase58(),
|
|
584
|
+
amount: amountToString(options.amount, decimals),
|
|
585
|
+
recipient: options.recipient.toBase58(),
|
|
586
|
+
fee_token: feeToken,
|
|
587
|
+
fee_amount: feeAmount,
|
|
588
|
+
nonce: nonce === null ? "1" : nonce.nonce.add(new bn_js_1.default(1)).toString(),
|
|
639
589
|
});
|
|
640
590
|
};
|
|
641
591
|
const BRIDGE_OUT_MESSAGE_HEADER = `Fogo Bridge Transfer:
|
|
@@ -738,25 +688,16 @@ const getNttPdas = async (options, wh, program, outboxItemPublicKey, quotePayeeA
|
|
|
738
688
|
};
|
|
739
689
|
const buildBridgeOutIntent = async (program, options, decimals, symbol, feeToken, feeAmount) => {
|
|
740
690
|
const nonce = await getNonce(program, options.walletPublicKey, NonceType.Bridge);
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
fee_amount: feeAmount,
|
|
752
|
-
nonce: nonce === null ? "1" : nonce.nonce.add(new bn_js_1.default(1)).toString(),
|
|
753
|
-
}),
|
|
754
|
-
].join("\n"));
|
|
755
|
-
const intentSignature = (0, kit_1.signatureBytes)(await options.solanaWallet.signMessage(message));
|
|
756
|
-
return web3_js_1.Ed25519Program.createInstructionWithPublicKey({
|
|
757
|
-
publicKey: options.walletPublicKey.toBytes(),
|
|
758
|
-
signature: intentSignature,
|
|
759
|
-
message: await addOffchainMessagePrefixToMessageIfNeeded(options.walletPublicKey, intentSignature, message),
|
|
691
|
+
return buildIntentInstruction(options, BRIDGE_OUT_MESSAGE_HEADER, {
|
|
692
|
+
version: `${CURRENT_BRIDGE_OUT_MAJOR}.${CURRENT_BRIDGE_OUT_MINOR}`,
|
|
693
|
+
from_chain_id: options.context.chainId,
|
|
694
|
+
to_chain_id: "solana",
|
|
695
|
+
token: symbol ?? options.fromToken.mint.toBase58(),
|
|
696
|
+
amount: amountToString(options.amount, decimals),
|
|
697
|
+
recipient_address: options.walletPublicKey.toBase58(),
|
|
698
|
+
fee_token: feeToken,
|
|
699
|
+
fee_amount: feeAmount,
|
|
700
|
+
nonce: nonce === null ? "1" : nonce.nonce.add(new bn_js_1.default(1)).toString(),
|
|
760
701
|
});
|
|
761
702
|
};
|
|
762
703
|
const bridgeIn = async (options) => {
|
|
@@ -770,10 +711,9 @@ const bridgeIn = async (options) => {
|
|
|
770
711
|
address: () => options.walletPublicKey.toBase58(),
|
|
771
712
|
chain: () => "Solana",
|
|
772
713
|
sign: (transactions) => Promise.all(transactions.map(async ({ transaction }) => {
|
|
773
|
-
|
|
774
|
-
const signedTx = await options.solanaWallet.signTransaction(
|
|
714
|
+
const signedTx = await options.signTransaction(
|
|
775
715
|
// Hooray for Wormhole's incomplete typing eh?
|
|
776
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
716
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
|
|
777
717
|
transaction.transaction);
|
|
778
718
|
// Hooray for Wormhole's incomplete typing eh?
|
|
779
719
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
|
package/esm/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { TransactionError } from "@solana/web3.js";
|
|
1
|
+
import type { TransactionError, VersionedTransaction } from "@solana/web3.js";
|
|
3
2
|
import { Connection, PublicKey } from "@solana/web3.js";
|
|
4
3
|
import type { Chain } from "@wormhole-foundation/sdk";
|
|
5
4
|
import BN from "bn.js";
|
|
@@ -11,7 +10,10 @@ export { type TransactionResult, type Connection, type TransactionOrInstructions
|
|
|
11
10
|
type EstablishSessionOptions = {
|
|
12
11
|
context: SessionContext;
|
|
13
12
|
walletPublicKey: PublicKey;
|
|
14
|
-
signMessage: (message: Uint8Array) => Promise<
|
|
13
|
+
signMessage: (message: Uint8Array) => Promise<{
|
|
14
|
+
signedMessage: Uint8Array;
|
|
15
|
+
signature: Uint8Array;
|
|
16
|
+
}>;
|
|
15
17
|
expires: Date;
|
|
16
18
|
extra?: Record<string, string> | undefined;
|
|
17
19
|
createUnsafeExtractableSessionKey?: boolean | undefined;
|
|
@@ -26,7 +28,10 @@ export declare const establishSession: (options: EstablishSessionOptions) => Pro
|
|
|
26
28
|
export declare const replaceSession: (options: {
|
|
27
29
|
context: SessionContext;
|
|
28
30
|
session: Session;
|
|
29
|
-
signMessage: (message: Uint8Array) => Promise<
|
|
31
|
+
signMessage: (message: Uint8Array) => Promise<{
|
|
32
|
+
signedMessage: Uint8Array;
|
|
33
|
+
signature: Uint8Array;
|
|
34
|
+
}>;
|
|
30
35
|
expires: Date;
|
|
31
36
|
extra?: Record<string, string> | undefined;
|
|
32
37
|
} & ({
|
|
@@ -2243,7 +2248,10 @@ export declare const getBridgeOutFee: (context: SessionContext) => Promise<{
|
|
|
2243
2248
|
type SendTransferOptions = {
|
|
2244
2249
|
context: SessionContext;
|
|
2245
2250
|
walletPublicKey: PublicKey;
|
|
2246
|
-
signMessage: (message: Uint8Array) => Promise<
|
|
2251
|
+
signMessage: (message: Uint8Array) => Promise<{
|
|
2252
|
+
signedMessage: Uint8Array;
|
|
2253
|
+
signature: Uint8Array;
|
|
2254
|
+
}>;
|
|
2247
2255
|
mint: PublicKey;
|
|
2248
2256
|
amount: bigint;
|
|
2249
2257
|
recipient: PublicKey;
|
|
@@ -2255,7 +2263,10 @@ type SendBridgeOutOptions = {
|
|
|
2255
2263
|
sessionKey: CryptoKeyPair;
|
|
2256
2264
|
sessionPublicKey: PublicKey;
|
|
2257
2265
|
walletPublicKey: PublicKey;
|
|
2258
|
-
|
|
2266
|
+
signMessage: (message: Uint8Array) => Promise<{
|
|
2267
|
+
signedMessage: Uint8Array;
|
|
2268
|
+
signature: Uint8Array;
|
|
2269
|
+
}>;
|
|
2259
2270
|
amount: bigint;
|
|
2260
2271
|
fromToken: WormholeToken & {
|
|
2261
2272
|
chain: "Fogo";
|
|
@@ -2275,7 +2286,7 @@ export declare const bridgeOut: (options: SendBridgeOutOptions) => Promise<Trans
|
|
|
2275
2286
|
type SendBridgeInOptions = {
|
|
2276
2287
|
context: SessionContext;
|
|
2277
2288
|
walletPublicKey: PublicKey;
|
|
2278
|
-
|
|
2289
|
+
signTransaction: (transaction: VersionedTransaction) => Promise<VersionedTransaction>;
|
|
2279
2290
|
amount: bigint;
|
|
2280
2291
|
fromToken: WormholeToken & {
|
|
2281
2292
|
chain: "Solana";
|
package/esm/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { publicKey as metaplexPublicKey } from "@metaplex-foundation/umi";
|
|
|
5
5
|
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
|
|
6
6
|
import { sha256 } from "@noble/hashes/sha2";
|
|
7
7
|
import { fromLegacyPublicKey } from "@solana/compat";
|
|
8
|
-
import { generateKeyPair, getAddressFromPublicKey, getProgramDerivedAddress,
|
|
8
|
+
import { generateKeyPair, getAddressFromPublicKey, getProgramDerivedAddress, } from "@solana/kit";
|
|
9
9
|
import { getAssociatedTokenAddressSync, getMint } from "@solana/spl-token";
|
|
10
10
|
import { ComputeBudgetProgram, Connection, Ed25519Program, Keypair, PublicKey, } from "@solana/web3.js";
|
|
11
11
|
import { Wormhole, wormhole, routes } from "@wormhole-foundation/sdk";
|
|
@@ -43,7 +43,7 @@ export const establishSession = async (options) => {
|
|
|
43
43
|
: await generateKeyPair();
|
|
44
44
|
if (options.unlimited) {
|
|
45
45
|
return sendSessionEstablishTransaction(options, sessionKey, await Promise.all([
|
|
46
|
-
|
|
46
|
+
buildStartSessionIntentInstruction(options, sessionKey),
|
|
47
47
|
buildStartSessionInstruction(options, sessionKey),
|
|
48
48
|
]), options.sessionEstablishmentLookupTable);
|
|
49
49
|
}
|
|
@@ -53,7 +53,7 @@ export const establishSession = async (options) => {
|
|
|
53
53
|
? await getTokenInfo(options.context, filteredLimits)
|
|
54
54
|
: [];
|
|
55
55
|
const [intentInstruction, startSessionInstruction] = await Promise.all([
|
|
56
|
-
|
|
56
|
+
buildStartSessionIntentInstruction(options, sessionKey, tokenInfo),
|
|
57
57
|
buildStartSessionInstruction(options, sessionKey, tokenInfo),
|
|
58
58
|
]);
|
|
59
59
|
return sendSessionEstablishTransaction(options, sessionKey, [intentInstruction, startSessionInstruction], options.sessionEstablishmentLookupTable);
|
|
@@ -359,64 +359,23 @@ const getTokenInfo = async (context, limits) => {
|
|
|
359
359
|
};
|
|
360
360
|
}));
|
|
361
361
|
};
|
|
362
|
-
const
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
}
|
|
373
|
-
else {
|
|
374
|
-
// Source: https://github.com/anza-xyz/solana-sdk/blob/master/offchain-message/src/lib.rs#L162
|
|
375
|
-
const messageWithOffchainMessagePrefix = Uint8Array.from([
|
|
376
|
-
// eslint-disable-next-line unicorn/number-literal-case
|
|
377
|
-
0xff,
|
|
378
|
-
...new TextEncoder().encode("solana offchain"),
|
|
379
|
-
0,
|
|
380
|
-
1,
|
|
381
|
-
...serializeU16LE(message.length),
|
|
382
|
-
...message,
|
|
383
|
-
]);
|
|
384
|
-
if (await verifySignature(publicKey, signature, messageWithOffchainMessagePrefix)) {
|
|
385
|
-
return messageWithOffchainMessagePrefix;
|
|
386
|
-
}
|
|
387
|
-
else {
|
|
388
|
-
throw new Error("The signature provided by the browser wallet is not valid");
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
};
|
|
392
|
-
const buildIntentInstruction = async (options, sessionKey, tokens) => {
|
|
393
|
-
const message = await buildMessage({
|
|
394
|
-
chainId: options.context.chainId,
|
|
395
|
-
domain: options.context.domain,
|
|
396
|
-
sessionKey,
|
|
397
|
-
expires: options.expires,
|
|
398
|
-
tokens,
|
|
399
|
-
extra: options.extra,
|
|
400
|
-
});
|
|
401
|
-
const intentSignature = signatureBytes(await options.signMessage(message));
|
|
362
|
+
const buildStartSessionIntentInstruction = async (options, sessionKey, tokens) => buildIntentInstruction(options, MESSAGE_HEADER, {
|
|
363
|
+
version: `${CURRENT_MAJOR}.${CURRENT_MINOR}`,
|
|
364
|
+
chain_id: options.context.chainId,
|
|
365
|
+
domain: options.context.domain,
|
|
366
|
+
expires: options.expires.toISOString(),
|
|
367
|
+
session_key: await getAddressFromPublicKey(sessionKey.publicKey),
|
|
368
|
+
tokens: serializeTokenList(tokens),
|
|
369
|
+
});
|
|
370
|
+
const buildIntentInstruction = async (options, header, body, extra) => {
|
|
371
|
+
const message = new TextEncoder().encode([header, serializeKV(body), extra && serializeExtra(extra)].join("\n"));
|
|
372
|
+
const { signature, signedMessage } = await options.signMessage(message);
|
|
402
373
|
return Ed25519Program.createInstructionWithPublicKey({
|
|
403
374
|
publicKey: options.walletPublicKey.toBytes(),
|
|
404
|
-
signature
|
|
405
|
-
message:
|
|
375
|
+
signature,
|
|
376
|
+
message: signedMessage,
|
|
406
377
|
});
|
|
407
378
|
};
|
|
408
|
-
const buildMessage = async (body) => new TextEncoder().encode([
|
|
409
|
-
MESSAGE_HEADER,
|
|
410
|
-
serializeKV({
|
|
411
|
-
version: `${CURRENT_MAJOR}.${CURRENT_MINOR}`,
|
|
412
|
-
chain_id: body.chainId,
|
|
413
|
-
domain: body.domain,
|
|
414
|
-
expires: body.expires.toISOString(),
|
|
415
|
-
session_key: await getAddressFromPublicKey(body.sessionKey.publicKey),
|
|
416
|
-
tokens: serializeTokenList(body.tokens),
|
|
417
|
-
}),
|
|
418
|
-
body.extra && serializeExtra(body.extra),
|
|
419
|
-
].join("\n"));
|
|
420
379
|
const serializeExtra = (extra) => {
|
|
421
380
|
for (const [key, value] of Object.entries(extra)) {
|
|
422
381
|
if (!/^[a-z]+(_[a-z0-9]+)*$/.test(key)) {
|
|
@@ -599,24 +558,15 @@ const buildTransferIntentInstruction = async (program, options, symbol, feeToken
|
|
|
599
558
|
getNonce(program, options.walletPublicKey, NonceType.Transfer),
|
|
600
559
|
getMint(options.context.connection, options.mint),
|
|
601
560
|
]);
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
fee_amount: feeAmount,
|
|
612
|
-
nonce: nonce === null ? "1" : nonce.nonce.add(new BN(1)).toString(),
|
|
613
|
-
}),
|
|
614
|
-
].join("\n"));
|
|
615
|
-
const intentSignature = signatureBytes(await options.signMessage(message));
|
|
616
|
-
return Ed25519Program.createInstructionWithPublicKey({
|
|
617
|
-
publicKey: options.walletPublicKey.toBytes(),
|
|
618
|
-
signature: intentSignature,
|
|
619
|
-
message: await addOffchainMessagePrefixToMessageIfNeeded(options.walletPublicKey, intentSignature, message),
|
|
561
|
+
return buildIntentInstruction(options, TRANSFER_MESSAGE_HEADER, {
|
|
562
|
+
version: `${CURRENT_INTENT_TRANSFER_MAJOR}.${CURRENT_INTENT_TRANSFER_MINOR}`,
|
|
563
|
+
chain_id: options.context.chainId,
|
|
564
|
+
token: symbol ?? options.mint.toBase58(),
|
|
565
|
+
amount: amountToString(options.amount, decimals),
|
|
566
|
+
recipient: options.recipient.toBase58(),
|
|
567
|
+
fee_token: feeToken,
|
|
568
|
+
fee_amount: feeAmount,
|
|
569
|
+
nonce: nonce === null ? "1" : nonce.nonce.add(new BN(1)).toString(),
|
|
620
570
|
});
|
|
621
571
|
};
|
|
622
572
|
const BRIDGE_OUT_MESSAGE_HEADER = `Fogo Bridge Transfer:
|
|
@@ -718,25 +668,16 @@ const getNttPdas = async (options, wh, program, outboxItemPublicKey, quotePayeeA
|
|
|
718
668
|
};
|
|
719
669
|
const buildBridgeOutIntent = async (program, options, decimals, symbol, feeToken, feeAmount) => {
|
|
720
670
|
const nonce = await getNonce(program, options.walletPublicKey, NonceType.Bridge);
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
fee_amount: feeAmount,
|
|
732
|
-
nonce: nonce === null ? "1" : nonce.nonce.add(new BN(1)).toString(),
|
|
733
|
-
}),
|
|
734
|
-
].join("\n"));
|
|
735
|
-
const intentSignature = signatureBytes(await options.solanaWallet.signMessage(message));
|
|
736
|
-
return Ed25519Program.createInstructionWithPublicKey({
|
|
737
|
-
publicKey: options.walletPublicKey.toBytes(),
|
|
738
|
-
signature: intentSignature,
|
|
739
|
-
message: await addOffchainMessagePrefixToMessageIfNeeded(options.walletPublicKey, intentSignature, message),
|
|
671
|
+
return buildIntentInstruction(options, BRIDGE_OUT_MESSAGE_HEADER, {
|
|
672
|
+
version: `${CURRENT_BRIDGE_OUT_MAJOR}.${CURRENT_BRIDGE_OUT_MINOR}`,
|
|
673
|
+
from_chain_id: options.context.chainId,
|
|
674
|
+
to_chain_id: "solana",
|
|
675
|
+
token: symbol ?? options.fromToken.mint.toBase58(),
|
|
676
|
+
amount: amountToString(options.amount, decimals),
|
|
677
|
+
recipient_address: options.walletPublicKey.toBase58(),
|
|
678
|
+
fee_token: feeToken,
|
|
679
|
+
fee_amount: feeAmount,
|
|
680
|
+
nonce: nonce === null ? "1" : nonce.nonce.add(new BN(1)).toString(),
|
|
740
681
|
});
|
|
741
682
|
};
|
|
742
683
|
export const bridgeIn = async (options) => {
|
|
@@ -750,10 +691,9 @@ export const bridgeIn = async (options) => {
|
|
|
750
691
|
address: () => options.walletPublicKey.toBase58(),
|
|
751
692
|
chain: () => "Solana",
|
|
752
693
|
sign: (transactions) => Promise.all(transactions.map(async ({ transaction }) => {
|
|
753
|
-
|
|
754
|
-
const signedTx = await options.solanaWallet.signTransaction(
|
|
694
|
+
const signedTx = await options.signTransaction(
|
|
755
695
|
// Hooray for Wormhole's incomplete typing eh?
|
|
756
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
696
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
|
|
757
697
|
transaction.transaction);
|
|
758
698
|
// Hooray for Wormhole's incomplete typing eh?
|
|
759
699
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fogo/sessions-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.29",
|
|
4
4
|
"description": "A set of utilities for integrating with Fogo sessions",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@wormhole-foundation/sdk-solana-ntt": "^4.0.1",
|
|
49
49
|
"bn.js": "^5.1.2",
|
|
50
50
|
"bs58": "^6.0.0",
|
|
51
|
-
"zod": "
|
|
51
|
+
"zod": "3.25.67",
|
|
52
52
|
"@fogo/sessions-idls": "^0.0.12"
|
|
53
53
|
}
|
|
54
54
|
}
|