mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
run lint --fix
This commit is contained in:
@@ -202,14 +202,22 @@ export function encodeAccountID(bytes: Buffer): string {
|
||||
return codecWithXrpAlphabet.encode(bytes, opts)
|
||||
}
|
||||
|
||||
/* eslint-disable import/no-unused-modules ---
|
||||
* unclear why this is aliased but we should keep it in case someone else is
|
||||
* importing it with the aliased name */
|
||||
export const encodeAddress = encodeAccountID
|
||||
/* eslint-enable import/no-unused-modules */
|
||||
|
||||
export function decodeAccountID(accountId: string): Buffer {
|
||||
const opts = { versions: [ACCOUNT_ID], expectedLength: 20 }
|
||||
return codecWithXrpAlphabet.decode(accountId, opts).bytes
|
||||
}
|
||||
|
||||
/* eslint-disable import/no-unused-modules ---
|
||||
* unclear why this is aliased but we should keep it in case someone else is
|
||||
* importing it with the aliased name */
|
||||
export const decodeAddress = decodeAccountID
|
||||
/* eslint-enable import/no-unused-modules */
|
||||
|
||||
export function decodeNodePublic(base58string: string): Buffer {
|
||||
const opts = { versions: [NODE_PUBLIC], expectedLength: 33 }
|
||||
|
||||
@@ -19,10 +19,7 @@ import {
|
||||
verify,
|
||||
sign,
|
||||
} from 'ripple-keypairs'
|
||||
|
||||
import {
|
||||
Utils
|
||||
} from 'xrpl-secret-numbers'
|
||||
import { Utils } from 'xrpl-secret-numbers'
|
||||
|
||||
import ECDSA from '../ECDSA'
|
||||
import { ValidationError } from '../errors'
|
||||
@@ -116,7 +113,7 @@ class Wallet {
|
||||
privateKey: string,
|
||||
opts: {
|
||||
masterAddress?: string
|
||||
seed?: string,
|
||||
seed?: string
|
||||
secretNumbers?: string
|
||||
} = {},
|
||||
) {
|
||||
@@ -211,16 +208,16 @@ class Wallet {
|
||||
* @returns A Wallet derived from secret numbers.
|
||||
* @throws ValidationError if unable to derive private key from secret number input.
|
||||
*/
|
||||
public static fromSecretNumbers(
|
||||
secretNumbers: Array<string> | string,
|
||||
opts: { masterAddress?: string, algorithm?: ECDSA } = {},
|
||||
public static fromSecretNumbers(
|
||||
secretNumbers: string[] | string,
|
||||
opts: { masterAddress?: string; algorithm?: ECDSA } = {},
|
||||
): Wallet {
|
||||
let numbersArray:Array<string> = [];
|
||||
let numbersArray: string[] = []
|
||||
|
||||
if (typeof secretNumbers === 'string') {
|
||||
numbersArray = Utils.parseSecretString(secretNumbers);
|
||||
numbersArray = Utils.parseSecretString(secretNumbers)
|
||||
} else if (Array.isArray(secretNumbers)) {
|
||||
numbersArray = secretNumbers;
|
||||
numbersArray = secretNumbers
|
||||
}
|
||||
|
||||
const entropy = Utils.secretToEntropy(numbersArray)
|
||||
@@ -228,7 +225,7 @@ class Wallet {
|
||||
return Wallet.fromEntropy(entropy, {
|
||||
algorithm: opts.algorithm ?? ECDSA.secp256k1,
|
||||
masterAddress: opts.masterAddress,
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -228,8 +228,18 @@ describe('Wallet', function () {
|
||||
})
|
||||
|
||||
describe('fromSecretNumbers', function () {
|
||||
const secretNumbersString = '399150 474506 009147 088773 432160 282843 253738 605430'
|
||||
const secretNumbersArray = ["399150","474506","009147","088773","432160","282843","253738","605430"]
|
||||
const secretNumbersString =
|
||||
'399150 474506 009147 088773 432160 282843 253738 605430'
|
||||
const secretNumbersArray = [
|
||||
'399150',
|
||||
'474506',
|
||||
'009147',
|
||||
'088773',
|
||||
'432160',
|
||||
'282843',
|
||||
'253738',
|
||||
'605430',
|
||||
]
|
||||
|
||||
const publicKey =
|
||||
'03BFC2F7AE242C3493187FA0B72BE97B2DF71194FB772E507FF9DEA0AD13CA1625'
|
||||
@@ -240,52 +250,59 @@ describe('Wallet', function () {
|
||||
const privateKeyED25519 =
|
||||
'EDD2AF6288A903DED9860FC62E778600A985BDF804E40BD8266505553E3222C3DA'
|
||||
|
||||
it('derives a wallet using default algorithm', function () {
|
||||
const wallet = Wallet.fromSecretNumbers(secretNumbersString)
|
||||
it('derives a wallet using default algorithm', function () {
|
||||
const wallet = Wallet.fromSecretNumbers(secretNumbersString)
|
||||
|
||||
assert.equal(wallet.publicKey, publicKey)
|
||||
assert.equal(wallet.privateKey, privateKey)
|
||||
assert.equal(wallet.publicKey, publicKey)
|
||||
assert.equal(wallet.privateKey, privateKey)
|
||||
})
|
||||
|
||||
it('derives a wallet from secret numbers as an array using default algorithm', function () {
|
||||
const wallet = Wallet.fromSecretNumbers(secretNumbersArray)
|
||||
|
||||
assert.equal(wallet.publicKey, publicKey)
|
||||
assert.equal(wallet.privateKey, privateKey)
|
||||
})
|
||||
|
||||
it('derives a wallet using algorithm ecdsa-secp256k1', function () {
|
||||
const algorithm = ECDSA.secp256k1
|
||||
const wallet = Wallet.fromSecretNumbers(secretNumbersString, {
|
||||
algorithm,
|
||||
})
|
||||
|
||||
it('derives a wallet from secret numbers as an array using default algorithm', function () {
|
||||
const wallet = Wallet.fromSecretNumbers(secretNumbersArray)
|
||||
assert.equal(wallet.publicKey, publicKey)
|
||||
assert.equal(wallet.privateKey, privateKey)
|
||||
})
|
||||
|
||||
assert.equal(wallet.publicKey, publicKey)
|
||||
assert.equal(wallet.privateKey, privateKey)
|
||||
it('derives a wallet using algorithm ed25519', function () {
|
||||
const algorithm = ECDSA.ed25519
|
||||
const wallet = Wallet.fromSecretNumbers(secretNumbersString, {
|
||||
algorithm,
|
||||
})
|
||||
|
||||
it('derives a wallet using algorithm ecdsa-secp256k1', function () {
|
||||
const algorithm = ECDSA.secp256k1
|
||||
const wallet = Wallet.fromSecretNumbers(secretNumbersString, { algorithm })
|
||||
assert.equal(wallet.publicKey, publicKeyED25519)
|
||||
assert.equal(wallet.privateKey, privateKeyED25519)
|
||||
})
|
||||
|
||||
assert.equal(wallet.publicKey, publicKey)
|
||||
assert.equal(wallet.privateKey, privateKey)
|
||||
it('derives a wallet using a Regular Key Pair', function () {
|
||||
const masterAddress = 'rUAi7pipxGpYfPNg3LtPcf2ApiS8aw9A93'
|
||||
const regularKeyPair = {
|
||||
secretNumbers:
|
||||
'399150 474506 009147 088773 432160 282843 253738 605430',
|
||||
publicKey:
|
||||
'03BFC2F7AE242C3493187FA0B72BE97B2DF71194FB772E507FF9DEA0AD13CA1625',
|
||||
privateKey:
|
||||
'00B6FE8507D977E46E988A8A94DB3B8B35E404B60F8B11AC5213FA8B5ABC8A8D19',
|
||||
}
|
||||
|
||||
const wallet = Wallet.fromSecretNumbers(regularKeyPair.secretNumbers, {
|
||||
masterAddress,
|
||||
})
|
||||
|
||||
it('derives a wallet using algorithm ed25519', function () {
|
||||
const algorithm = ECDSA.ed25519
|
||||
const wallet = Wallet.fromSecretNumbers(secretNumbersString, { algorithm })
|
||||
|
||||
assert.equal(wallet.publicKey, publicKeyED25519)
|
||||
assert.equal(wallet.privateKey, privateKeyED25519)
|
||||
})
|
||||
|
||||
it('derives a wallet using a Regular Key Pair', function () {
|
||||
const masterAddress = 'rUAi7pipxGpYfPNg3LtPcf2ApiS8aw9A93'
|
||||
const regularKeyPair = {
|
||||
secretNumbers: '399150 474506 009147 088773 432160 282843 253738 605430',
|
||||
publicKey:
|
||||
'03BFC2F7AE242C3493187FA0B72BE97B2DF71194FB772E507FF9DEA0AD13CA1625',
|
||||
privateKey:
|
||||
'00B6FE8507D977E46E988A8A94DB3B8B35E404B60F8B11AC5213FA8B5ABC8A8D19',
|
||||
}
|
||||
|
||||
const wallet = Wallet.fromSecretNumbers(regularKeyPair.secretNumbers, { masterAddress })
|
||||
|
||||
assert.equal(wallet.publicKey, regularKeyPair.publicKey)
|
||||
assert.equal(wallet.privateKey, regularKeyPair.privateKey)
|
||||
assert.equal(wallet.classicAddress, masterAddress)
|
||||
})
|
||||
assert.equal(wallet.publicKey, regularKeyPair.publicKey)
|
||||
assert.equal(wallet.privateKey, regularKeyPair.privateKey)
|
||||
assert.equal(wallet.classicAddress, masterAddress)
|
||||
})
|
||||
})
|
||||
|
||||
describe('fromEntropy', function () {
|
||||
|
||||
Reference in New Issue
Block a user