@fogo/sessions-sdk 0.0.10 → 0.0.12
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.js +15 -7
- package/esm/adapter.js +15 -7
- package/package.json +1 -1
package/cjs/adapter.js
CHANGED
|
@@ -29,7 +29,8 @@ const TransactionResult = {
|
|
|
29
29
|
};
|
|
30
30
|
const createSolanaWalletAdapter = async (options) => {
|
|
31
31
|
const addressLookupTables = await getAddressLookupTables(options.connection, options.addressLookupTableAddress);
|
|
32
|
-
const
|
|
32
|
+
const domain = getDomain(options.domain);
|
|
33
|
+
const sponsor = await getSponsor(options, domain);
|
|
33
34
|
return {
|
|
34
35
|
connection: options.connection,
|
|
35
36
|
payer: sponsor,
|
|
@@ -38,7 +39,7 @@ const createSolanaWalletAdapter = async (options) => {
|
|
|
38
39
|
sendTransaction: async (sessionKey, instructions) => {
|
|
39
40
|
const rpc = (0, kit_1.createSolanaRpc)(options.connection.rpcEndpoint);
|
|
40
41
|
const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();
|
|
41
|
-
return await sendToPaymaster(options, await buildTransaction(latestBlockhash, sessionKey, sponsor, instructions, addressLookupTables));
|
|
42
|
+
return await sendToPaymaster(options, await buildTransaction(latestBlockhash, sessionKey, sponsor, instructions, addressLookupTables), domain);
|
|
42
43
|
},
|
|
43
44
|
};
|
|
44
45
|
};
|
|
@@ -66,12 +67,14 @@ const buildTransaction = async (latestBlockhash, sessionKey, sponsor, instructio
|
|
|
66
67
|
: (0, kit_1.partiallySignTransaction)([sessionKey], tx);
|
|
67
68
|
}
|
|
68
69
|
};
|
|
69
|
-
const getSponsor = async (options) => {
|
|
70
|
+
const getSponsor = async (options, domain) => {
|
|
70
71
|
if ("sponsor" in options) {
|
|
71
72
|
return options.sponsor;
|
|
72
73
|
}
|
|
73
74
|
else {
|
|
74
|
-
const
|
|
75
|
+
const url = new URL("/api/sponsor_pubkey", options.paymaster ?? DEFAULT_PAYMASTER);
|
|
76
|
+
url.searchParams.set("domain", domain);
|
|
77
|
+
const response = await fetch(url);
|
|
75
78
|
return new web3_js_1.PublicKey(zod_1.z.string().parse(await response.text()));
|
|
76
79
|
}
|
|
77
80
|
};
|
|
@@ -84,7 +87,9 @@ const sponsorAndSendResponseSchema = zod_1.z
|
|
|
84
87
|
zod_1.z.object({
|
|
85
88
|
type: zod_1.z.literal("failed"),
|
|
86
89
|
signature: zod_1.z.string(),
|
|
87
|
-
error: zod_1.z.object({
|
|
90
|
+
error: zod_1.z.object({
|
|
91
|
+
InstructionError: zod_1.z.tuple([zod_1.z.number(), zod_1.z.unknown()]),
|
|
92
|
+
}),
|
|
88
93
|
}),
|
|
89
94
|
])
|
|
90
95
|
.transform((data) => {
|
|
@@ -92,12 +97,15 @@ const sponsorAndSendResponseSchema = zod_1.z
|
|
|
92
97
|
? TransactionResult.Success(data.signature)
|
|
93
98
|
: TransactionResult.Failed(data.signature, data.error);
|
|
94
99
|
});
|
|
95
|
-
const sendToPaymaster = async (options, transaction) => {
|
|
100
|
+
const sendToPaymaster = async (options, transaction, domain) => {
|
|
96
101
|
if ("sendToPaymaster" in options) {
|
|
97
102
|
return options.sendToPaymaster(transaction);
|
|
98
103
|
}
|
|
99
104
|
else {
|
|
100
|
-
const
|
|
105
|
+
const url = new URL("/api/sponsor_and_send", options.paymaster ?? DEFAULT_PAYMASTER);
|
|
106
|
+
url.searchParams.set("confirm", "true");
|
|
107
|
+
url.searchParams.set("domain", domain);
|
|
108
|
+
const response = await fetch(url, {
|
|
101
109
|
method: "POST",
|
|
102
110
|
headers: {
|
|
103
111
|
"Content-Type": "application/json",
|
package/esm/adapter.js
CHANGED
|
@@ -26,7 +26,8 @@ const TransactionResult = {
|
|
|
26
26
|
};
|
|
27
27
|
export const createSolanaWalletAdapter = async (options) => {
|
|
28
28
|
const addressLookupTables = await getAddressLookupTables(options.connection, options.addressLookupTableAddress);
|
|
29
|
-
const
|
|
29
|
+
const domain = getDomain(options.domain);
|
|
30
|
+
const sponsor = await getSponsor(options, domain);
|
|
30
31
|
return {
|
|
31
32
|
connection: options.connection,
|
|
32
33
|
payer: sponsor,
|
|
@@ -35,7 +36,7 @@ export const createSolanaWalletAdapter = async (options) => {
|
|
|
35
36
|
sendTransaction: async (sessionKey, instructions) => {
|
|
36
37
|
const rpc = createSolanaRpc(options.connection.rpcEndpoint);
|
|
37
38
|
const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();
|
|
38
|
-
return await sendToPaymaster(options, await buildTransaction(latestBlockhash, sessionKey, sponsor, instructions, addressLookupTables));
|
|
39
|
+
return await sendToPaymaster(options, await buildTransaction(latestBlockhash, sessionKey, sponsor, instructions, addressLookupTables), domain);
|
|
39
40
|
},
|
|
40
41
|
};
|
|
41
42
|
};
|
|
@@ -62,12 +63,14 @@ const buildTransaction = async (latestBlockhash, sessionKey, sponsor, instructio
|
|
|
62
63
|
: partiallySignTransaction([sessionKey], tx);
|
|
63
64
|
}
|
|
64
65
|
};
|
|
65
|
-
const getSponsor = async (options) => {
|
|
66
|
+
const getSponsor = async (options, domain) => {
|
|
66
67
|
if ("sponsor" in options) {
|
|
67
68
|
return options.sponsor;
|
|
68
69
|
}
|
|
69
70
|
else {
|
|
70
|
-
const
|
|
71
|
+
const url = new URL("/api/sponsor_pubkey", options.paymaster ?? DEFAULT_PAYMASTER);
|
|
72
|
+
url.searchParams.set("domain", domain);
|
|
73
|
+
const response = await fetch(url);
|
|
71
74
|
return new PublicKey(z.string().parse(await response.text()));
|
|
72
75
|
}
|
|
73
76
|
};
|
|
@@ -80,7 +83,9 @@ const sponsorAndSendResponseSchema = z
|
|
|
80
83
|
z.object({
|
|
81
84
|
type: z.literal("failed"),
|
|
82
85
|
signature: z.string(),
|
|
83
|
-
error: z.object({
|
|
86
|
+
error: z.object({
|
|
87
|
+
InstructionError: z.tuple([z.number(), z.unknown()]),
|
|
88
|
+
}),
|
|
84
89
|
}),
|
|
85
90
|
])
|
|
86
91
|
.transform((data) => {
|
|
@@ -88,12 +93,15 @@ const sponsorAndSendResponseSchema = z
|
|
|
88
93
|
? TransactionResult.Success(data.signature)
|
|
89
94
|
: TransactionResult.Failed(data.signature, data.error);
|
|
90
95
|
});
|
|
91
|
-
const sendToPaymaster = async (options, transaction) => {
|
|
96
|
+
const sendToPaymaster = async (options, transaction, domain) => {
|
|
92
97
|
if ("sendToPaymaster" in options) {
|
|
93
98
|
return options.sendToPaymaster(transaction);
|
|
94
99
|
}
|
|
95
100
|
else {
|
|
96
|
-
const
|
|
101
|
+
const url = new URL("/api/sponsor_and_send", options.paymaster ?? DEFAULT_PAYMASTER);
|
|
102
|
+
url.searchParams.set("confirm", "true");
|
|
103
|
+
url.searchParams.set("domain", domain);
|
|
104
|
+
const response = await fetch(url, {
|
|
97
105
|
method: "POST",
|
|
98
106
|
headers: {
|
|
99
107
|
"Content-Type": "application/json",
|