@fogo/sessions-sdk 0.0.11 → 0.0.13

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 CHANGED
@@ -75,7 +75,12 @@ const getSponsor = async (options, domain) => {
75
75
  const url = new URL("/api/sponsor_pubkey", options.paymaster ?? DEFAULT_PAYMASTER);
76
76
  url.searchParams.set("domain", domain);
77
77
  const response = await fetch(url);
78
- return new web3_js_1.PublicKey(zod_1.z.string().parse(await response.text()));
78
+ if (response.status === 200) {
79
+ return new web3_js_1.PublicKey(zod_1.z.string().parse(await response.text()));
80
+ }
81
+ else {
82
+ throw new PaymasterResponseError(response.status, await response.text());
83
+ }
79
84
  }
80
85
  };
81
86
  const sponsorAndSendResponseSchema = zod_1.z
@@ -87,7 +92,9 @@ const sponsorAndSendResponseSchema = zod_1.z
87
92
  zod_1.z.object({
88
93
  type: zod_1.z.literal("failed"),
89
94
  signature: zod_1.z.string(),
90
- error: zod_1.z.object({}),
95
+ error: zod_1.z.object({
96
+ InstructionError: zod_1.z.tuple([zod_1.z.number(), zod_1.z.unknown()]),
97
+ }),
91
98
  }),
92
99
  ])
93
100
  .transform((data) => {
@@ -101,7 +108,6 @@ const sendToPaymaster = async (options, transaction, domain) => {
101
108
  }
102
109
  else {
103
110
  const url = new URL("/api/sponsor_and_send", options.paymaster ?? DEFAULT_PAYMASTER);
104
- url.searchParams.set("confirm", "true");
105
111
  url.searchParams.set("domain", domain);
106
112
  const response = await fetch(url, {
107
113
  method: "POST",
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Sign a message using a CryptoKeyPair session key
3
+ * @param publicPrivateKeyPair - The public private key pair to sign the message with
4
+ * @param message - The message to sign
5
+ * @returns The signature of the message
6
+ */
7
+ export declare const signMessageWithKey: (publicPrivateKeyPair: CryptoKeyPair, message: string) => Promise<string>;
8
+ /**
9
+ * Verify a message with a CryptoKey public key
10
+ * @param publicKey - The public key of the session key
11
+ * @param message - The message to verify
12
+ * @param signature - The signature to verify
13
+ * @returns True if the message and signature are valid, false otherwise
14
+ */
15
+ export declare const verifyMessageWithKey: (publicKey: CryptoKey, message: string, signature: string) => Promise<boolean>;
16
+ /**
17
+ * Import a public key into a CryptoKey
18
+ * @param publicKey - The public key to import
19
+ * @returns The imported CryptoKey
20
+ */
21
+ export declare const importKey: (publicKey: string) => Promise<CryptoKey>;
package/cjs/crypto.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.importKey = exports.verifyMessageWithKey = exports.signMessageWithKey = void 0;
7
+ const bs58_1 = __importDefault(require("bs58"));
8
+ /**
9
+ * Sign a message using a CryptoKeyPair session key
10
+ * @param publicPrivateKeyPair - The public private key pair to sign the message with
11
+ * @param message - The message to sign
12
+ * @returns The signature of the message
13
+ */
14
+ const signMessageWithKey = async (publicPrivateKeyPair, message) => {
15
+ const signature = await crypto.subtle.sign({ name: "Ed25519" }, publicPrivateKeyPair.privateKey, new TextEncoder().encode(message));
16
+ return bs58_1.default.encode(new Uint8Array(signature));
17
+ };
18
+ exports.signMessageWithKey = signMessageWithKey;
19
+ /**
20
+ * Verify a message with a CryptoKey public key
21
+ * @param publicKey - The public key of the session key
22
+ * @param message - The message to verify
23
+ * @param signature - The signature to verify
24
+ * @returns True if the message and signature are valid, false otherwise
25
+ */
26
+ const verifyMessageWithKey = async (publicKey, message, signature) => {
27
+ const isValid = await crypto.subtle.verify({ name: "Ed25519" }, publicKey, bs58_1.default.decode(signature), new TextEncoder().encode(message));
28
+ return isValid;
29
+ };
30
+ exports.verifyMessageWithKey = verifyMessageWithKey;
31
+ /**
32
+ * Import a public key into a CryptoKey
33
+ * @param publicKey - The public key to import
34
+ * @returns The imported CryptoKey
35
+ */
36
+ const importKey = async (publicKey) => {
37
+ return await crypto.subtle.importKey("raw", new Uint8Array(bs58_1.default.decode(publicKey)), { name: "Ed25519" }, false, ["verify"]);
38
+ };
39
+ exports.importKey = importKey;