-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(lint): apply prettier to secret-numbers (#2549)
The config was not applied when it was moved to the monorepo
- Loading branch information
Showing
7 changed files
with
244 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
"@xrplf/isomorphic": "^1.0.0-beta.0", | ||
"ripple-keypairs": "^2.0.0-beta.0" | ||
}, | ||
"prettier": "@xrplf/prettier-config", | ||
"repository": { | ||
"type": "git", | ||
"url": "[email protected]:XRPLF/xrpl.js.git" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
/* Methods ==================================================================== */ | ||
import Account from "./schema/Account"; | ||
import * as Utils from "./utils"; | ||
import Account from './schema/Account' | ||
import * as Utils from './utils' | ||
|
||
/* Types ==================================================================== */ | ||
|
||
/* Export ==================================================================== */ | ||
export { Account, Utils }; | ||
export { Account, Utils } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,99 @@ | ||
import * as keypairs from "ripple-keypairs"; | ||
import * as keypairs from 'ripple-keypairs' | ||
|
||
import * as utils from "../utils"; | ||
import * as utils from '../utils' | ||
|
||
/* Types ==================================================================== */ | ||
|
||
// eslint-disable-next-line import/no-unused-modules -- it is returned by Account.getKeypair | ||
export interface Keypair { | ||
publicKey: string; | ||
privateKey: string; | ||
publicKey: string | ||
privateKey: string | ||
} | ||
|
||
interface AccountData { | ||
familySeed: string; | ||
address: string; | ||
keypair: Keypair; | ||
familySeed: string | ||
address: string | ||
keypair: Keypair | ||
} | ||
|
||
/* Class ==================================================================== */ | ||
|
||
export default class Account { | ||
private readonly _secret: string[]; | ||
private readonly _secret: string[] | ||
private readonly _account: AccountData = { | ||
familySeed: "", | ||
address: "", | ||
familySeed: '', | ||
address: '', | ||
keypair: { | ||
publicKey: "", | ||
privateKey: "", | ||
publicKey: '', | ||
privateKey: '', | ||
}, | ||
}; | ||
} | ||
|
||
constructor(secretNumbers?: string[] | string | Buffer) { | ||
if (typeof secretNumbers === "string") { | ||
this._secret = utils.parseSecretString(secretNumbers); | ||
if (typeof secretNumbers === 'string') { | ||
this._secret = utils.parseSecretString(secretNumbers) | ||
} else if (Array.isArray(secretNumbers)) { | ||
this._secret = secretNumbers; | ||
this._secret = secretNumbers | ||
} else if (Buffer.isBuffer(secretNumbers)) { | ||
this._secret = utils.entropyToSecret(secretNumbers); | ||
this._secret = utils.entropyToSecret(secretNumbers) | ||
} else { | ||
this._secret = utils.randomSecret(); | ||
this._secret = utils.randomSecret() | ||
} | ||
|
||
validateLengths(this._secret); | ||
this.derive(); | ||
validateLengths(this._secret) | ||
this.derive() | ||
} | ||
|
||
getSecret(): string[] { | ||
return this._secret; | ||
return this._secret | ||
} | ||
|
||
getSecretString(): string { | ||
return this._secret.join(" "); | ||
return this._secret.join(' ') | ||
} | ||
|
||
getAddress(): string { | ||
return this._account.address; | ||
return this._account.address | ||
} | ||
|
||
getFamilySeed(): string { | ||
return this._account.familySeed; | ||
return this._account.familySeed | ||
} | ||
|
||
getKeypair(): Keypair { | ||
return this._account.keypair; | ||
return this._account.keypair | ||
} | ||
|
||
toString(): string { | ||
return this.getSecretString(); | ||
return this.getSecretString() | ||
} | ||
|
||
private derive(): void { | ||
try { | ||
const entropy = utils.secretToEntropy(this._secret); | ||
this._account.familySeed = keypairs.generateSeed({ entropy }); | ||
this._account.keypair = keypairs.deriveKeypair(this._account.familySeed); | ||
const entropy = utils.secretToEntropy(this._secret) | ||
this._account.familySeed = keypairs.generateSeed({ entropy }) | ||
this._account.keypair = keypairs.deriveKeypair(this._account.familySeed) | ||
this._account.address = keypairs.deriveAddress( | ||
this._account.keypair.publicKey | ||
); | ||
this._account.keypair.publicKey, | ||
) | ||
} catch (error) { | ||
let message = "Unknown Error"; | ||
let message = 'Unknown Error' | ||
if (error instanceof Error) { | ||
message = error.message; | ||
message = error.message | ||
} | ||
// we'll proceed, but let's report it | ||
throw new Error(message); | ||
throw new Error(message) | ||
} | ||
} | ||
} | ||
|
||
function validateLengths(secretNumbers: string[]): void { | ||
if (secretNumbers.length !== 8) { | ||
throw new Error("Secret must have 8 numbers"); | ||
throw new Error('Secret must have 8 numbers') | ||
} | ||
secretNumbers.forEach((num) => { | ||
if (num.length !== 6) { | ||
throw new Error("Each secret number must be 6 digits"); | ||
throw new Error('Each secret number must be 6 digits') | ||
} | ||
}); | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.