-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilties.ts
46 lines (40 loc) · 1.37 KB
/
utilties.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import path from 'path'
import { fileURLToPath } from 'url'
import { Keypair, PublicKey } from '@solana/web3.js'
import fs from 'fs'
import * as anchor from '@project-serum/anchor'
import dotenv from 'dotenv'
// @ts-ignore
import findConfig from 'find-config'
dotenv.config({ path: findConfig('.env') })
const { web3 } = anchor
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const PROGRAM_ID = new web3.PublicKey(process.env.SkillStaking_PROGRAM_ID)
export function loadKeypairFromFile(filename: string) {
const secret = JSON.parse(fs.readFileSync(filename).toString())
const secretKey = Uint8Array.from(secret)
return Keypair.fromSecretKey(secretKey)
}
export const readConfig = () => {
const configPath = path.resolve(__dirname, 'cli-config.json')
const configString = fs.readFileSync(configPath, 'utf-8')
return JSON.parse(configString)
}
export const getNameRouterAccount = async (
signingName: string,
signatureVersion: string
) => {
const [nameRouterAccount] = await web3.PublicKey.findProgramAddress(
[
Buffer.from(signingName),
Buffer.from(signatureVersion.toString()),
Buffer.from(process.env.AuthKey),
],
PROGRAM_ID
)
return nameRouterAccount
}
export const mintAddress = new PublicKey(
'4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU'
)