-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
28 lines (24 loc) · 794 Bytes
/
util.js
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
import algosdk from 'algosdk';
const { generateAccount, secretKeyToMnemonic } = algosdk;
export function genSeed() {
return secretKeyToMnemonic(generateAccount().sk);
}
export function swapWords(seed, leftIdx, rightIdx) {
const nextSeed = [...seed];
if (rightIdx > seed.length - 1)
rightIdx = rightIdx % seed.length;
const [right, left] = [seed[leftIdx], seed[rightIdx]];
nextSeed[leftIdx] = left;
nextSeed[rightIdx] = right;
return nextSeed;
}
export function moveWord(seed, leftIdx, rightIdx) {
const nextSeed = [...seed];
const [word] = nextSeed.splice(leftIdx, 1, '');
if (rightIdx > seed.length - 1)
rightIdx = (rightIdx + 1) % seed.length
if (leftIdx < rightIdx)
rightIdx++;
nextSeed.splice(rightIdx, 0, word);
return nextSeed.filter(Boolean);
}