@openfort/openfort-node 0.10.0 → 0.10.1

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.
@@ -1,6 +1,10 @@
1
1
  // Usage: npx tsx solana/accounts/importAccount.ts
2
2
 
3
3
  import Openfort from "@openfort/openfort-node";
4
+ import {
5
+ createKeyPairFromPrivateKeyBytes,
6
+ getAddressFromPublicKey,
7
+ } from "@solana/kit";
4
8
  import "dotenv/config";
5
9
 
6
10
  const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
@@ -8,18 +12,20 @@ const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
8
12
  walletSecret: process.env.OPENFORT_WALLET_SECRET,
9
13
  });
10
14
 
11
- // For demonstration, we'll use a random 32-byte hex key
12
- // In production, you would use an actual Solana private key (base58 or hex format)
13
- const privateKeyHex = Array.from({ length: 64 }, () =>
14
- Math.floor(Math.random() * 16).toString(16)
15
- ).join("");
15
+ // Generate a random 32-byte private key using @solana/kit
16
+ const privateKeyBytes = new Uint8Array(32);
17
+ crypto.getRandomValues(privateKeyBytes);
16
18
 
17
- console.log("Private key (hex):", privateKeyHex);
19
+ const { publicKey } = await createKeyPairFromPrivateKeyBytes(privateKeyBytes);
20
+ const solanaAddress = await getAddressFromPublicKey(publicKey);
21
+ console.log("Generated Solana address:", solanaAddress);
22
+
23
+ // Convert private key bytes to hex for import
24
+ const privateKeyHex = Buffer.from(privateKeyBytes).toString("hex");
18
25
 
19
26
  // Import the account to Openfort
20
- // Openfort accepts both base58 and hex format for Solana keys
21
27
  const account = await openfort.accounts.solana.backend.import({
22
- privateKey: privateKeyHex, // Can also be base58 format
28
+ privateKey: privateKeyHex,
23
29
  });
24
30
 
25
31
  console.log("\nImported Solana account:");
@@ -1,6 +1,18 @@
1
1
  // Usage: npx tsx solana/signing/signTransaction.ts
2
2
 
3
3
  import Openfort from "@openfort/openfort-node";
4
+ import { getTransferSolInstruction } from "@solana-program/system";
5
+ import {
6
+ address,
7
+ createNoopSigner,
8
+ createSolanaRpc,
9
+ createTransactionMessage,
10
+ setTransactionMessageFeePayerSigner,
11
+ setTransactionMessageLifetimeUsingBlockhash,
12
+ appendTransactionMessageInstruction,
13
+ compileTransaction,
14
+ getBase64EncodedWireTransaction,
15
+ } from "@solana/kit";
4
16
  import "dotenv/config";
5
17
 
6
18
  const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
@@ -12,28 +24,37 @@ const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
12
24
  const account = await openfort.accounts.solana.backend.create();
13
25
  console.log("Created Solana account:", account.address);
14
26
 
15
- // Create a sample transaction (base64 encoded)
16
- // In production, you would create this using @solana/web3.js
17
- // This is a placeholder transaction for demonstration
18
- const sampleTransaction = Buffer.from("sample-transaction-data").toString(
19
- "base64"
27
+ // Build a transaction using @solana/kit
28
+ const rpc = createSolanaRpc("https://api.devnet.solana.com");
29
+ const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();
30
+
31
+ const sender = createNoopSigner(address(account.address));
32
+ const destination = address("FDx9mfVqTvXUaSPQDELwDtGgMqxirmAFsEK2s4YsKfsc");
33
+
34
+ const transferIx = getTransferSolInstruction({
35
+ source: sender,
36
+ destination,
37
+ amount: 1_000n,
38
+ });
39
+
40
+ const transactionMessage = appendTransactionMessageInstruction(
41
+ transferIx,
42
+ setTransactionMessageLifetimeUsingBlockhash(
43
+ latestBlockhash,
44
+ setTransactionMessageFeePayerSigner(
45
+ sender,
46
+ createTransactionMessage({ version: 0 }),
47
+ ),
48
+ ),
20
49
  );
21
50
 
22
- console.log("\nTransaction (base64):", sampleTransaction);
51
+ const compiledTransaction = compileTransaction(transactionMessage);
52
+ const base64Transaction = getBase64EncodedWireTransaction(compiledTransaction);
53
+
54
+ console.log("\nTransaction (base64):", base64Transaction);
23
55
 
24
56
  // Sign the transaction
25
- // Note: This example uses a placeholder. In production, create a proper
26
- // Solana transaction using @solana/web3.js or @solana/kit and serialize it to base64
27
- try {
28
- const signedTransaction = await account.signTransaction({
29
- transaction: sampleTransaction,
30
- });
31
- console.log("Signed transaction:", signedTransaction);
32
- } catch (error) {
33
- console.log(
34
- "\nNote: This example uses a placeholder transaction."
35
- );
36
- console.log(
37
- "In production, create a valid Solana transaction using @solana/web3.js"
38
- );
39
- }
57
+ const signedTransaction = await account.signTransaction({
58
+ transaction: base64Transaction,
59
+ });
60
+ console.log("Signed transaction:", signedTransaction);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfort/openfort-node",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "description": "Openfort Node SDK",
5
5
  "author": "Openfort",
6
6
  "repository": {