mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-19 19:55:51 +00:00
chore(lint): apply prettier to secret-numbers (#2549)
The config was not applied when it was moved to the monorepo
This commit is contained in:
@@ -1,99 +1,95 @@
|
||||
import * as keypairs from "ripple-keypairs";
|
||||
import * as keypairs from 'ripple-keypairs'
|
||||
|
||||
import { Account, Utils } from "../src";
|
||||
import { Account, Utils } from '../src'
|
||||
|
||||
describe("API: XRPL Secret Numbers", () => {
|
||||
describe("Generate new account", () => {
|
||||
const account = new Account();
|
||||
it("Output sanity checks", () => {
|
||||
expect(account.getAddress()).toMatch(/^r[a-zA-Z0-9]{19,}$/u);
|
||||
const entropy = Utils.secretToEntropy(`${account.toString()}`.split(" "));
|
||||
const familySeed = keypairs.generateSeed({ entropy });
|
||||
const keypair = keypairs.deriveKeypair(familySeed);
|
||||
const address = keypairs.deriveAddress(keypair.publicKey);
|
||||
expect(address).toEqual(account.getAddress());
|
||||
expect(familySeed).toEqual(account.getFamilySeed());
|
||||
});
|
||||
});
|
||||
describe('API: XRPL Secret Numbers', () => {
|
||||
describe('Generate new account', () => {
|
||||
const account = new Account()
|
||||
it('Output sanity checks', () => {
|
||||
expect(account.getAddress()).toMatch(/^r[a-zA-Z0-9]{19,}$/u)
|
||||
const entropy = Utils.secretToEntropy(`${account.toString()}`.split(' '))
|
||||
const familySeed = keypairs.generateSeed({ entropy })
|
||||
const keypair = keypairs.deriveKeypair(familySeed)
|
||||
const address = keypairs.deriveAddress(keypair.publicKey)
|
||||
expect(address).toEqual(account.getAddress())
|
||||
expect(familySeed).toEqual(account.getFamilySeed())
|
||||
})
|
||||
})
|
||||
|
||||
describe("Account based on entropy", () => {
|
||||
const entropy = Buffer.from("0123456789ABCDEF0123456789ABCDEF", "hex");
|
||||
const account = new Account(entropy);
|
||||
describe('Account based on entropy', () => {
|
||||
const entropy = Buffer.from('0123456789ABCDEF0123456789ABCDEF', 'hex')
|
||||
const account = new Account(entropy)
|
||||
|
||||
it("familySeed as expected", () => {
|
||||
expect(account.getFamilySeed()).toEqual("sp5DmDCut79BpgumfHhvRzdxXYQyU");
|
||||
});
|
||||
it("address as expected", () => {
|
||||
expect(account.getAddress()).toEqual(
|
||||
"rMCcybKHfwCSkDHd3M36PAeUniEoygwjR3"
|
||||
);
|
||||
});
|
||||
it("Account object to string as expected", () => {
|
||||
it('familySeed as expected', () => {
|
||||
expect(account.getFamilySeed()).toEqual('sp5DmDCut79BpgumfHhvRzdxXYQyU')
|
||||
})
|
||||
it('address as expected', () => {
|
||||
expect(account.getAddress()).toEqual('rMCcybKHfwCSkDHd3M36PAeUniEoygwjR3')
|
||||
})
|
||||
it('Account object to string as expected', () => {
|
||||
const accountAsStr =
|
||||
"002913 177673 352434 527196 002910 177672 352435 527190";
|
||||
expect(`${account.toString()}`).toEqual(accountAsStr);
|
||||
});
|
||||
});
|
||||
'002913 177673 352434 527196 002910 177672 352435 527190'
|
||||
expect(`${account.toString()}`).toEqual(accountAsStr)
|
||||
})
|
||||
})
|
||||
|
||||
describe("Account based on existing secret", () => {
|
||||
describe('Account based on existing secret', () => {
|
||||
const secret = [
|
||||
"084677",
|
||||
"005323",
|
||||
"580272",
|
||||
"282388",
|
||||
"626800",
|
||||
"105300",
|
||||
"560913",
|
||||
"071783",
|
||||
];
|
||||
'084677',
|
||||
'005323',
|
||||
'580272',
|
||||
'282388',
|
||||
'626800',
|
||||
'105300',
|
||||
'560913',
|
||||
'071783',
|
||||
]
|
||||
|
||||
const account = new Account(secret);
|
||||
const account = new Account(secret)
|
||||
|
||||
it("familySeed as expected", () => {
|
||||
expect(account.getFamilySeed()).toEqual("sswpWwri7Y11dNCSmXdphgcoPZk3y");
|
||||
});
|
||||
it("publicKey as expected", () => {
|
||||
it('familySeed as expected', () => {
|
||||
expect(account.getFamilySeed()).toEqual('sswpWwri7Y11dNCSmXdphgcoPZk3y')
|
||||
})
|
||||
it('publicKey as expected', () => {
|
||||
const pubkey =
|
||||
"020526A0EDC9123F7FBB7588402518B80FCD2C8D8AB4C45F5A68A2F220098EA06F";
|
||||
expect(account.getKeypair().publicKey).toEqual(pubkey);
|
||||
});
|
||||
it("privateKey as expected", () => {
|
||||
'020526A0EDC9123F7FBB7588402518B80FCD2C8D8AB4C45F5A68A2F220098EA06F'
|
||||
expect(account.getKeypair().publicKey).toEqual(pubkey)
|
||||
})
|
||||
it('privateKey as expected', () => {
|
||||
const privkey =
|
||||
"005122B2127B4635FEE7D242FA6EC9B02B611C04494D0D7D49764374D90C8BC8D3";
|
||||
expect(account.getKeypair().privateKey).toEqual(privkey);
|
||||
});
|
||||
it("address as expected", () => {
|
||||
expect(account.getAddress()).toEqual(
|
||||
"rfqJsRLLmr7wdWnEzW1mP6AVaPSdzmso9Z"
|
||||
);
|
||||
});
|
||||
it("Account object to string as expected", () => {
|
||||
'005122B2127B4635FEE7D242FA6EC9B02B611C04494D0D7D49764374D90C8BC8D3'
|
||||
expect(account.getKeypair().privateKey).toEqual(privkey)
|
||||
})
|
||||
it('address as expected', () => {
|
||||
expect(account.getAddress()).toEqual('rfqJsRLLmr7wdWnEzW1mP6AVaPSdzmso9Z')
|
||||
})
|
||||
it('Account object to string as expected', () => {
|
||||
const accountAsStr =
|
||||
"084677 005323 580272 282388 626800 105300 560913 071783";
|
||||
expect(`${account.toString()}`).toEqual(accountAsStr);
|
||||
});
|
||||
});
|
||||
'084677 005323 580272 282388 626800 105300 560913 071783'
|
||||
expect(`${account.toString()}`).toEqual(accountAsStr)
|
||||
})
|
||||
})
|
||||
|
||||
describe("Checksum error", () => {
|
||||
describe('Checksum error', () => {
|
||||
const secret = [
|
||||
"084677",
|
||||
"005324",
|
||||
"580272",
|
||||
"626800",
|
||||
"282388",
|
||||
"105300",
|
||||
"560913",
|
||||
"071783",
|
||||
];
|
||||
it("Should throw an Checksum Error", () => {
|
||||
'084677',
|
||||
'005324',
|
||||
'580272',
|
||||
'626800',
|
||||
'282388',
|
||||
'105300',
|
||||
'560913',
|
||||
'071783',
|
||||
]
|
||||
it('Should throw an Checksum Error', () => {
|
||||
expect(() => {
|
||||
// eslint-disable-next-line no-new -- Don't want unused variable
|
||||
new Account(secret);
|
||||
new Account(secret)
|
||||
})
|
||||
// TODO: Remove if jest is removed.
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- Jest and Jasmine have two different signatures.
|
||||
// @ts-expect-error
|
||||
.toThrowError(Error, "Invalid secret part: checksum invalid");
|
||||
});
|
||||
});
|
||||
});
|
||||
.toThrowError(Error, 'Invalid secret part: checksum invalid')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,107 +1,107 @@
|
||||
import * as utils from "../src/utils";
|
||||
import * as utils from '../src/utils'
|
||||
|
||||
describe("Utils", () => {
|
||||
it("randomEntropy: valid output", () => {
|
||||
const data = utils.randomEntropy();
|
||||
expect(typeof data).toEqual("object");
|
||||
expect(data instanceof Buffer).toBeTruthy();
|
||||
expect(data.length).toEqual(16);
|
||||
expect(data.toString("hex").length).toEqual(32);
|
||||
expect(data.toString("hex")).toMatch(/^[a-f0-9]+$/u);
|
||||
});
|
||||
describe('Utils', () => {
|
||||
it('randomEntropy: valid output', () => {
|
||||
const data = utils.randomEntropy()
|
||||
expect(typeof data).toEqual('object')
|
||||
expect(data instanceof Buffer).toBeTruthy()
|
||||
expect(data.length).toEqual(16)
|
||||
expect(data.toString('hex').length).toEqual(32)
|
||||
expect(data.toString('hex')).toMatch(/^[a-f0-9]+$/u)
|
||||
})
|
||||
|
||||
it("calculateChecksum: 1st position", () => {
|
||||
expect(utils.calculateChecksum(0, 55988)).toEqual(8);
|
||||
});
|
||||
it('calculateChecksum: 1st position', () => {
|
||||
expect(utils.calculateChecksum(0, 55988)).toEqual(8)
|
||||
})
|
||||
|
||||
it("calculateChecksum: 8th position", () => {
|
||||
expect(utils.calculateChecksum(7, 49962)).toEqual(0);
|
||||
});
|
||||
it('calculateChecksum: 8th position', () => {
|
||||
expect(utils.calculateChecksum(7, 49962)).toEqual(0)
|
||||
})
|
||||
|
||||
it("checkChecksum: 2nd position, split numbers", () => {
|
||||
expect(utils.checkChecksum(1, 55450, 3)).toBeTruthy();
|
||||
});
|
||||
it('checkChecksum: 2nd position, split numbers', () => {
|
||||
expect(utils.checkChecksum(1, 55450, 3)).toBeTruthy()
|
||||
})
|
||||
|
||||
it("checkChecksum: 7th position, split numbers", () => {
|
||||
expect(utils.checkChecksum(6, 18373, 7)).toBeTruthy();
|
||||
});
|
||||
it('checkChecksum: 7th position, split numbers', () => {
|
||||
expect(utils.checkChecksum(6, 18373, 7)).toBeTruthy()
|
||||
})
|
||||
|
||||
it("checkChecksum: 4th position, as string", () => {
|
||||
expect(utils.checkChecksum(3, "391566")).toBeTruthy();
|
||||
});
|
||||
it('checkChecksum: 4th position, as string', () => {
|
||||
expect(utils.checkChecksum(3, '391566')).toBeTruthy()
|
||||
})
|
||||
|
||||
it("randomSecret: valid checksums", () => {
|
||||
utils.randomSecret();
|
||||
expect(0).toEqual(0);
|
||||
});
|
||||
it('randomSecret: valid checksums', () => {
|
||||
utils.randomSecret()
|
||||
expect(0).toEqual(0)
|
||||
})
|
||||
|
||||
it("randomSecret: valid output", () => {
|
||||
const data = utils.randomSecret();
|
||||
expect(Array.isArray(data)).toBeTruthy();
|
||||
expect(data.length).toEqual(8);
|
||||
expect(typeof data[0]).toEqual("string");
|
||||
expect(data[0].length).toEqual(6);
|
||||
expect(data[7].length).toEqual(6);
|
||||
});
|
||||
it('randomSecret: valid output', () => {
|
||||
const data = utils.randomSecret()
|
||||
expect(Array.isArray(data)).toBeTruthy()
|
||||
expect(data.length).toEqual(8)
|
||||
expect(typeof data[0]).toEqual('string')
|
||||
expect(data[0].length).toEqual(6)
|
||||
expect(data[7].length).toEqual(6)
|
||||
})
|
||||
|
||||
it("entropyToSecret", () => {
|
||||
const entropy = Buffer.from("76ebb2d06879b45b7568fb9c1ded097c", "hex");
|
||||
it('entropyToSecret', () => {
|
||||
const entropy = Buffer.from('76ebb2d06879b45b7568fb9c1ded097c', 'hex')
|
||||
const secret = [
|
||||
"304435",
|
||||
"457766",
|
||||
"267453",
|
||||
"461717",
|
||||
"300560",
|
||||
"644127",
|
||||
"076618",
|
||||
"024286",
|
||||
];
|
||||
expect(utils.entropyToSecret(entropy)).toEqual(secret);
|
||||
});
|
||||
'304435',
|
||||
'457766',
|
||||
'267453',
|
||||
'461717',
|
||||
'300560',
|
||||
'644127',
|
||||
'076618',
|
||||
'024286',
|
||||
]
|
||||
expect(utils.entropyToSecret(entropy)).toEqual(secret)
|
||||
})
|
||||
|
||||
it("secretToEntropy", () => {
|
||||
it('secretToEntropy', () => {
|
||||
const secret = [
|
||||
"304435",
|
||||
"457766",
|
||||
"267453",
|
||||
"461717",
|
||||
"300560",
|
||||
"644127",
|
||||
"076618",
|
||||
"024286",
|
||||
];
|
||||
const entropy = Buffer.from("76ebb2d06879b45b7568fb9c1ded097c", "hex");
|
||||
expect(utils.secretToEntropy(secret)).toEqual(entropy);
|
||||
});
|
||||
'304435',
|
||||
'457766',
|
||||
'267453',
|
||||
'461717',
|
||||
'300560',
|
||||
'644127',
|
||||
'076618',
|
||||
'024286',
|
||||
]
|
||||
const entropy = Buffer.from('76ebb2d06879b45b7568fb9c1ded097c', 'hex')
|
||||
expect(utils.secretToEntropy(secret)).toEqual(entropy)
|
||||
})
|
||||
|
||||
it("parseSecretString with spaces valid", () => {
|
||||
it('parseSecretString with spaces valid', () => {
|
||||
const secret = [
|
||||
"304435",
|
||||
"457766",
|
||||
"267453",
|
||||
"461717",
|
||||
"300560",
|
||||
"644127",
|
||||
"076618",
|
||||
"024286",
|
||||
];
|
||||
'304435',
|
||||
'457766',
|
||||
'267453',
|
||||
'461717',
|
||||
'300560',
|
||||
'644127',
|
||||
'076618',
|
||||
'024286',
|
||||
]
|
||||
expect(
|
||||
utils.parseSecretString(
|
||||
"304435 457766 267453 461717 300560 644127 076618 024286"
|
||||
)
|
||||
).toEqual(secret);
|
||||
'304435 457766 267453 461717 300560 644127 076618 024286',
|
||||
),
|
||||
).toEqual(secret)
|
||||
expect(
|
||||
utils.parseSecretString(
|
||||
"304435457766267453461717300560644127076618024286"
|
||||
)
|
||||
).toEqual(secret);
|
||||
'304435457766267453461717300560644127076618024286',
|
||||
),
|
||||
).toEqual(secret)
|
||||
expect(
|
||||
utils.parseSecretString(`
|
||||
304435 457766
|
||||
267453 461717
|
||||
300560 644127
|
||||
076618 024286
|
||||
`)
|
||||
).toEqual(secret);
|
||||
});
|
||||
});
|
||||
`),
|
||||
).toEqual(secret)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user