utils.ts 972 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import {
  2. Connection,
  3. Keypair,
  4. PublicKey,
  5. Signer,
  6. TransactionInstruction,
  7. TransactionMessage,
  8. VersionedTransaction,
  9. AccountMeta,
  10. } from "@solana/web3.js";
  11. import * as bs58 from "bs58";
  12. export function loadWalletKey(keypairFile: string): Keypair {
  13. const fs = require("fs");
  14. return Keypair.fromSecretKey(
  15. new Uint8Array(JSON.parse(fs.readFileSync(keypairFile).toString()))
  16. );
  17. }
  18. export function decode(stuff: string) {
  19. return bufferToArray(bs58.decode(stuff));
  20. }
  21. function bufferToArray(buffer: Buffer): number[] {
  22. const nums: number[] = [];
  23. for (let i = 0; i < buffer.length; i++) {
  24. nums.push(buffer[i]);
  25. }
  26. return nums;
  27. }
  28. export const mapProof = (assetProof: { proof: string[] }): AccountMeta[] => {
  29. if (!assetProof.proof || assetProof.proof.length === 0) {
  30. throw new Error("Proof is empty");
  31. }
  32. return assetProof.proof.map((node) => ({
  33. pubkey: new PublicKey(node),
  34. isSigner: false,
  35. isWritable: false,
  36. }));
  37. };