utils.ts 983 B

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