@fogo/sessions-sdk 0.0.4 → 0.0.6
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/adapter.d.ts +4 -4
- package/cjs/adapter.js +12 -6
- package/cjs/index.d.ts +2 -2
- package/esm/adapter.d.ts +4 -4
- package/esm/adapter.js +15 -9
- package/esm/index.d.ts +2 -2
- package/package.json +2 -2
package/cjs/adapter.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { Transaction } from "@solana/kit";
|
|
2
|
-
import type { Connection, TransactionError
|
|
3
|
-
import { PublicKey } from "@solana/web3.js";
|
|
1
|
+
import type { Transaction, IInstruction } from "@solana/kit";
|
|
2
|
+
import type { Connection, TransactionError } from "@solana/web3.js";
|
|
3
|
+
import { PublicKey, TransactionInstruction, VersionedTransaction } from "@solana/web3.js";
|
|
4
4
|
export type SessionAdapter = {
|
|
5
5
|
chainId: string;
|
|
6
6
|
connection: Connection;
|
|
7
7
|
payer: PublicKey;
|
|
8
8
|
domain: string;
|
|
9
|
-
sendTransaction: (sessionKey: CryptoKeyPair, instructions: TransactionInstruction[]) => Promise<TransactionResult>;
|
|
9
|
+
sendTransaction: (sessionKey: CryptoKeyPair, instructions: (TransactionInstruction | IInstruction)[] | VersionedTransaction | Transaction) => Promise<TransactionResult>;
|
|
10
10
|
};
|
|
11
11
|
export declare enum TransactionResultType {
|
|
12
12
|
Success = 0,
|
package/cjs/adapter.js
CHANGED
|
@@ -6,8 +6,8 @@ const sessions_idls_1 = require("@fogo/sessions-idls");
|
|
|
6
6
|
const compat_1 = require("@solana/compat");
|
|
7
7
|
const kit_1 = require("@solana/kit");
|
|
8
8
|
const web3_js_1 = require("@solana/web3.js");
|
|
9
|
-
// eslint-disable-next-line
|
|
10
|
-
const IS_BROWSER = typeof globalThis.window !== undefined;
|
|
9
|
+
// eslint-disable-next-line unicorn/no-typeof-undefined
|
|
10
|
+
const IS_BROWSER = typeof globalThis.window !== "undefined";
|
|
11
11
|
var TransactionResultType;
|
|
12
12
|
(function (TransactionResultType) {
|
|
13
13
|
TransactionResultType[TransactionResultType["Success"] = 0] = "Success";
|
|
@@ -35,10 +35,16 @@ const createSolanaWalletAdapter = async (options) => {
|
|
|
35
35
|
const rpc = (0, kit_1.createSolanaRpc)(options.connection.rpcEndpoint);
|
|
36
36
|
const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();
|
|
37
37
|
const sessionKeySigner = await (0, kit_1.createSignerFromKeyPair)(sessionKey);
|
|
38
|
-
const transaction =
|
|
39
|
-
(0, compat_1.fromLegacyPublicKey)(
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
const transaction = Array.isArray(instructions)
|
|
39
|
+
? await (0, kit_1.partiallySignTransactionMessageWithSigners)((0, kit_1.pipe)((0, kit_1.createTransactionMessage)({ version: 0 }), (tx) => (0, kit_1.setTransactionMessageFeePayer)((0, compat_1.fromLegacyPublicKey)(options.sponsor), tx), (tx) => (0, kit_1.setTransactionMessageLifetimeUsingBlockhash)(latestBlockhash, tx), (tx) => (0, kit_1.appendTransactionMessageInstructions)(instructions.map((instruction) => instruction instanceof web3_js_1.TransactionInstruction
|
|
40
|
+
? (0, compat_1.fromLegacyTransactionInstruction)(instruction)
|
|
41
|
+
: instruction), tx), (tx) => (0, kit_1.compressTransactionMessageUsingAddressLookupTables)(tx, Object.fromEntries(addressLookupTables?.map((table) => [
|
|
42
|
+
(0, compat_1.fromLegacyPublicKey)(table.key),
|
|
43
|
+
table.state.addresses.map((address) => (0, compat_1.fromLegacyPublicKey)(address)),
|
|
44
|
+
]) ?? [])), (tx) => (0, kit_1.addSignersToTransactionMessage)([sessionKeySigner], tx)))
|
|
45
|
+
: await (0, kit_1.partiallySignTransaction)([sessionKey], instructions instanceof web3_js_1.VersionedTransaction
|
|
46
|
+
? (0, compat_1.fromVersionedTransaction)(instructions)
|
|
47
|
+
: instructions);
|
|
42
48
|
const signature = "sendToPaymaster" in options
|
|
43
49
|
? await options.sendToPaymaster(transaction)
|
|
44
50
|
: await sendToPaymaster(options.paymasterUrl, transaction);
|
package/cjs/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TransactionError } from "@solana/web3.js";
|
|
2
2
|
import { PublicKey } from "@solana/web3.js";
|
|
3
3
|
import type { SessionAdapter, TransactionResult } from "./adapter.js";
|
|
4
4
|
export { type SessionAdapter, type TransactionResult, TransactionResultType, createSolanaWalletAdapter, } from "./adapter.js";
|
|
@@ -43,5 +43,5 @@ export type Session = {
|
|
|
43
43
|
sessionKey: CryptoKeyPair;
|
|
44
44
|
walletPublicKey: PublicKey;
|
|
45
45
|
payer: PublicKey;
|
|
46
|
-
sendTransaction: (instructions:
|
|
46
|
+
sendTransaction: (instructions: Parameters<SessionAdapter["sendTransaction"]>[1]) => Promise<TransactionResult>;
|
|
47
47
|
};
|
package/esm/adapter.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { Transaction } from "@solana/kit";
|
|
2
|
-
import type { Connection, TransactionError
|
|
3
|
-
import { PublicKey } from "@solana/web3.js";
|
|
1
|
+
import type { Transaction, IInstruction } from "@solana/kit";
|
|
2
|
+
import type { Connection, TransactionError } from "@solana/web3.js";
|
|
3
|
+
import { PublicKey, TransactionInstruction, VersionedTransaction } from "@solana/web3.js";
|
|
4
4
|
export type SessionAdapter = {
|
|
5
5
|
chainId: string;
|
|
6
6
|
connection: Connection;
|
|
7
7
|
payer: PublicKey;
|
|
8
8
|
domain: string;
|
|
9
|
-
sendTransaction: (sessionKey: CryptoKeyPair, instructions: TransactionInstruction[]) => Promise<TransactionResult>;
|
|
9
|
+
sendTransaction: (sessionKey: CryptoKeyPair, instructions: (TransactionInstruction | IInstruction)[] | VersionedTransaction | Transaction) => Promise<TransactionResult>;
|
|
10
10
|
};
|
|
11
11
|
export declare enum TransactionResultType {
|
|
12
12
|
Success = 0,
|
package/esm/adapter.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { AnchorProvider } from "@coral-xyz/anchor";
|
|
2
2
|
import { ChainIdProgram } from "@fogo/sessions-idls";
|
|
3
|
-
import { fromLegacyPublicKey, fromLegacyTransactionInstruction, } from "@solana/compat";
|
|
4
|
-
import { createTransactionMessage, setTransactionMessageFeePayer, setTransactionMessageLifetimeUsingBlockhash, appendTransactionMessageInstructions, getBase64EncodedWireTransaction, partiallySignTransactionMessageWithSigners, pipe, createSolanaRpc, addSignersToTransactionMessage, compressTransactionMessageUsingAddressLookupTables, createSignerFromKeyPair, } from "@solana/kit";
|
|
5
|
-
import { PublicKey, Keypair } from "@solana/web3.js";
|
|
6
|
-
// eslint-disable-next-line
|
|
7
|
-
const IS_BROWSER = typeof globalThis.window !== undefined;
|
|
3
|
+
import { fromLegacyPublicKey, fromLegacyTransactionInstruction, fromVersionedTransaction, } from "@solana/compat";
|
|
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
|
+
// eslint-disable-next-line unicorn/no-typeof-undefined
|
|
7
|
+
const IS_BROWSER = typeof globalThis.window !== "undefined";
|
|
8
8
|
export var TransactionResultType;
|
|
9
9
|
(function (TransactionResultType) {
|
|
10
10
|
TransactionResultType[TransactionResultType["Success"] = 0] = "Success";
|
|
@@ -32,10 +32,16 @@ export const createSolanaWalletAdapter = async (options) => {
|
|
|
32
32
|
const rpc = createSolanaRpc(options.connection.rpcEndpoint);
|
|
33
33
|
const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();
|
|
34
34
|
const sessionKeySigner = await createSignerFromKeyPair(sessionKey);
|
|
35
|
-
const transaction =
|
|
36
|
-
fromLegacyPublicKey(
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
const transaction = Array.isArray(instructions)
|
|
36
|
+
? await partiallySignTransactionMessageWithSigners(pipe(createTransactionMessage({ version: 0 }), (tx) => setTransactionMessageFeePayer(fromLegacyPublicKey(options.sponsor), tx), (tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx), (tx) => appendTransactionMessageInstructions(instructions.map((instruction) => instruction instanceof TransactionInstruction
|
|
37
|
+
? fromLegacyTransactionInstruction(instruction)
|
|
38
|
+
: instruction), tx), (tx) => compressTransactionMessageUsingAddressLookupTables(tx, Object.fromEntries(addressLookupTables?.map((table) => [
|
|
39
|
+
fromLegacyPublicKey(table.key),
|
|
40
|
+
table.state.addresses.map((address) => fromLegacyPublicKey(address)),
|
|
41
|
+
]) ?? [])), (tx) => addSignersToTransactionMessage([sessionKeySigner], tx)))
|
|
42
|
+
: await partiallySignTransaction([sessionKey], instructions instanceof VersionedTransaction
|
|
43
|
+
? fromVersionedTransaction(instructions)
|
|
44
|
+
: instructions);
|
|
39
45
|
const signature = "sendToPaymaster" in options
|
|
40
46
|
? await options.sendToPaymaster(transaction)
|
|
41
47
|
: await sendToPaymaster(options.paymasterUrl, transaction);
|
package/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TransactionError } from "@solana/web3.js";
|
|
2
2
|
import { PublicKey } from "@solana/web3.js";
|
|
3
3
|
import type { SessionAdapter, TransactionResult } from "./adapter.js";
|
|
4
4
|
export { type SessionAdapter, type TransactionResult, TransactionResultType, createSolanaWalletAdapter, } from "./adapter.js";
|
|
@@ -43,5 +43,5 @@ export type Session = {
|
|
|
43
43
|
sessionKey: CryptoKeyPair;
|
|
44
44
|
walletPublicKey: PublicKey;
|
|
45
45
|
payer: PublicKey;
|
|
46
|
-
sendTransaction: (instructions:
|
|
46
|
+
sendTransaction: (instructions: Parameters<SessionAdapter["sendTransaction"]>[1]) => Promise<TransactionResult>;
|
|
47
47
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fogo/sessions-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "A set of utilities for integrating with Fogo sessions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fogo",
|
|
@@ -47,6 +47,6 @@
|
|
|
47
47
|
"@solana/web3.js": "^1.92.3",
|
|
48
48
|
"bs58": "^6.0.0",
|
|
49
49
|
"zod": "^3.25.62",
|
|
50
|
-
"@fogo/sessions-idls": "0.0.2"
|
|
50
|
+
"@fogo/sessions-idls": "^0.0.2"
|
|
51
51
|
}
|
|
52
52
|
}
|