@fogo/sessions-sdk 0.0.12 → 0.0.14
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 +6 -2
- package/cjs/crypto.d.ts +21 -0
- package/cjs/crypto.js +39 -0
- package/cjs/index.d.ts +1203 -158
- package/cjs/index.js +262 -46
- package/esm/adapter.js +6 -2
- package/esm/crypto.d.ts +21 -0
- package/esm/crypto.js +30 -0
- package/esm/index.d.ts +1203 -158
- package/esm/index.js +260 -47
- package/package.json +3 -12
- package/cjs/paymaster.d.ts +0 -7
- package/cjs/paymaster.js +0 -51
- package/esm/paymaster.d.ts +0 -7
- package/esm/paymaster.js +0 -47
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
|
-
|
|
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
|
|
@@ -103,7 +108,6 @@ const sendToPaymaster = async (options, transaction, domain) => {
|
|
|
103
108
|
}
|
|
104
109
|
else {
|
|
105
110
|
const url = new URL("/api/sponsor_and_send", options.paymaster ?? DEFAULT_PAYMASTER);
|
|
106
|
-
url.searchParams.set("confirm", "true");
|
|
107
111
|
url.searchParams.set("domain", domain);
|
|
108
112
|
const response = await fetch(url, {
|
|
109
113
|
method: "POST",
|
package/cjs/crypto.d.ts
ADDED
|
@@ -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;
|