@account-kit/signer 4.54.1 → 4.56.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.
- package/dist/esm/client/base.d.ts +7 -0
- package/dist/esm/client/base.js +28 -0
- package/dist/esm/client/base.js.map +1 -1
- package/dist/esm/client/types.d.ts +26 -0
- package/dist/esm/client/types.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/solanaSigner.js +2 -40
- package/dist/esm/solanaSigner.js.map +1 -1
- package/dist/esm/utils/solana.d.ts +21 -0
- package/dist/esm/utils/solana.js +72 -0
- package/dist/esm/utils/solana.js.map +1 -0
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/client/base.d.ts +7 -0
- package/dist/types/client/base.d.ts.map +1 -1
- package/dist/types/client/types.d.ts +26 -0
- package/dist/types/client/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/solanaSigner.d.ts.map +1 -1
- package/dist/types/utils/solana.d.ts +22 -0
- package/dist/types/utils/solana.d.ts.map +1 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +4 -4
- package/src/client/base.ts +36 -0
- package/src/client/types.ts +26 -0
- package/src/index.ts +4 -0
- package/src/solanaSigner.ts +5 -49
- package/src/utils/solana.ts +100 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,100 @@
|
|
|
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
|
+
}
|
package/src/version.ts
CHANGED