Skip to content

Commit

Permalink
remove json yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-Rey committed Aug 12, 2024
1 parent d7e04b3 commit 1374edd
Showing 1 changed file with 17 additions and 39 deletions.
56 changes: 17 additions & 39 deletions src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,6 @@ import Sealer from './crypto/interfaces/sealer'
import { PasswordSeal } from './crypto/passwordSeal'
import { Address, PrivateKey, PublicKey, Signature } from './basicElements'

let fs: typeof import('fs') | undefined
let yaml: typeof import('js-yaml') | undefined

if (typeof window === 'undefined') {
console.log('Running in Node.js')
// Running in Node.js
import('fs')
.then((module) => {
fs = module
})
.catch(() => {
// ignore error
})

import('js-yaml')
.then((module) => {
yaml = module
})
.catch(() => {
// ignore error
})
}

/**
* A class representing an account.
*/
Expand Down Expand Up @@ -254,23 +231,24 @@ export class Account {
return Account.fromPrivateKey(PrivateKey.fromEnv(key))
}

/**
* Uses the environment variables to create an account.
*
* @returns An account instance.
*/
static async fromYaml(path: string, password: string): Promise<Account> {
if (typeof window !== 'undefined' || !fs || !yaml) {
throw new Error('This function is not available in the browser')
}
// check that file exists
if (!fs.existsSync(path)) {
throw new Error(`wallet file "${path}" does not exist.`)
}
// TODO fix js-yaml import in browser
// /**
// * Uses the environment variables to create an account.
// *
// * @returns An account instance.
// */
// static async fromYaml(path: string, password: string): Promise<Account> {
// if (typeof window !== 'undefined' || !fs || !yaml) {
// throw new Error('This function is not available in the browser')
// }
// // check that file exists
// if (!fs.existsSync(path)) {
// throw new Error(`wallet file "${path}" does not exist.`)
// }

const ks = yaml.load(fs.readFileSync(path, 'utf8')) as AccountKeyStore
return Account.fromKeyStore(ks, password)
}
// const ks = yaml.load(fs.readFileSync(path, 'utf8')) as AccountKeyStore
// return Account.fromKeyStore(ks, password)
// }
}

/* eslint-disable @typescript-eslint/naming-convention */
Expand Down

0 comments on commit 1374edd

Please sign in to comment.