@account-kit/signer 4.53.1-alpha.0 → 4.53.2-alpha.0

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.
Files changed (69) hide show
  1. package/dist/esm/base.d.ts +1 -0
  2. package/dist/esm/base.js +34 -0
  3. package/dist/esm/base.js.map +1 -1
  4. package/dist/esm/client/base.d.ts +2 -1
  5. package/dist/esm/client/base.js.map +1 -1
  6. package/dist/esm/client/index.d.ts +27 -1
  7. package/dist/esm/client/index.js +35 -0
  8. package/dist/esm/client/index.js.map +1 -1
  9. package/dist/esm/client/types.d.ts +18 -1
  10. package/dist/esm/client/types.js.map +1 -1
  11. package/dist/esm/index.d.ts +0 -1
  12. package/dist/esm/index.js +0 -1
  13. package/dist/esm/index.js.map +1 -1
  14. package/dist/esm/metrics.d.ts +3 -0
  15. package/dist/esm/metrics.js.map +1 -1
  16. package/dist/esm/session/manager.js +6 -0
  17. package/dist/esm/session/manager.js.map +1 -1
  18. package/dist/esm/session/types.d.ts +1 -1
  19. package/dist/esm/session/types.js.map +1 -1
  20. package/dist/esm/signer.d.ts +4 -1
  21. package/dist/esm/signer.js.map +1 -1
  22. package/dist/esm/solanaSigner.js +40 -2
  23. package/dist/esm/solanaSigner.js.map +1 -1
  24. package/dist/esm/types.d.ts +1 -0
  25. package/dist/esm/types.js +1 -0
  26. package/dist/esm/types.js.map +1 -1
  27. package/dist/esm/version.d.ts +1 -1
  28. package/dist/esm/version.js +1 -1
  29. package/dist/esm/version.js.map +1 -1
  30. package/dist/types/base.d.ts +1 -0
  31. package/dist/types/base.d.ts.map +1 -1
  32. package/dist/types/client/base.d.ts +2 -1
  33. package/dist/types/client/base.d.ts.map +1 -1
  34. package/dist/types/client/index.d.ts +27 -1
  35. package/dist/types/client/index.d.ts.map +1 -1
  36. package/dist/types/client/types.d.ts +18 -1
  37. package/dist/types/client/types.d.ts.map +1 -1
  38. package/dist/types/index.d.ts +0 -1
  39. package/dist/types/index.d.ts.map +1 -1
  40. package/dist/types/metrics.d.ts +3 -0
  41. package/dist/types/metrics.d.ts.map +1 -1
  42. package/dist/types/session/manager.d.ts.map +1 -1
  43. package/dist/types/session/types.d.ts +1 -1
  44. package/dist/types/session/types.d.ts.map +1 -1
  45. package/dist/types/signer.d.ts +4 -1
  46. package/dist/types/signer.d.ts.map +1 -1
  47. package/dist/types/solanaSigner.d.ts.map +1 -1
  48. package/dist/types/types.d.ts +1 -0
  49. package/dist/types/types.d.ts.map +1 -1
  50. package/dist/types/version.d.ts +1 -1
  51. package/package.json +4 -4
  52. package/src/base.ts +34 -0
  53. package/src/client/base.ts +6 -0
  54. package/src/client/index.ts +40 -0
  55. package/src/client/types.ts +27 -1
  56. package/src/index.ts +0 -4
  57. package/src/metrics.ts +2 -1
  58. package/src/session/manager.ts +8 -2
  59. package/src/session/types.ts +1 -1
  60. package/src/signer.ts +4 -0
  61. package/src/solanaSigner.ts +49 -5
  62. package/src/types.ts +1 -0
  63. package/src/version.ts +1 -1
  64. package/dist/esm/utils/solana.d.ts +0 -21
  65. package/dist/esm/utils/solana.js +0 -72
  66. package/dist/esm/utils/solana.js.map +0 -1
  67. package/dist/types/utils/solana.d.ts +0 -22
  68. package/dist/types/utils/solana.d.ts.map +0 -1
  69. package/src/utils/solana.ts +0 -100
@@ -14,6 +14,8 @@ import type {
14
14
  ExportWalletParams,
15
15
  OauthConfig,
16
16
  OtpParams,
17
+ JwtParams,
18
+ JwtResponse,
17
19
  User,
18
20
  SubmitOtpCodeResponse,
19
21
  AuthLinkingPrompt,
@@ -259,6 +261,44 @@ export class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams>
259
261
  );
260
262
  }
261
263
 
264
+ /**
265
+ * Authenticates using a custom issued JWT
266
+ *
267
+ * @example
268
+ * ```ts
269
+ * import { AlchemySignerWebClient } from "@account-kit/signer";
270
+ *
271
+ * const client = new AlchemySignerWebClient({
272
+ * connection: {
273
+ * apiKey: "your-api-key",
274
+ * },
275
+ * iframeConfig: {
276
+ * iframeContainerId: "signer-iframe-container",
277
+ * },
278
+ * });
279
+ *
280
+ * const account = await client.submitJwt({
281
+ * jwt: "custom-issued-jwt",
282
+ * authProvider: "auth-provider-name",
283
+ * });
284
+ * ```
285
+ *
286
+ * @param {Omit<JwtParams, "targetPublicKey">} args The parameters for the JWT request, excluding the target public key.
287
+ * @returns {Promise<{ bundle: string }>} A promise that resolves to an object containing the credential bundle.
288
+ */
289
+ public override async submitJwt(
290
+ args: Omit<JwtParams, "targetPublicKey">,
291
+ ): Promise<JwtResponse> {
292
+ this.eventEmitter.emit("authenticating", { type: "custom-jwt" });
293
+ const targetPublicKey = await this.initSessionStamper();
294
+ return this.request("/v1/auth-jwt", {
295
+ jwt: args.jwt,
296
+ targetPublicKey,
297
+ authProvider: args.authProvider,
298
+ expirationSeconds: args?.expirationSeconds,
299
+ });
300
+ }
301
+
262
302
  /**
263
303
  * Completes auth for the user by injecting a credential bundle and retrieving
264
304
  * the user information based on the provided organization ID. Emits events
@@ -95,6 +95,19 @@ export type OtpResponse =
95
95
  multiFactors: MfaFactor[];
96
96
  };
97
97
 
98
+ export type JwtParams = {
99
+ jwt: string;
100
+ targetPublicKey: string;
101
+ authProvider: string;
102
+ expirationSeconds?: number;
103
+ };
104
+
105
+ export type JwtResponse = {
106
+ isSignUp: boolean;
107
+ orgId: string;
108
+ credentialBundle: string;
109
+ };
110
+
98
111
  export type SignupResponse = {
99
112
  orgId: string;
100
113
  userId?: string;
@@ -263,6 +276,11 @@ export type SignerEndpoints = [
263
276
  multiFactors: MfaFactor[];
264
277
  };
265
278
  },
279
+ {
280
+ Route: "/v1/auth-jwt";
281
+ Body: JwtParams;
282
+ Response: JwtResponse;
283
+ },
266
284
  {
267
285
  Route: "/v1/signer-config";
268
286
  Body: {};
@@ -347,7 +365,14 @@ export type SignerEndpoints = [
347
365
  ];
348
366
 
349
367
  export type AuthenticatingEventMetadata = {
350
- type: "email" | "passkey" | "oauth" | "otp" | "otpVerify" | "sms";
368
+ type:
369
+ | "email"
370
+ | "passkey"
371
+ | "oauth"
372
+ | "otp"
373
+ | "otpVerify"
374
+ | "custom-jwt"
375
+ | "sms";
351
376
  };
352
377
 
353
378
  export type AlchemySignerClientEvents = {
@@ -358,6 +383,7 @@ export type AlchemySignerClientEvents = {
358
383
  connectedPasskey(user: User): void;
359
384
  connectedOauth(user: User, bundle: string): void;
360
385
  connectedOtp(user: User, bundle: string): void;
386
+ connectedJwt(user: User, bundle: string): void;
361
387
  disconnected(): void;
362
388
  };
363
389
 
package/src/index.ts CHANGED
@@ -21,7 +21,3 @@ export type * from "./solanaSigner.js";
21
21
  export type * from "./types.js";
22
22
  export { AlchemySignerStatus } from "./types.js";
23
23
  export { SolanaSigner } from "./solanaSigner.js";
24
- export {
25
- createSolanaSponsoredTransaction,
26
- createSolanaTransaction,
27
- } from "./utils/solana.js";
package/src/metrics.ts CHANGED
@@ -15,7 +15,8 @@ export type SignerEventsSchema = [
15
15
  | "oauthReturn";
16
16
  provider?: never;
17
17
  }
18
- | { authType: "oauth"; provider: string };
18
+ | { authType: "oauth"; provider: string }
19
+ | { authType: "custom-jwt"; provider: string };
19
20
  },
20
21
  {
21
22
  EventName: "signer_sign_message";
@@ -97,6 +97,7 @@ export class SessionManager {
97
97
  switch (existingSession.type) {
98
98
  case "email":
99
99
  case "oauth":
100
+ case "custom-jwt":
100
101
  case "otp": {
101
102
  const connectedEventName = (() => {
102
103
  switch (existingSession.type) {
@@ -106,6 +107,8 @@ export class SessionManager {
106
107
  return "connectedOauth";
107
108
  case "otp":
108
109
  return "connectedOtp";
110
+ case "custom-jwt":
111
+ return "connectedJwt";
109
112
  }
110
113
  })();
111
114
  const result = await this.client
@@ -208,7 +211,7 @@ export class SessionManager {
208
211
  private setSession = (
209
212
  session_:
210
213
  | Omit<
211
- Extract<Session, { type: "email" | "oauth" | "otp" }>,
214
+ Extract<Session, { type: "email" | "oauth" | "otp" | "custom-jwt" }>,
212
215
  "expirationDateMs"
213
216
  >
214
217
  | Omit<Extract<Session, { type: "passkey" }>, "expirationDateMs">,
@@ -284,6 +287,9 @@ export class SessionManager {
284
287
  connectedOtp: (user, bundle) => {
285
288
  this.setSessionWithUserAndBundle({ type: "otp", user, bundle });
286
289
  },
290
+ connectedJwt: (user, bundle) => {
291
+ this.setSessionWithUserAndBundle({ type: "custom-jwt", user, bundle });
292
+ },
287
293
  disconnected: () => this.clearSession(),
288
294
  };
289
295
 
@@ -339,7 +345,7 @@ export class SessionManager {
339
345
  user,
340
346
  bundle,
341
347
  }: {
342
- type: "email" | "oauth" | "otp";
348
+ type: "email" | "oauth" | "otp" | "custom-jwt";
343
349
  user: User;
344
350
  bundle: string;
345
351
  }) => {
@@ -2,7 +2,7 @@ import type { User } from "../client/types";
2
2
 
3
3
  export type Session =
4
4
  | {
5
- type: "email" | "oauth" | "otp";
5
+ type: "email" | "oauth" | "otp" | "custom-jwt";
6
6
  bundle: string;
7
7
  expirationDateMs: number;
8
8
  user: User;
package/src/signer.ts CHANGED
@@ -54,6 +54,10 @@ export type AuthParams =
54
54
  idToken: string;
55
55
  isNewUser?: boolean;
56
56
  }
57
+ | ({
58
+ type: "custom-jwt";
59
+ jwt: string;
60
+ } & OauthProviderConfig)
57
61
  | {
58
62
  type: "otp";
59
63
  otpCode: string;
@@ -9,7 +9,6 @@ import {
9
9
  import { size, slice, toBytes, toHex, type ByteArray, type Hex } from "viem";
10
10
  import type { BaseSignerClient } from "./client/base";
11
11
  import { NotAuthenticatedError } from "./errors.js";
12
- import { createSolanaSponsoredTransaction } from "./utils/solana.js";
13
12
 
14
13
  /**
15
14
  * The SolanaSigner class is used to sign transactions and messages for the Solana blockchain.
@@ -160,11 +159,53 @@ export class SolanaSigner {
160
159
  connection: Connection,
161
160
  policyId: string,
162
161
  ): Promise<VersionedTransaction> {
163
- return createSolanaSponsoredTransaction(
162
+ const { blockhash } = await connection.getLatestBlockhash({
163
+ commitment: "finalized",
164
+ });
165
+ const message = new TransactionMessage({
166
+ // Right now the backend will rewrite this payer Key to the server's address
167
+ payerKey: new PublicKey(this.address),
168
+ recentBlockhash: blockhash,
164
169
  instructions,
165
- connection,
166
- policyId,
167
- this.address,
170
+ }).compileToV0Message();
171
+ const versionedTransaction = new VersionedTransaction(message);
172
+ const serializedTransaction = Buffer.from(
173
+ versionedTransaction.serialize(),
174
+ ).toString("base64");
175
+ const body = JSON.stringify({
176
+ id: crypto?.randomUUID() ?? Math.floor(Math.random() * 1000000),
177
+ jsonrpc: "2.0",
178
+ method: "alchemy_requestFeePayer",
179
+ params: [
180
+ {
181
+ policyId,
182
+ serializedTransaction,
183
+ },
184
+ ],
185
+ });
186
+ const options = {
187
+ method: "POST",
188
+ headers: {
189
+ accept: "application/json",
190
+ "content-type": "application/json",
191
+ },
192
+ body,
193
+ };
194
+
195
+ const response = await fetch(
196
+ // TODO: Use the connection??
197
+ connection.rpcEndpoint,
198
+ options,
199
+ );
200
+ const jsonResponse = await response.json();
201
+ if (!jsonResponse?.result?.serializedTransaction)
202
+ throw new Error(
203
+ `Response doesn't include the serializedTransaction ${JSON.stringify(
204
+ jsonResponse,
205
+ )}`,
206
+ );
207
+ return VersionedTransaction.deserialize(
208
+ decodeBase64(jsonResponse.result.serializedTransaction),
168
209
  );
169
210
  }
170
211
 
@@ -184,3 +225,6 @@ export class SolanaSigner {
184
225
  return toHex(messageToSign);
185
226
  }
186
227
  }
228
+ function decodeBase64(serializedTransaction: string): Uint8Array {
229
+ return Buffer.from(serializedTransaction, "base64");
230
+ }
package/src/types.ts CHANGED
@@ -23,6 +23,7 @@ export enum AlchemySignerStatus {
23
23
  AUTHENTICATING_PASSKEY = "AUTHENTICATING_PASSKEY",
24
24
  AUTHENTICATING_EMAIL = "AUTHENTICATING_EMAIL",
25
25
  AUTHENTICATING_OAUTH = "AUTHENTICATING_OAUTH",
26
+ AUTHENTICATING_JWT = "AUTHENTICATING_JWT",
26
27
  AWAITING_EMAIL_AUTH = "AWAITING_EMAIL_AUTH",
27
28
  AWAITING_SMS_AUTH = "AWAITING_SMS_AUTH",
28
29
  AWAITING_OTP_AUTH = "AWAITING_OTP_AUTH",
package/src/version.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  // This file is autogenerated by inject-version.ts. Any changes will be
2
2
  // overwritten on commit!
3
- export const VERSION = "4.53.1-alpha.0";
3
+ export const VERSION = "4.53.2-alpha.0";
@@ -1,21 +0,0 @@
1
- import type { TransactionInstruction } from "@solana/web3.js";
2
- import { Connection, VersionedTransaction } from "@solana/web3.js";
3
- /**
4
- * This function wraps instructions in a sponsored transaction using Alchemy's fee payer service
5
- *
6
- * @param {TransactionInstruction[]} instructions - The instructions to add sponsorship to
7
- * @param {Connection} connection - The connection to use
8
- * @param {string} policyId - The policy id to use
9
- * @param {string} address - The address to use
10
- * @returns {Promise<VersionedTransaction>} - The sponsored transaction
11
- */
12
- export declare function createSolanaSponsoredTransaction(instructions: TransactionInstruction[], connection: Connection, policyId: string, address: string): Promise<VersionedTransaction>;
13
- /**
14
- * Creates a regular (non-sponsored) Solana transaction from instructions
15
- *
16
- * @param {TransactionInstruction[]} instructions - The instructions to create transaction from
17
- * @param {Connection} connection - The connection to use
18
- * @param {string} address - The payer address
19
- * @returns {Promise<VersionedTransaction>} - The transaction
20
- */
21
- export declare function createSolanaTransaction(instructions: TransactionInstruction[], connection: Connection, address: string): Promise<VersionedTransaction>;
@@ -1,72 +0,0 @@
1
- import { Connection, PublicKey, TransactionMessage, VersionedTransaction, } from "@solana/web3.js";
2
- /**
3
- * This function wraps instructions in a sponsored transaction using Alchemy's fee payer service
4
- *
5
- * @param {TransactionInstruction[]} instructions - The instructions to add sponsorship to
6
- * @param {Connection} connection - The connection to use
7
- * @param {string} policyId - The policy id to use
8
- * @param {string} address - The address to use
9
- * @returns {Promise<VersionedTransaction>} - The sponsored transaction
10
- */
11
- export async function createSolanaSponsoredTransaction(instructions, connection, policyId, address) {
12
- const { blockhash } = await connection.getLatestBlockhash({
13
- commitment: "finalized",
14
- });
15
- const message = new TransactionMessage({
16
- // Right now the backend will rewrite this payer Key to the server's address
17
- payerKey: new PublicKey(address),
18
- recentBlockhash: blockhash,
19
- instructions,
20
- }).compileToV0Message();
21
- const versionedTransaction = new VersionedTransaction(message);
22
- const serializedTransaction = Buffer.from(versionedTransaction.serialize()).toString("base64");
23
- const body = JSON.stringify({
24
- id: crypto?.randomUUID() ?? Math.floor(Math.random() * 1000000),
25
- jsonrpc: "2.0",
26
- method: "alchemy_requestFeePayer",
27
- params: [
28
- {
29
- policyId,
30
- serializedTransaction,
31
- },
32
- ],
33
- });
34
- const options = {
35
- method: "POST",
36
- headers: {
37
- accept: "application/json",
38
- "content-type": "application/json",
39
- },
40
- body,
41
- };
42
- const response = await fetch(
43
- // TODO: Use the connection??
44
- connection.rpcEndpoint, options);
45
- const jsonResponse = await response.json();
46
- if (!jsonResponse?.result?.serializedTransaction)
47
- throw new Error(`Response doesn't include the serializedTransaction ${JSON.stringify(jsonResponse)}`);
48
- return VersionedTransaction.deserialize(decodeBase64(jsonResponse.result.serializedTransaction));
49
- }
50
- /**
51
- * Creates a regular (non-sponsored) Solana transaction from instructions
52
- *
53
- * @param {TransactionInstruction[]} instructions - The instructions to create transaction from
54
- * @param {Connection} connection - The connection to use
55
- * @param {string} address - The payer address
56
- * @returns {Promise<VersionedTransaction>} - The transaction
57
- */
58
- export async function createSolanaTransaction(instructions, connection, address) {
59
- const { blockhash } = await connection.getLatestBlockhash({
60
- commitment: "finalized",
61
- });
62
- const message = new TransactionMessage({
63
- payerKey: new PublicKey(address),
64
- recentBlockhash: blockhash,
65
- instructions,
66
- }).compileToV0Message();
67
- return new VersionedTransaction(message);
68
- }
69
- function decodeBase64(serializedTransaction) {
70
- return Buffer.from(serializedTransaction, "base64");
71
- }
72
- //# sourceMappingURL=solana.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"solana.js","sourceRoot":"","sources":["../../../src/utils/solana.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EACV,SAAS,EACT,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,gCAAgC,CACpD,YAAsC,EACtC,UAAsB,EACtB,QAAgB,EAChB,OAAe;IAEf,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,UAAU,CAAC,kBAAkB,CAAC;QACxD,UAAU,EAAE,WAAW;KACxB,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,IAAI,kBAAkB,CAAC;QACrC,4EAA4E;QAC5E,QAAQ,EAAE,IAAI,SAAS,CAAC,OAAO,CAAC;QAChC,eAAe,EAAE,SAAS;QAC1B,YAAY;KACb,CAAC,CAAC,kBAAkB,EAAE,CAAC;IACxB,MAAM,oBAAoB,GAAG,IAAI,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC/D,MAAM,qBAAqB,GAAG,MAAM,CAAC,IAAI,CACvC,oBAAoB,CAAC,SAAS,EAAE,CACjC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACrB,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC;QAC1B,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC;QAC/D,OAAO,EAAE,KAAK;QACd,MAAM,EAAE,yBAAyB;QACjC,MAAM,EAAE;YACN;gBACE,QAAQ;gBACR,qBAAqB;aACtB;SACF;KACF,CAAC,CAAC;IACH,MAAM,OAAO,GAAG;QACd,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,MAAM,EAAE,kBAAkB;YAC1B,cAAc,EAAE,kBAAkB;SACnC;QACD,IAAI;KACL,CAAC;IAEF,MAAM,QAAQ,GAAG,MAAM,KAAK;IAC1B,6BAA6B;IAC7B,UAAU,CAAC,WAAW,EACtB,OAAO,CACR,CAAC;IACF,MAAM,YAAY,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC3C,IAAI,CAAC,YAAY,EAAE,MAAM,EAAE,qBAAqB;QAC9C,MAAM,IAAI,KAAK,CACb,sDAAsD,IAAI,CAAC,SAAS,CAClE,YAAY,CACb,EAAE,CACJ,CAAC;IACJ,OAAO,oBAAoB,CAAC,WAAW,CACrC,YAAY,CAAC,YAAY,CAAC,MAAM,CAAC,qBAAqB,CAAC,CACxD,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,YAAsC,EACtC,UAAsB,EACtB,OAAe;IAEf,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,UAAU,CAAC,kBAAkB,CAAC;QACxD,UAAU,EAAE,WAAW;KACxB,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,IAAI,kBAAkB,CAAC;QACrC,QAAQ,EAAE,IAAI,SAAS,CAAC,OAAO,CAAC;QAChC,eAAe,EAAE,SAAS;QAC1B,YAAY;KACb,CAAC,CAAC,kBAAkB,EAAE,CAAC;IACxB,OAAO,IAAI,oBAAoB,CAAC,OAAO,CAAC,CAAC;AAC3C,CAAC;AAED,SAAS,YAAY,CAAC,qBAA6B;IACjD,OAAO,MAAM,CAAC,IAAI,CAAC,qBAAqB,EAAE,QAAQ,CAAC,CAAC;AACtD,CAAC","sourcesContent":["import type { TransactionInstruction } from \"@solana/web3.js\";\nimport {\n Connection,\n PublicKey,\n TransactionMessage,\n VersionedTransaction,\n} from \"@solana/web3.js\";\n\n/**\n * This function wraps instructions in a sponsored transaction using Alchemy's fee payer service\n *\n * @param {TransactionInstruction[]} instructions - The instructions to add sponsorship to\n * @param {Connection} connection - The connection to use\n * @param {string} policyId - The policy id to use\n * @param {string} address - The address to use\n * @returns {Promise<VersionedTransaction>} - The sponsored transaction\n */\nexport async function createSolanaSponsoredTransaction(\n instructions: TransactionInstruction[],\n connection: Connection,\n policyId: string,\n address: string,\n): Promise<VersionedTransaction> {\n const { blockhash } = await connection.getLatestBlockhash({\n commitment: \"finalized\",\n });\n const message = new TransactionMessage({\n // Right now the backend will rewrite this payer Key to the server's address\n payerKey: new PublicKey(address),\n recentBlockhash: blockhash,\n instructions,\n }).compileToV0Message();\n const versionedTransaction = new VersionedTransaction(message);\n const serializedTransaction = Buffer.from(\n versionedTransaction.serialize(),\n ).toString(\"base64\");\n const body = JSON.stringify({\n id: crypto?.randomUUID() ?? Math.floor(Math.random() * 1000000),\n jsonrpc: \"2.0\",\n method: \"alchemy_requestFeePayer\",\n params: [\n {\n policyId,\n serializedTransaction,\n },\n ],\n });\n const options = {\n method: \"POST\",\n headers: {\n accept: \"application/json\",\n \"content-type\": \"application/json\",\n },\n body,\n };\n\n const response = await fetch(\n // TODO: Use the connection??\n connection.rpcEndpoint,\n options,\n );\n const jsonResponse = await response.json();\n if (!jsonResponse?.result?.serializedTransaction)\n throw new Error(\n `Response doesn't include the serializedTransaction ${JSON.stringify(\n jsonResponse,\n )}`,\n );\n return VersionedTransaction.deserialize(\n decodeBase64(jsonResponse.result.serializedTransaction),\n );\n}\n\n/**\n * Creates a regular (non-sponsored) Solana transaction from instructions\n *\n * @param {TransactionInstruction[]} instructions - The instructions to create transaction from\n * @param {Connection} connection - The connection to use\n * @param {string} address - The payer address\n * @returns {Promise<VersionedTransaction>} - The transaction\n */\nexport async function createSolanaTransaction(\n instructions: TransactionInstruction[],\n connection: Connection,\n address: string,\n): Promise<VersionedTransaction> {\n const { blockhash } = await connection.getLatestBlockhash({\n commitment: \"finalized\",\n });\n const message = new TransactionMessage({\n payerKey: new PublicKey(address),\n recentBlockhash: blockhash,\n instructions,\n }).compileToV0Message();\n return new VersionedTransaction(message);\n}\n\nfunction decodeBase64(serializedTransaction: string): Uint8Array {\n return Buffer.from(serializedTransaction, \"base64\");\n}\n"]}
@@ -1,22 +0,0 @@
1
- import type { TransactionInstruction } from "@solana/web3.js";
2
- import { Connection, VersionedTransaction } from "@solana/web3.js";
3
- /**
4
- * This function wraps instructions in a sponsored transaction using Alchemy's fee payer service
5
- *
6
- * @param {TransactionInstruction[]} instructions - The instructions to add sponsorship to
7
- * @param {Connection} connection - The connection to use
8
- * @param {string} policyId - The policy id to use
9
- * @param {string} address - The address to use
10
- * @returns {Promise<VersionedTransaction>} - The sponsored transaction
11
- */
12
- export declare function createSolanaSponsoredTransaction(instructions: TransactionInstruction[], connection: Connection, policyId: string, address: string): Promise<VersionedTransaction>;
13
- /**
14
- * Creates a regular (non-sponsored) Solana transaction from instructions
15
- *
16
- * @param {TransactionInstruction[]} instructions - The instructions to create transaction from
17
- * @param {Connection} connection - The connection to use
18
- * @param {string} address - The payer address
19
- * @returns {Promise<VersionedTransaction>} - The transaction
20
- */
21
- export declare function createSolanaTransaction(instructions: TransactionInstruction[], connection: Connection, address: string): Promise<VersionedTransaction>;
22
- //# sourceMappingURL=solana.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"solana.d.ts","sourceRoot":"","sources":["../../../src/utils/solana.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EACL,UAAU,EAGV,oBAAoB,EACrB,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;GAQG;AACH,wBAAsB,gCAAgC,CACpD,YAAY,EAAE,sBAAsB,EAAE,EACtC,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,oBAAoB,CAAC,CAiD/B;AAED;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CAC3C,YAAY,EAAE,sBAAsB,EAAE,EACtC,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,oBAAoB,CAAC,CAU/B"}
@@ -1,100 +0,0 @@
1
- import type { TransactionInstruction } from "@solana/web3.js";
2
- import {
3
- Connection,
4
- PublicKey,
5
- TransactionMessage,
6
- VersionedTransaction,
7
- } from "@solana/web3.js";
8
-
9
- /**
10
- * This function wraps instructions in a sponsored transaction using Alchemy's fee payer service
11
- *
12
- * @param {TransactionInstruction[]} instructions - The instructions to add sponsorship to
13
- * @param {Connection} connection - The connection to use
14
- * @param {string} policyId - The policy id to use
15
- * @param {string} address - The address to use
16
- * @returns {Promise<VersionedTransaction>} - The sponsored transaction
17
- */
18
- export async function createSolanaSponsoredTransaction(
19
- instructions: TransactionInstruction[],
20
- connection: Connection,
21
- policyId: string,
22
- address: string,
23
- ): Promise<VersionedTransaction> {
24
- const { blockhash } = await connection.getLatestBlockhash({
25
- commitment: "finalized",
26
- });
27
- const message = new TransactionMessage({
28
- // Right now the backend will rewrite this payer Key to the server's address
29
- payerKey: new PublicKey(address),
30
- recentBlockhash: blockhash,
31
- instructions,
32
- }).compileToV0Message();
33
- const versionedTransaction = new VersionedTransaction(message);
34
- const serializedTransaction = Buffer.from(
35
- versionedTransaction.serialize(),
36
- ).toString("base64");
37
- const body = JSON.stringify({
38
- id: crypto?.randomUUID() ?? Math.floor(Math.random() * 1000000),
39
- jsonrpc: "2.0",
40
- method: "alchemy_requestFeePayer",
41
- params: [
42
- {
43
- policyId,
44
- serializedTransaction,
45
- },
46
- ],
47
- });
48
- const options = {
49
- method: "POST",
50
- headers: {
51
- accept: "application/json",
52
- "content-type": "application/json",
53
- },
54
- body,
55
- };
56
-
57
- const response = await fetch(
58
- // TODO: Use the connection??
59
- connection.rpcEndpoint,
60
- options,
61
- );
62
- const jsonResponse = await response.json();
63
- if (!jsonResponse?.result?.serializedTransaction)
64
- throw new Error(
65
- `Response doesn't include the serializedTransaction ${JSON.stringify(
66
- jsonResponse,
67
- )}`,
68
- );
69
- return VersionedTransaction.deserialize(
70
- decodeBase64(jsonResponse.result.serializedTransaction),
71
- );
72
- }
73
-
74
- /**
75
- * Creates a regular (non-sponsored) Solana transaction from instructions
76
- *
77
- * @param {TransactionInstruction[]} instructions - The instructions to create transaction from
78
- * @param {Connection} connection - The connection to use
79
- * @param {string} address - The payer address
80
- * @returns {Promise<VersionedTransaction>} - The transaction
81
- */
82
- export async function createSolanaTransaction(
83
- instructions: TransactionInstruction[],
84
- connection: Connection,
85
- address: string,
86
- ): Promise<VersionedTransaction> {
87
- const { blockhash } = await connection.getLatestBlockhash({
88
- commitment: "finalized",
89
- });
90
- const message = new TransactionMessage({
91
- payerKey: new PublicKey(address),
92
- recentBlockhash: blockhash,
93
- instructions,
94
- }).compileToV0Message();
95
- return new VersionedTransaction(message);
96
- }
97
-
98
- function decodeBase64(serializedTransaction: string): Uint8Array {
99
- return Buffer.from(serializedTransaction, "base64");
100
- }