mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-05-31 05:36:59 +00:00
Create encryption folder and move files
This commit is contained in:
parent
9edb2cf4d4
commit
cec429c691
@ -76,7 +76,7 @@ import {
|
|||||||
groupApi,
|
groupApi,
|
||||||
groupApiSocket,
|
groupApiSocket,
|
||||||
storeWallets,
|
storeWallets,
|
||||||
} from './background';
|
} from './background/background.ts';
|
||||||
import {
|
import {
|
||||||
executeEvent,
|
executeEvent,
|
||||||
subscribeToEvent,
|
subscribeToEvent,
|
||||||
@ -124,7 +124,7 @@ import { Tutorials } from './components/Tutorials/Tutorials';
|
|||||||
import { useHandleTutorials } from './hooks/useHandleTutorials.tsx';
|
import { useHandleTutorials } from './hooks/useHandleTutorials.tsx';
|
||||||
import { useHandleUserInfo } from './hooks/useHandleUserInfo.tsx';
|
import { useHandleUserInfo } from './hooks/useHandleUserInfo.tsx';
|
||||||
import { Minting } from './components/Minting/Minting';
|
import { Minting } from './components/Minting/Minting';
|
||||||
import { isRunningGateway } from './qortalRequests';
|
import { isRunningGateway } from './qortalRequests/qortalRequests.ts';
|
||||||
import { QMailStatus } from './components/QMailStatus';
|
import { QMailStatus } from './components/QMailStatus';
|
||||||
import { GlobalActions } from './components/GlobalActions/GlobalActions';
|
import { GlobalActions } from './components/GlobalActions/GlobalActions';
|
||||||
import { useBlockedAddresses } from './hooks/useBlockUsers.tsx';
|
import { useBlockedAddresses } from './hooks/useBlockUsers.tsx';
|
||||||
|
@ -23,7 +23,11 @@ import { useDropzone } from 'react-dropzone';
|
|||||||
import EditIcon from '@mui/icons-material/Edit';
|
import EditIcon from '@mui/icons-material/Edit';
|
||||||
import { Label } from './components/Group/AddGroup';
|
import { Label } from './components/Group/AddGroup';
|
||||||
import { Spacer } from './common/Spacer';
|
import { Spacer } from './common/Spacer';
|
||||||
import { getWallets, storeWallets, walletVersion } from './background';
|
import {
|
||||||
|
getWallets,
|
||||||
|
storeWallets,
|
||||||
|
walletVersion,
|
||||||
|
} from './background/background.ts';
|
||||||
import { useModal } from './common/useModal';
|
import { useModal } from './common/useModal';
|
||||||
import PhraseWallet from './utils/generateWallet/phrase-wallet';
|
import PhraseWallet from './utils/generateWallet/phrase-wallet';
|
||||||
import { decryptStoredWalletFromSeedPhrase } from './utils/decryptWallet';
|
import { decryptStoredWalletFromSeedPhrase } from './utils/decryptWallet';
|
||||||
|
@ -55,20 +55,20 @@ import {
|
|||||||
setGroupData,
|
setGroupData,
|
||||||
updateThreadActivity,
|
updateThreadActivity,
|
||||||
walletVersion,
|
walletVersion,
|
||||||
} from './background';
|
} from '../background/background.ts';
|
||||||
import {
|
import {
|
||||||
decryptGroupEncryption,
|
decryptGroupEncryption,
|
||||||
encryptAndPublishSymmetricKeyGroupChat,
|
encryptAndPublishSymmetricKeyGroupChat,
|
||||||
encryptAndPublishSymmetricKeyGroupChatForAdmins,
|
encryptAndPublishSymmetricKeyGroupChatForAdmins,
|
||||||
publishGroupEncryptedResource,
|
publishGroupEncryptedResource,
|
||||||
publishOnQDN,
|
publishOnQDN,
|
||||||
} from './backgroundFunctions/encryption';
|
} from '../encryption/encryption.ts';
|
||||||
import { PUBLIC_NOTIFICATION_CODE_FIRST_SECRET_KEY } from './constants/constants';
|
import { PUBLIC_NOTIFICATION_CODE_FIRST_SECRET_KEY } from '../constants/constants';
|
||||||
import Base58 from './deps/Base58';
|
import Base58 from '../encryption/Base58.ts';
|
||||||
import { encryptSingle } from './qdn/encryption/group-encryption';
|
import { encryptSingle } from '../qdn/encryption/group-encryption';
|
||||||
import { _createPoll, _voteOnPoll } from './qortalRequests/get';
|
import { _createPoll, _voteOnPoll } from '../qortalRequests/get';
|
||||||
import { createTransaction } from './transactions/transactions';
|
import { createTransaction } from '../transactions/transactions';
|
||||||
import { getData, storeData } from './utils/chromeStorage';
|
import { getData, storeData } from '../utils/chromeStorage';
|
||||||
|
|
||||||
export function versionCase(request, event) {
|
export function versionCase(request, event) {
|
||||||
event.source.postMessage(
|
event.source.postMessage(
|
@ -1,27 +1,27 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import './qortalRequests';
|
import '../qortalRequests/qortalRequests';
|
||||||
import { isArray } from 'lodash';
|
import { isArray } from 'lodash';
|
||||||
import { uint8ArrayToObject } from './backgroundFunctions/encryption';
|
import { uint8ArrayToObject } from '../encryption/encryption.ts';
|
||||||
import Base58 from './deps/Base58';
|
import Base58 from '../encryption/Base58';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import {
|
import {
|
||||||
base64ToUint8Array,
|
base64ToUint8Array,
|
||||||
decryptSingle,
|
decryptSingle,
|
||||||
encryptSingle,
|
encryptSingle,
|
||||||
objectToBase64,
|
objectToBase64,
|
||||||
} from './qdn/encryption/group-encryption';
|
} from '../qdn/encryption/group-encryption';
|
||||||
import ChatComputePowWorker from './chatComputePow.worker.js?worker';
|
import ChatComputePowWorker from '../chatComputePow.worker.js?worker';
|
||||||
import { reusableGet } from './qdn/publish/pubish';
|
import { reusableGet } from '../qdn/publish/pubish';
|
||||||
import { signChat } from './transactions/signChat';
|
import { signChat } from '../transactions/signChat';
|
||||||
import { createTransaction } from './transactions/transactions';
|
import { createTransaction } from '../transactions/transactions';
|
||||||
import { decryptChatMessage } from './utils/decryptChatMessage';
|
import { decryptChatMessage } from '../utils/decryptChatMessage';
|
||||||
import { decryptStoredWallet } from './utils/decryptWallet';
|
import { decryptStoredWallet } from '../utils/decryptWallet';
|
||||||
import PhraseWallet from './utils/generateWallet/phrase-wallet';
|
import PhraseWallet from '../utils/generateWallet/phrase-wallet';
|
||||||
import { RequestQueueWithPromise } from './utils/queue/queue';
|
import { RequestQueueWithPromise } from '../utils/queue/queue';
|
||||||
import { validateAddress } from './utils/validateAddress';
|
import { validateAddress } from '../utils/validateAddress';
|
||||||
import { Sha256 } from 'asmcrypto.js';
|
import { Sha256 } from 'asmcrypto.js';
|
||||||
import { TradeBotRespondMultipleRequest } from './transactions/TradeBotRespondMultipleRequest';
|
import { TradeBotRespondMultipleRequest } from '../transactions/TradeBotRespondMultipleRequest';
|
||||||
import { RESOURCE_TYPE_NUMBER_GROUP_CHAT_REACTIONS } from './constants/constants';
|
import { RESOURCE_TYPE_NUMBER_GROUP_CHAT_REACTIONS } from '../constants/constants';
|
||||||
import {
|
import {
|
||||||
addDataPublishesCase,
|
addDataPublishesCase,
|
||||||
addEnteredQmailTimestampCase,
|
addEnteredQmailTimestampCase,
|
||||||
@ -68,7 +68,6 @@ import {
|
|||||||
ltcBalanceCase,
|
ltcBalanceCase,
|
||||||
makeAdminCase,
|
makeAdminCase,
|
||||||
nameCase,
|
nameCase,
|
||||||
notificationCase,
|
|
||||||
notifyAdminRegenerateSecretKeyCase,
|
notifyAdminRegenerateSecretKeyCase,
|
||||||
pauseAllQueuesCase,
|
pauseAllQueuesCase,
|
||||||
publishGroupEncryptedResourceCase,
|
publishGroupEncryptedResourceCase,
|
||||||
@ -90,9 +89,13 @@ import {
|
|||||||
validApiCase,
|
validApiCase,
|
||||||
versionCase,
|
versionCase,
|
||||||
voteOnPollCase,
|
voteOnPollCase,
|
||||||
} from './background-cases';
|
} from '../background/background-cases';
|
||||||
import { getData, removeKeysAndLogout, storeData } from './utils/chromeStorage';
|
import {
|
||||||
import TradeBotRespondRequest from './transactions/TradeBotRespondRequest';
|
getData,
|
||||||
|
removeKeysAndLogout,
|
||||||
|
storeData,
|
||||||
|
} from '../utils/chromeStorage';
|
||||||
|
import TradeBotRespondRequest from '../transactions/TradeBotRespondRequest';
|
||||||
|
|
||||||
export let groupSecretkeys = {};
|
export let groupSecretkeys = {};
|
||||||
|
|
@ -22,7 +22,7 @@ import { executeEvent } from '../../utils/events';
|
|||||||
import { useDropzone } from 'react-dropzone';
|
import { useDropzone } from 'react-dropzone';
|
||||||
import { LoadingSnackbar } from '../Snackbar/LoadingSnackbar';
|
import { LoadingSnackbar } from '../Snackbar/LoadingSnackbar';
|
||||||
import { CustomizedSnackbars } from '../Snackbar/Snackbar';
|
import { CustomizedSnackbars } from '../Snackbar/Snackbar';
|
||||||
import { getFee } from '../../background';
|
import { getFee } from '../../background/background.ts';
|
||||||
import { fileToBase64 } from '../../utils/fileReading';
|
import { fileToBase64 } from '../../utils/fileReading';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useSortedMyNames } from '../../hooks/useSortedMyNames';
|
import { useSortedMyNames } from '../../hooks/useSortedMyNames';
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Box, Rating } from '@mui/material';
|
import { Box, Rating } from '@mui/material';
|
||||||
import { useCallback, useContext, useEffect, useRef, useState } from 'react';
|
import { useCallback, useContext, useEffect, useRef, useState } from 'react';
|
||||||
import { getFee } from '../../background';
|
import { getFee } from '../../background/background.ts';
|
||||||
import { QORTAL_APP_CONTEXT, getBaseApiReact } from '../../App';
|
import { QORTAL_APP_CONTEXT, getBaseApiReact } from '../../App';
|
||||||
import { CustomizedSnackbars } from '../Snackbar/Snackbar';
|
import { CustomizedSnackbars } from '../Snackbar/Snackbar';
|
||||||
import { StarFilledIcon } from '../../assets/Icons/StarFilled';
|
import { StarFilledIcon } from '../../assets/Icons/StarFilled';
|
||||||
|
@ -23,7 +23,7 @@ import { QORTAL_APP_CONTEXT, getBaseApiReact } from '../../App';
|
|||||||
import { executeEvent } from '../../utils/events';
|
import { executeEvent } from '../../utils/events';
|
||||||
import { Spacer } from '../../common/Spacer';
|
import { Spacer } from '../../common/Spacer';
|
||||||
import { useModal } from '../../common/useModal';
|
import { useModal } from '../../common/useModal';
|
||||||
import { createEndpoint, isUsingLocal } from '../../background';
|
import { createEndpoint, isUsingLocal } from '../../background/background.ts';
|
||||||
import { Label } from '../Group/AddGroup';
|
import { Label } from '../Group/AddGroup';
|
||||||
import ShortUniqueId from 'short-unique-id';
|
import ShortUniqueId from 'short-unique-id';
|
||||||
import swaggerSVG from '../../assets/svgs/swagger.svg';
|
import swaggerSVG from '../../assets/svgs/swagger.svg';
|
||||||
|
@ -40,7 +40,7 @@ import ImageUploader from '../../common/ImageUploader';
|
|||||||
import { QORTAL_APP_CONTEXT } from '../../App';
|
import { QORTAL_APP_CONTEXT } from '../../App';
|
||||||
import { fileToBase64 } from '../../utils/fileReading';
|
import { fileToBase64 } from '../../utils/fileReading';
|
||||||
import { objectToBase64 } from '../../qdn/encryption/group-encryption';
|
import { objectToBase64 } from '../../qdn/encryption/group-encryption';
|
||||||
import { getFee } from '../../background';
|
import { getFee } from '../../background/background.ts';
|
||||||
import { useAtom } from 'jotai';
|
import { useAtom } from 'jotai';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useSortedMyNames } from '../../hooks/useSortedMyNames';
|
import { useSortedMyNames } from '../../hooks/useSortedMyNames';
|
||||||
|
@ -10,9 +10,9 @@ import {
|
|||||||
getPublishesFromAdmins,
|
getPublishesFromAdmins,
|
||||||
validateSecretKey,
|
validateSecretKey,
|
||||||
} from '../Group/Group';
|
} from '../Group/Group';
|
||||||
import { getFee } from '../../background';
|
import { getFee } from '../../background/background.ts';
|
||||||
import { base64ToUint8Array } from '../../qdn/encryption/group-encryption';
|
import { base64ToUint8Array } from '../../qdn/encryption/group-encryption';
|
||||||
import { uint8ArrayToObject } from '../../backgroundFunctions/encryption';
|
import { uint8ArrayToObject } from '../../encryption/encryption.ts';
|
||||||
import { formatTimestampForum } from '../../utils/time';
|
import { formatTimestampForum } from '../../utils/time';
|
||||||
import { Spacer } from '../../common/Spacer';
|
import { Spacer } from '../../common/Spacer';
|
||||||
import { GroupAvatar } from './GroupAvatar';
|
import { GroupAvatar } from './GroupAvatar';
|
||||||
|
@ -8,7 +8,7 @@ import { Box, CircularProgress, useTheme } from '@mui/material';
|
|||||||
import { objectToBase64 } from '../../qdn/encryption/group-encryption';
|
import { objectToBase64 } from '../../qdn/encryption/group-encryption';
|
||||||
import ShortUniqueId from 'short-unique-id';
|
import ShortUniqueId from 'short-unique-id';
|
||||||
import { LoadingSnackbar } from '../Snackbar/LoadingSnackbar';
|
import { LoadingSnackbar } from '../Snackbar/LoadingSnackbar';
|
||||||
import { getFee } from '../../background';
|
import { getFee } from '../../background/background.ts';
|
||||||
import {
|
import {
|
||||||
decryptPublishes,
|
decryptPublishes,
|
||||||
getTempPublish,
|
getTempPublish,
|
||||||
|
@ -14,7 +14,7 @@ import {
|
|||||||
pauseAllQueues,
|
pauseAllQueues,
|
||||||
resumeAllQueues,
|
resumeAllQueues,
|
||||||
} from '../../App';
|
} from '../../App';
|
||||||
import { getPublicKey } from '../../background';
|
import { getPublicKey } from '../../background/background.ts';
|
||||||
import { useMessageQueue } from '../../MessageQueueContext';
|
import { useMessageQueue } from '../../MessageQueueContext';
|
||||||
import {
|
import {
|
||||||
executeEvent,
|
executeEvent,
|
||||||
|
@ -44,7 +44,7 @@ import ShortUniqueId from 'short-unique-id';
|
|||||||
import { ReplyPreview } from './MessageItem';
|
import { ReplyPreview } from './MessageItem';
|
||||||
import { ExitIcon } from '../../assets/Icons/ExitIcon';
|
import { ExitIcon } from '../../assets/Icons/ExitIcon';
|
||||||
import { RESOURCE_TYPE_NUMBER_GROUP_CHAT_REACTIONS } from '../../constants/constants';
|
import { RESOURCE_TYPE_NUMBER_GROUP_CHAT_REACTIONS } from '../../constants/constants';
|
||||||
import { getFee, isExtMsg } from '../../background';
|
import { getFee, isExtMsg } from '../../background/background.ts';
|
||||||
import AppViewerContainer from '../Apps/AppViewerContainer';
|
import AppViewerContainer from '../Apps/AppViewerContainer';
|
||||||
import CloseIcon from '@mui/icons-material/Close';
|
import CloseIcon from '@mui/icons-material/Close';
|
||||||
import { throttle } from 'lodash';
|
import { throttle } from 'lodash';
|
||||||
|
@ -8,14 +8,14 @@ import {
|
|||||||
getBaseApiReact,
|
getBaseApiReact,
|
||||||
pauseAllQueues,
|
pauseAllQueues,
|
||||||
} from '../../App';
|
} from '../../App';
|
||||||
import { getFee } from '../../background';
|
import { getFee } from '../../background/background.ts';
|
||||||
import {
|
import {
|
||||||
decryptResource,
|
decryptResource,
|
||||||
getGroupAdmins,
|
getGroupAdmins,
|
||||||
validateSecretKey,
|
validateSecretKey,
|
||||||
} from '../Group/Group';
|
} from '../Group/Group';
|
||||||
import { base64ToUint8Array } from '../../qdn/encryption/group-encryption';
|
import { base64ToUint8Array } from '../../qdn/encryption/group-encryption';
|
||||||
import { uint8ArrayToObject } from '../../backgroundFunctions/encryption';
|
import { uint8ArrayToObject } from '../../encryption/encryption.ts';
|
||||||
import { useSetAtom } from 'jotai';
|
import { useSetAtom } from 'jotai';
|
||||||
import { txListAtom } from '../../atoms/global';
|
import { txListAtom } from '../../atoms/global';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
@ -7,7 +7,7 @@ import {
|
|||||||
useRef,
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import { uint8ArrayToObject } from '../../backgroundFunctions/encryption';
|
import { uint8ArrayToObject } from '../../encryption/encryption.ts';
|
||||||
import {
|
import {
|
||||||
base64ToUint8Array,
|
base64ToUint8Array,
|
||||||
objectToBase64,
|
objectToBase64,
|
||||||
@ -15,7 +15,7 @@ import {
|
|||||||
import Tiptap from './TipTap';
|
import Tiptap from './TipTap';
|
||||||
import { CustomButton } from '../../styles/App-styles';
|
import { CustomButton } from '../../styles/App-styles';
|
||||||
import CircularProgress from '@mui/material/CircularProgress';
|
import CircularProgress from '@mui/material/CircularProgress';
|
||||||
import { getFee } from '../../background';
|
import { getFee } from '../../background/background.ts';
|
||||||
import { LoadingSnackbar } from '../Snackbar/LoadingSnackbar';
|
import { LoadingSnackbar } from '../Snackbar/LoadingSnackbar';
|
||||||
import { Box, Typography, useTheme } from '@mui/material';
|
import { Box, Typography, useTheme } from '@mui/material';
|
||||||
import { Spacer } from '../../common/Spacer';
|
import { Spacer } from '../../common/Spacer';
|
||||||
|
@ -16,7 +16,7 @@ import {
|
|||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
import { Spacer } from '../../common/Spacer';
|
import { Spacer } from '../../common/Spacer';
|
||||||
import ImageUploader from '../../common/ImageUploader';
|
import ImageUploader from '../../common/ImageUploader';
|
||||||
import { getFee } from '../../background';
|
import { getFee } from '../../background/background.ts';
|
||||||
import { fileToBase64 } from '../../utils/fileReading';
|
import { fileToBase64 } from '../../utils/fileReading';
|
||||||
import { LoadingButton } from '@mui/lab';
|
import { LoadingButton } from '@mui/lab';
|
||||||
import ErrorIcon from '@mui/icons-material/Error';
|
import ErrorIcon from '@mui/icons-material/Error';
|
||||||
|
@ -16,7 +16,7 @@ import {
|
|||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
import { getNameInfo } from '../Group/Group';
|
import { getNameInfo } from '../Group/Group';
|
||||||
import PollIcon from '@mui/icons-material/Poll';
|
import PollIcon from '@mui/icons-material/Poll';
|
||||||
import { getFee } from '../../background';
|
import { getFee } from '../../background/background.ts';
|
||||||
import RefreshIcon from '@mui/icons-material/Refresh';
|
import RefreshIcon from '@mui/icons-material/Refresh';
|
||||||
import { Spacer } from '../../common/Spacer';
|
import { Spacer } from '../../common/Spacer';
|
||||||
import OpenInNewIcon from '@mui/icons-material/OpenInNew';
|
import OpenInNewIcon from '@mui/icons-material/OpenInNew';
|
||||||
|
@ -12,7 +12,7 @@ import {
|
|||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
import { CustomButtonAccept } from '../../styles/App-styles';
|
import { CustomButtonAccept } from '../../styles/App-styles';
|
||||||
import { getBaseApiReact, QORTAL_APP_CONTEXT } from '../../App';
|
import { getBaseApiReact, QORTAL_APP_CONTEXT } from '../../App';
|
||||||
import { getFee } from '../../background';
|
import { getFee } from '../../background/background.ts';
|
||||||
import { CustomizedSnackbars } from '../Snackbar/Snackbar';
|
import { CustomizedSnackbars } from '../Snackbar/Snackbar';
|
||||||
import { FidgetSpinner } from 'react-loader-spinner';
|
import { FidgetSpinner } from 'react-loader-spinner';
|
||||||
import { useAtom, useSetAtom } from 'jotai';
|
import { useAtom, useSetAtom } from 'jotai';
|
||||||
|
@ -34,7 +34,7 @@ import {
|
|||||||
import { AddGroupList } from './AddGroupList';
|
import { AddGroupList } from './AddGroupList';
|
||||||
import { UserListOfInvites } from './UserListOfInvites';
|
import { UserListOfInvites } from './UserListOfInvites';
|
||||||
import { CustomizedSnackbars } from '../Snackbar/Snackbar';
|
import { CustomizedSnackbars } from '../Snackbar/Snackbar';
|
||||||
import { getFee } from '../../background';
|
import { getFee } from '../../background/background.ts';
|
||||||
import { QORTAL_APP_CONTEXT } from '../../App';
|
import { QORTAL_APP_CONTEXT } from '../../App';
|
||||||
import { subscribeToEvent, unsubscribeFromEvent } from '../../utils/events';
|
import { subscribeToEvent, unsubscribeFromEvent } from '../../utils/events';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
@ -25,7 +25,7 @@ import {
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { QORTAL_APP_CONTEXT, getBaseApiReact } from '../../App';
|
import { QORTAL_APP_CONTEXT, getBaseApiReact } from '../../App';
|
||||||
import { LoadingButton } from '@mui/lab';
|
import { LoadingButton } from '@mui/lab';
|
||||||
import { getFee } from '../../background';
|
import { getFee } from '../../background/background.ts';
|
||||||
import LockIcon from '@mui/icons-material/Lock';
|
import LockIcon from '@mui/icons-material/Lock';
|
||||||
import NoEncryptionGmailerrorredIcon from '@mui/icons-material/NoEncryptionGmailerrorred';
|
import NoEncryptionGmailerrorredIcon from '@mui/icons-material/NoEncryptionGmailerrorred';
|
||||||
import { Spacer } from '../../common/Spacer';
|
import { Spacer } from '../../common/Spacer';
|
||||||
|
@ -22,7 +22,7 @@ import {
|
|||||||
pauseAllQueues,
|
pauseAllQueues,
|
||||||
resumeAllQueues,
|
resumeAllQueues,
|
||||||
} from '../../../App';
|
} from '../../../App';
|
||||||
import { getFee } from '../../../background';
|
import { getFee } from '../../../background/background';
|
||||||
import TipTap from '../../Chat/TipTap';
|
import TipTap from '../../Chat/TipTap';
|
||||||
import { MessageDisplay } from '../../Chat/MessageDisplay';
|
import { MessageDisplay } from '../../Chat/MessageDisplay';
|
||||||
import { CustomizedSnackbars } from '../../Snackbar/Snackbar';
|
import { CustomizedSnackbars } from '../../Snackbar/Snackbar';
|
||||||
|
@ -13,7 +13,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|||||||
import { ChatGroup } from '../Chat/ChatGroup';
|
import { ChatGroup } from '../Chat/ChatGroup';
|
||||||
import { CreateCommonSecret } from '../Chat/CreateCommonSecret';
|
import { CreateCommonSecret } from '../Chat/CreateCommonSecret';
|
||||||
import { base64ToUint8Array } from '../../qdn/encryption/group-encryption';
|
import { base64ToUint8Array } from '../../qdn/encryption/group-encryption';
|
||||||
import { uint8ArrayToObject } from '../../backgroundFunctions/encryption';
|
import { uint8ArrayToObject } from '../../encryption/encryption';
|
||||||
import { AddGroup } from './AddGroup';
|
import { AddGroup } from './AddGroup';
|
||||||
import CreateIcon from '@mui/icons-material/Create';
|
import CreateIcon from '@mui/icons-material/Create';
|
||||||
import {
|
import {
|
||||||
|
@ -3,7 +3,7 @@ import { Box, Input, MenuItem, Select, SelectChangeEvent } from '@mui/material';
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Spacer } from '../../common/Spacer';
|
import { Spacer } from '../../common/Spacer';
|
||||||
import { Label } from './AddGroup';
|
import { Label } from './AddGroup';
|
||||||
import { getFee } from '../../background';
|
import { getFee } from '../../background/background.ts';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
export const InviteMember = ({ groupId, setInfoSnack, setOpenSnack, show }) => {
|
export const InviteMember = ({ groupId, setInfoSnack, setOpenSnack, show }) => {
|
||||||
|
@ -15,7 +15,7 @@ import {
|
|||||||
List,
|
List,
|
||||||
} from 'react-virtualized';
|
} from 'react-virtualized';
|
||||||
import { getNameInfo } from './Group';
|
import { getNameInfo } from './Group';
|
||||||
import { getFee } from '../../background';
|
import { getFee } from '../../background/background.ts';
|
||||||
import { LoadingButton } from '@mui/lab';
|
import { LoadingButton } from '@mui/lab';
|
||||||
import { getBaseApiReact } from '../../App';
|
import { getBaseApiReact } from '../../App';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
@ -42,7 +42,7 @@ import { useVirtualizer } from '@tanstack/react-virtual';
|
|||||||
import ErrorBoundary from '../../common/ErrorBoundary';
|
import ErrorBoundary from '../../common/ErrorBoundary';
|
||||||
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
||||||
import ExpandLessIcon from '@mui/icons-material/ExpandLess';
|
import ExpandLessIcon from '@mui/icons-material/ExpandLess';
|
||||||
import { getFee } from '../../background';
|
import { getFee } from '../../background/background.ts';
|
||||||
import { useAtom, useSetAtom } from 'jotai';
|
import { useAtom, useSetAtom } from 'jotai';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ import {
|
|||||||
List,
|
List,
|
||||||
} from 'react-virtualized';
|
} from 'react-virtualized';
|
||||||
import { getNameInfo } from './Group';
|
import { getNameInfo } from './Group';
|
||||||
import { getFee } from '../../background';
|
import { getFee } from '../../background/background.ts';
|
||||||
import { LoadingButton } from '@mui/lab';
|
import { LoadingButton } from '@mui/lab';
|
||||||
import { getBaseApiReact } from '../../App';
|
import { getBaseApiReact } from '../../App';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
@ -15,7 +15,7 @@ import {
|
|||||||
List,
|
List,
|
||||||
} from 'react-virtualized';
|
} from 'react-virtualized';
|
||||||
import { getNameInfo } from './Group';
|
import { getNameInfo } from './Group';
|
||||||
import { getFee } from '../../background';
|
import { getFee } from '../../background/background.ts';
|
||||||
import { LoadingButton } from '@mui/lab';
|
import { LoadingButton } from '@mui/lab';
|
||||||
import { getBaseApiReact } from '../../App';
|
import { getBaseApiReact } from '../../App';
|
||||||
import { txListAtom } from '../../atoms/global';
|
import { txListAtom } from '../../atoms/global';
|
||||||
|
@ -17,7 +17,7 @@ import {
|
|||||||
List,
|
List,
|
||||||
} from 'react-virtualized';
|
} from 'react-virtualized';
|
||||||
import { LoadingButton } from '@mui/lab';
|
import { LoadingButton } from '@mui/lab';
|
||||||
import { getFee } from '../../background';
|
import { getFee } from '../../background/background.ts';
|
||||||
import { getBaseApiReact } from '../../App';
|
import { getBaseApiReact } from '../../App';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ import { CustomizedSnackbars } from '../Snackbar/Snackbar';
|
|||||||
import { QORTAL_APP_CONTEXT, getBaseApiReact } from '../../App';
|
import { QORTAL_APP_CONTEXT, getBaseApiReact } from '../../App';
|
||||||
import { getGroupMembers, getNames } from './Group';
|
import { getGroupMembers, getNames } from './Group';
|
||||||
import { LoadingSnackbar } from '../Snackbar/LoadingSnackbar';
|
import { LoadingSnackbar } from '../Snackbar/LoadingSnackbar';
|
||||||
import { getFee } from '../../background';
|
import { getFee } from '../../background/background.ts';
|
||||||
import { LoadingButton } from '@mui/lab';
|
import { LoadingButton } from '@mui/lab';
|
||||||
import { subscribeToEvent, unsubscribeFromEvent } from '../../utils/events';
|
import { subscribeToEvent, unsubscribeFromEvent } from '../../utils/events';
|
||||||
import { Spacer } from '../../common/Spacer';
|
import { Spacer } from '../../common/Spacer';
|
||||||
|
@ -36,8 +36,8 @@ import { useAtom } from 'jotai';
|
|||||||
import { decryptStoredWallet } from '../../utils/decryptWallet';
|
import { decryptStoredWallet } from '../../utils/decryptWallet';
|
||||||
import { Spacer } from '../../common/Spacer';
|
import { Spacer } from '../../common/Spacer';
|
||||||
import PhraseWallet from '../../utils/generateWallet/phrase-wallet';
|
import PhraseWallet from '../../utils/generateWallet/phrase-wallet';
|
||||||
import { walletVersion } from '../../background';
|
import { walletVersion } from '../../background/background.ts';
|
||||||
import Base58 from '../../deps/Base58';
|
import Base58 from '../../encryption/Base58.ts';
|
||||||
import { QORTAL_APP_CONTEXT } from '../../App';
|
import { QORTAL_APP_CONTEXT } from '../../App';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ import {
|
|||||||
} from 'react-virtualized';
|
} from 'react-virtualized';
|
||||||
import { QORTAL_APP_CONTEXT, getBaseApiReact } from '../../App';
|
import { QORTAL_APP_CONTEXT, getBaseApiReact } from '../../App';
|
||||||
import { LoadingButton } from '@mui/lab';
|
import { LoadingButton } from '@mui/lab';
|
||||||
import { getFee } from '../../background';
|
import { getFee } from '../../background/background.ts';
|
||||||
import LockIcon from '@mui/icons-material/Lock';
|
import LockIcon from '@mui/icons-material/Lock';
|
||||||
import NoEncryptionGmailerrorredIcon from '@mui/icons-material/NoEncryptionGmailerrorred';
|
import NoEncryptionGmailerrorredIcon from '@mui/icons-material/NoEncryptionGmailerrorred';
|
||||||
import { Spacer } from '../../common/Spacer';
|
import { Spacer } from '../../common/Spacer';
|
||||||
|
@ -16,7 +16,7 @@ import {
|
|||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
import { Spacer } from '../common/Spacer';
|
import { Spacer } from '../common/Spacer';
|
||||||
import ImageUploader from '../common/ImageUploader';
|
import ImageUploader from '../common/ImageUploader';
|
||||||
import { getFee } from '../background';
|
import { getFee } from '../background/background.ts';
|
||||||
import { fileToBase64 } from '../utils/fileReading';
|
import { fileToBase64 } from '../utils/fileReading';
|
||||||
import { LoadingButton } from '@mui/lab';
|
import { LoadingButton } from '@mui/lab';
|
||||||
import ErrorIcon from '@mui/icons-material/Error';
|
import ErrorIcon from '@mui/icons-material/Error';
|
||||||
|
@ -21,7 +21,7 @@ import {
|
|||||||
subscribeToEvent,
|
subscribeToEvent,
|
||||||
unsubscribeFromEvent,
|
unsubscribeFromEvent,
|
||||||
} from '../../utils/events';
|
} from '../../utils/events';
|
||||||
import { getFee } from '../../background';
|
import { getFee } from '../../background/background.ts';
|
||||||
import { Spacer } from '../../common/Spacer';
|
import { Spacer } from '../../common/Spacer';
|
||||||
import { FidgetSpinner } from 'react-loader-spinner';
|
import { FidgetSpinner } from 'react-loader-spinner';
|
||||||
import { useModal } from '../../common/useModal';
|
import { useModal } from '../../common/useModal';
|
||||||
|
@ -27,7 +27,7 @@ import {
|
|||||||
import Logo1Dark from '../assets/svgs/Logo1Dark.svg';
|
import Logo1Dark from '../assets/svgs/Logo1Dark.svg';
|
||||||
import HelpIcon from '@mui/icons-material/Help';
|
import HelpIcon from '@mui/icons-material/Help';
|
||||||
import { CustomizedSnackbars } from './Snackbar/Snackbar';
|
import { CustomizedSnackbars } from './Snackbar/Snackbar';
|
||||||
import { cleanUrl, gateways } from '../background';
|
import { cleanUrl, gateways } from '../background/background.ts';
|
||||||
import Tooltip, { TooltipProps, tooltipClasses } from '@mui/material/Tooltip';
|
import Tooltip, { TooltipProps, tooltipClasses } from '@mui/material/Tooltip';
|
||||||
import ThemeSelector from './Theme/ThemeSelector';
|
import ThemeSelector from './Theme/ThemeSelector';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
@ -2,7 +2,7 @@ import { Box, useTheme } from '@mui/material';
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { TextP } from '../styles/App-styles';
|
import { TextP } from '../styles/App-styles';
|
||||||
import { Spacer } from '../common/Spacer';
|
import { Spacer } from '../common/Spacer';
|
||||||
import { getFee } from '../background';
|
import { getFee } from '../background/background.ts';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
export const QortPayment = ({ balance, show, onSuccess, defaultPaymentTo }) => {
|
export const QortPayment = ({ balance, show, onSuccess, defaultPaymentTo }) => {
|
||||||
|
@ -17,7 +17,7 @@ import {
|
|||||||
import { Label } from './Group/AddGroup';
|
import { Label } from './Group/AddGroup';
|
||||||
import { Spacer } from '../common/Spacer';
|
import { Spacer } from '../common/Spacer';
|
||||||
import { getBaseApiReact } from '../App';
|
import { getBaseApiReact } from '../App';
|
||||||
import { getFee } from '../background';
|
import { getFee } from '../background/background.ts';
|
||||||
import RadioButtonCheckedIcon from '@mui/icons-material/RadioButtonChecked';
|
import RadioButtonCheckedIcon from '@mui/icons-material/RadioButtonChecked';
|
||||||
import { subscribeToEvent, unsubscribeFromEvent } from '../utils/events';
|
import { subscribeToEvent, unsubscribeFromEvent } from '../utils/events';
|
||||||
import { BarSpinner } from '../common/Spinners/BarSpinner/BarSpinner';
|
import { BarSpinner } from '../common/Spinners/BarSpinner/BarSpinner';
|
||||||
|
@ -19,7 +19,7 @@ import {
|
|||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
import { objectToBase64 } from '../../qdn/encryption/group-encryption';
|
import { objectToBase64 } from '../../qdn/encryption/group-encryption';
|
||||||
import { QORTAL_APP_CONTEXT } from '../../App';
|
import { QORTAL_APP_CONTEXT } from '../../App';
|
||||||
import { getFee } from '../../background';
|
import { getFee } from '../../background/background.ts';
|
||||||
import { CustomizedSnackbars } from '../Snackbar/Snackbar';
|
import { CustomizedSnackbars } from '../Snackbar/Snackbar';
|
||||||
import { SaveIcon } from '../../assets/Icons/SaveIcon';
|
import { SaveIcon } from '../../assets/Icons/SaveIcon';
|
||||||
import { IconWrapper } from '../Desktop/DesktopFooter';
|
import { IconWrapper } from '../Desktop/DesktopFooter';
|
||||||
@ -31,7 +31,7 @@ import { saveFileToDiskGeneric } from '../../utils/generateWallet/generateWallet
|
|||||||
import {
|
import {
|
||||||
base64ToUint8Array,
|
base64ToUint8Array,
|
||||||
uint8ArrayToObject,
|
uint8ArrayToObject,
|
||||||
} from '../../backgroundFunctions/encryption';
|
} from '../../encryption/encryption.ts';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useAtom, useSetAtom } from 'jotai';
|
import { useAtom, useSetAtom } from 'jotai';
|
||||||
|
|
||||||
|
@ -19,7 +19,10 @@ import {
|
|||||||
useTheme,
|
useTheme,
|
||||||
Autocomplete,
|
Autocomplete,
|
||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
import { getAddressInfo, getNameOrAddress } from '../../background';
|
import {
|
||||||
|
getAddressInfo,
|
||||||
|
getNameOrAddress,
|
||||||
|
} from '../../background/background.ts';
|
||||||
import { getBaseApiReact } from '../../App';
|
import { getBaseApiReact } from '../../App';
|
||||||
import { getNameInfo } from '../Group/Group';
|
import { getNameInfo } from '../Group/Group';
|
||||||
import AccountCircleIcon from '@mui/icons-material/AccountCircle';
|
import AccountCircleIcon from '@mui/icons-material/AccountCircle';
|
||||||
|
@ -1,864 +0,0 @@
|
|||||||
// @ts-nocheck
|
|
||||||
;
|
|
||||||
import Base58 from '../deps/Base58.js'
|
|
||||||
import {Sha256, Sha512} from 'asmcrypto.js'
|
|
||||||
import jsSHA from 'jssha'
|
|
||||||
import RIPEMD160 from '../deps/ripemd160.js'
|
|
||||||
import utils from '../utils/utils'
|
|
||||||
import {BigInteger, EllipticCurve} from './ecbn'
|
|
||||||
import {Buffer} from 'buffer'
|
|
||||||
|
|
||||||
export default class AltcoinHDWallet {
|
|
||||||
|
|
||||||
constructor(addressParams) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Seed - 32 bytes
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.seed = new Uint8Array(32)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Version Bytes - 4 byte
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.versionBytes = addressParams
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Depth - 1 byte
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.depth = 0
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parent Fingerprint - 4 bytes
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.parentFingerprint = '0x00000000' // master key
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Child Index - 4 bytes
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.childIndex = '0x00000000' // master key
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Chain Code - 32 bytes
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.chainCode = new Uint8Array(32)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Key Data - 33 bytes
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.keyData = new Uint8Array(33)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Seed Hash - 64 bytes
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.seedHash = new Uint8Array(64)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Private Key - 32 bytes
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.privateKey = new Uint8Array(32)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Public Key - 33 bytes (compressed)
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.publicKey = new Uint8Array(33)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Public Key Hash160 (used to derive the parent fingerprint for derived)
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.publicKeyHash = new Uint8Array(20)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Master Private Key (Base58 encoded)
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.masterPrivateKey = ''
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Master Public Key (Base58 encoded)
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.masterPublicKey = ''
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Testnet Master Private Key (Base58 encoded) - THIS IS TESTNET
|
|
||||||
*/
|
|
||||||
|
|
||||||
this._tMasterPrivateKey = ''
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Testnet Master Public Key (Base58 encoded) - THIS IS TESTNET
|
|
||||||
*/
|
|
||||||
|
|
||||||
this._tmasterPublicKey = ''
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Child Keys Derivation from the Parent Keys
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Child Private Key - 32 bytes
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.childPrivateKey = new Uint8Array(32)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Child Chain Code - 32 bytes
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.childChainCode = new Uint8Array(32)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Child Public Key - 33 bytes (compressed)
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.childPublicKey = new Uint8Array(33)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Child Public Key Hash160 (used to derive the parent fingerprint for derived)
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.childPublicKeyHash = new Uint8Array(20)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extended Private Child Key - Base58 encoded
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.xPrivateChildKey = ''
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extended Public Child Key - Base58 encoded
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.xPublicChildKey = ''
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Grand Child Keys Derivation from the Child Keys
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Grand Child Private Key - 32 bytes
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.grandChildPrivateKey = new Uint8Array(32)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Grand Child Chain Code - 32 bytes
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.grandChildChainCode = new Uint8Array(32)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Grand Child Public Key - 33 bytes (compressed)
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.grandChildPublicKey = new Uint8Array(33)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Grand Public Key Hash160 (used to derive the parent fingerprint for derived)
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.grandChildPublicKeyHash = new Uint8Array(20)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extended Private Grand Child Key - Base58 encoded
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.xPrivateGrandChildKey = ''
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extended Public Grand Child Key - Base58 encoded
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.xPublicGrandChildKey = ''
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Litecoin Legacy Address - Derived from the Grand Child Public Key Hash
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.litecoinLegacyAddress = ''
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TESTNET Litecoin Legacy Address (Derived from the Grand Child Public Key Hash) - THIS IS TESTNET
|
|
||||||
*/
|
|
||||||
|
|
||||||
this._tlitecoinLegacyAddress = ''
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wallet - Wallet Object (keys...)
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.wallet = {}
|
|
||||||
}
|
|
||||||
|
|
||||||
setSeed(seed) {
|
|
||||||
this.seed = seed
|
|
||||||
}
|
|
||||||
|
|
||||||
createWallet(seed, isBIP44, indicator = null) {
|
|
||||||
|
|
||||||
// Set Seeed
|
|
||||||
this.setSeed(seed)
|
|
||||||
|
|
||||||
// Generate Seed Hash
|
|
||||||
this.generateSeedHash(this.seed, isBIP44, indicator)
|
|
||||||
|
|
||||||
// Generate Private Key
|
|
||||||
this.generatePrivateKey(this.seedHash)
|
|
||||||
|
|
||||||
// Generate Chain Code
|
|
||||||
this.generateChainCode(this.seedHash)
|
|
||||||
|
|
||||||
// Generate Public Key from Private Key
|
|
||||||
this.generatePublicKey(this.privateKey)
|
|
||||||
|
|
||||||
// Generate Mainnet Master Private Key
|
|
||||||
this.generateMainnetMasterPrivateKey()
|
|
||||||
|
|
||||||
// Generate Mainnet Master Public Key
|
|
||||||
this.generateMainnetMasterPublicKey()
|
|
||||||
|
|
||||||
// Generate Testnet Master Private Key
|
|
||||||
this.generateTestnetMasterPrivateKey()
|
|
||||||
|
|
||||||
// Generate Testnet Master Public Key
|
|
||||||
this.generateTestnetMasterPublicKey()
|
|
||||||
|
|
||||||
// Generate Child and Grand Child Keys
|
|
||||||
this.generateDerivedChildKeys()
|
|
||||||
|
|
||||||
// Return Wallet Object Specification
|
|
||||||
return this.returnWallet()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
generateSeedHash(seed, isBIP44, indicator = null) {
|
|
||||||
let buffer
|
|
||||||
|
|
||||||
if (isBIP44) {
|
|
||||||
buffer = utils.appendBuffer(seed.reverse(), utils.int32ToBytes(indicator))
|
|
||||||
} else {
|
|
||||||
if(indicator !== null) {
|
|
||||||
const indicatorString = utils.stringtoUTF8Array(indicator)
|
|
||||||
buffer = utils.appendBuffer(seed.reverse(), indicatorString)
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
buffer = seed.reverse()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const _reverseSeedHash = new Sha256().process(buffer).finish().result
|
|
||||||
this.seedHash = new Sha512().process(utils.appendBuffer(seed, _reverseSeedHash)).finish().result
|
|
||||||
}
|
|
||||||
|
|
||||||
generatePrivateKey(seedHash) {
|
|
||||||
const SECP256K1_CURVE_ORDER = new BigInteger("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141")
|
|
||||||
|
|
||||||
const privateKeyHash = seedHash.slice(0, 32)
|
|
||||||
|
|
||||||
this.seed58 = Base58.encode(privateKeyHash)
|
|
||||||
|
|
||||||
const _privateKeyHash = [...privateKeyHash]
|
|
||||||
let privateKeyBigInt = BigInteger.fromByteArrayUnsigned(_privateKeyHash)
|
|
||||||
|
|
||||||
const privateKey = (privateKeyBigInt.mod(SECP256K1_CURVE_ORDER.subtract(BigInteger.ONE))).add(BigInteger.ONE)
|
|
||||||
this.privateKey = privateKey.toByteArrayUnsigned()
|
|
||||||
}
|
|
||||||
|
|
||||||
generateChainCode(seedHash) {
|
|
||||||
this.chainCode = new Sha256().process(seedHash.slice(32, 64)).finish().result
|
|
||||||
}
|
|
||||||
|
|
||||||
generatePublicKey(privateKey) {
|
|
||||||
const _privateKey = [...privateKey]
|
|
||||||
const privateKeyBigInt = BigInteger.fromByteArrayUnsigned(_privateKey)
|
|
||||||
|
|
||||||
const epCurve = EllipticCurve.getSECCurveByName("secp256k1")
|
|
||||||
const curvePoints = epCurve.getG().multiply(privateKeyBigInt)
|
|
||||||
|
|
||||||
|
|
||||||
const x = curvePoints.getX().toBigInteger()
|
|
||||||
const y = curvePoints.getY().toBigInteger()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deriving Uncompressed Public Key (65 bytes)
|
|
||||||
*
|
|
||||||
* const publicKeyBytes = EllipticCurve.integerToBytes(x, 32)
|
|
||||||
* this.publicKey = publicKeyBytes.concat(EllipticCurve.integerToBytes(y, 32))
|
|
||||||
* this.publicKey.unshift(0x04) // append point indicator
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Compressed Public Key (33 bytes)
|
|
||||||
this.publicKey = EllipticCurve.integerToBytes(x, 32)
|
|
||||||
|
|
||||||
|
|
||||||
if (y.isEven()) {
|
|
||||||
this.publicKey.unshift(0x02) // append point indicator
|
|
||||||
} else {
|
|
||||||
this.publicKey.unshift(0x03) // append point indicator
|
|
||||||
}
|
|
||||||
|
|
||||||
// PublicKey Hash
|
|
||||||
const publicKeySHA256 = new Sha256().process(new Uint8Array(this.publicKey)).finish().result
|
|
||||||
const _publicKeyHash = new RIPEMD160().update(Buffer.from(publicKeySHA256)).digest('hex')
|
|
||||||
this.publicKeyHash = _publicKeyHash
|
|
||||||
}
|
|
||||||
|
|
||||||
generateMainnetMasterPrivateKey() {
|
|
||||||
// Serialization Variable
|
|
||||||
const s = []
|
|
||||||
|
|
||||||
// Append Version Byte
|
|
||||||
s.push(...(utils.int32ToBytes(this.versionBytes.mainnet.private)))
|
|
||||||
|
|
||||||
// Append Depth
|
|
||||||
s.push(this.depth)
|
|
||||||
|
|
||||||
// Append Parent Fingerprint
|
|
||||||
s.push(...(utils.int32ToBytes(this.parentFingerprint)))
|
|
||||||
|
|
||||||
// Append Child Number
|
|
||||||
s.push(...(utils.int32ToBytes(this.childIndex)))
|
|
||||||
|
|
||||||
// Append Chain Code
|
|
||||||
s.push(...this.chainCode)
|
|
||||||
|
|
||||||
// Append 1 byte '0x00' (to make the key data 33 bytes, DO THIS ONLY FOR PRIVATE KEYS )
|
|
||||||
s.push(0)
|
|
||||||
|
|
||||||
//if the private key length is less than 32 let's add leading zeros
|
|
||||||
if(this.privateKey.length<32){
|
|
||||||
for(let i=this.privateKey.length;i<32;i++){
|
|
||||||
s.push(0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Append Private Key
|
|
||||||
s.push(...this.privateKey)
|
|
||||||
|
|
||||||
// Generate CheckSum
|
|
||||||
const _s = new Uint8Array(s)
|
|
||||||
const _checkSum = new Sha256().process(new Sha256().process(_s).finish().result).finish().result
|
|
||||||
const checkSum = _checkSum.slice(0, 4)
|
|
||||||
|
|
||||||
// Append CheckSum
|
|
||||||
s.push(...checkSum) // And this brings us to the end of the serialization...
|
|
||||||
|
|
||||||
// Save to Private Key as Base58 encoded
|
|
||||||
this.masterPrivateKey = Base58.encode(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
generateMainnetMasterPublicKey() {
|
|
||||||
// Serialization Variable
|
|
||||||
const s = []
|
|
||||||
|
|
||||||
// Append Version Byte
|
|
||||||
s.push(...(utils.int32ToBytes(this.versionBytes.mainnet.public)))
|
|
||||||
|
|
||||||
// Append Depth
|
|
||||||
s.push(this.depth)
|
|
||||||
|
|
||||||
// Append Parent Fingerprint
|
|
||||||
s.push(...(utils.int32ToBytes(this.parentFingerprint)))
|
|
||||||
|
|
||||||
// Append Child Number
|
|
||||||
s.push(...(utils.int32ToBytes(this.childIndex)))
|
|
||||||
|
|
||||||
// Append Chain Code
|
|
||||||
s.push(...this.chainCode)
|
|
||||||
|
|
||||||
// Append Public Key
|
|
||||||
s.push(...this.publicKey)
|
|
||||||
|
|
||||||
// Generate CheckSum
|
|
||||||
const _s = new Uint8Array(s)
|
|
||||||
const _checkSum = new Sha256().process(new Sha256().process(_s).finish().result).finish().result
|
|
||||||
const checkSum = _checkSum.slice(0, 4)
|
|
||||||
|
|
||||||
// Append CheckSum
|
|
||||||
s.push(...checkSum) // And this brings us to the end of the serialization...
|
|
||||||
|
|
||||||
// Save to Public Key as Base58 encoded
|
|
||||||
this.masterPublicKey = Base58.encode(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
generateTestnetMasterPrivateKey() {
|
|
||||||
|
|
||||||
// To be Used ONLY in Testnet...
|
|
||||||
|
|
||||||
// Serialization Variable
|
|
||||||
const s = []
|
|
||||||
|
|
||||||
// Append Version Byte
|
|
||||||
s.push(...(utils.int32ToBytes(this.versionBytes.testnet.private)))
|
|
||||||
|
|
||||||
// Append Depth
|
|
||||||
s.push(this.depth)
|
|
||||||
|
|
||||||
// Append Parent Fingerprint
|
|
||||||
s.push(...(utils.int32ToBytes(this.parentFingerprint)))
|
|
||||||
|
|
||||||
// Append Child Number
|
|
||||||
s.push(...(utils.int32ToBytes(this.childIndex)))
|
|
||||||
|
|
||||||
// Append Chain Code
|
|
||||||
s.push(...this.chainCode)
|
|
||||||
|
|
||||||
// Append 1 byte '0x00' (to make the key data 33 bytes, DO THIS ONLY FOR PRIVATE KEYS )
|
|
||||||
s.push(0)
|
|
||||||
|
|
||||||
// Append Private Key
|
|
||||||
s.push(...this.privateKey)
|
|
||||||
|
|
||||||
// Generate CheckSum
|
|
||||||
const _s = new Uint8Array(s)
|
|
||||||
const _checkSum = new Sha256().process(new Sha256().process(_s).finish().result).finish().result
|
|
||||||
const checkSum = _checkSum.slice(0, 4)
|
|
||||||
|
|
||||||
// Append CheckSum
|
|
||||||
s.push(...checkSum) // And this brings us to the end of the serialization...
|
|
||||||
|
|
||||||
// Save to Private Key as Base58 encoded
|
|
||||||
this._tMasterPrivateKey = Base58.encode(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
generateTestnetMasterPublicKey() {
|
|
||||||
|
|
||||||
// To be Used ONLY in Testnet...
|
|
||||||
|
|
||||||
// Serialization Variable
|
|
||||||
const s = []
|
|
||||||
|
|
||||||
// Append Version Byte
|
|
||||||
s.push(...(utils.int32ToBytes(this.versionBytes.testnet.public)))
|
|
||||||
|
|
||||||
// Append Depth
|
|
||||||
s.push(this.depth)
|
|
||||||
|
|
||||||
// Append Parent Fingerprint
|
|
||||||
s.push(...(utils.int32ToBytes(this.parentFingerprint)))
|
|
||||||
|
|
||||||
// Append Child Number
|
|
||||||
s.push(...(utils.int32ToBytes(this.childIndex)))
|
|
||||||
|
|
||||||
// Append Chain Code
|
|
||||||
s.push(...this.chainCode)
|
|
||||||
|
|
||||||
// Append Private Key
|
|
||||||
s.push(...this.publicKey)
|
|
||||||
|
|
||||||
// Generate CheckSum
|
|
||||||
const _s = new Uint8Array(s)
|
|
||||||
const _checkSum = new Sha256().process(new Sha256().process(_s).finish().result).finish().result
|
|
||||||
const checkSum = _checkSum.slice(0, 4)
|
|
||||||
|
|
||||||
// Append CheckSum
|
|
||||||
s.push(...checkSum) // And this brings us to the end of the serialization...
|
|
||||||
|
|
||||||
// Save to Private Key as Base58 encoded
|
|
||||||
this._tmasterPublicKey = Base58.encode(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
generateDerivedChildKeys() {
|
|
||||||
|
|
||||||
// SPEC INFO: https://en.bitcoin.it/wiki/BIP_0032#Child_key_derivation_.28CKD.29_functions
|
|
||||||
// NOTE: will not be using some of derivations func as the value is known. (So I'd rather shove in the values and rewrite out the derivations later ?)
|
|
||||||
|
|
||||||
// NOTE: I "re-wrote" and "reduplicate" the code for child and grandChild keys derivations inorder to get the child and grandchild from the child
|
|
||||||
// TODO: Make this more better in the future
|
|
||||||
|
|
||||||
const path = 'm/0/0'
|
|
||||||
// let p = path.split('/')
|
|
||||||
|
|
||||||
// Get Public kEY
|
|
||||||
const derivePublicChildKey = () => {
|
|
||||||
|
|
||||||
const _privateKey = [...this.childPrivateKey]
|
|
||||||
const privateKeyBigInt = BigInteger.fromByteArrayUnsigned(_privateKey)
|
|
||||||
|
|
||||||
const epCurve = EllipticCurve.getSECCurveByName("secp256k1")
|
|
||||||
const curvePoints = epCurve.getG().multiply(privateKeyBigInt)
|
|
||||||
|
|
||||||
const x = curvePoints.getX().toBigInteger()
|
|
||||||
const y = curvePoints.getY().toBigInteger()
|
|
||||||
|
|
||||||
// Compressed Public Key (33 bytes)
|
|
||||||
this.childPublicKey = EllipticCurve.integerToBytes(x, 32)
|
|
||||||
|
|
||||||
|
|
||||||
if (y.isEven()) {
|
|
||||||
|
|
||||||
this.childPublicKey.unshift(0x02) // append point indicator
|
|
||||||
} else {
|
|
||||||
|
|
||||||
this.childPublicKey.unshift(0x03) // append point indicator
|
|
||||||
}
|
|
||||||
|
|
||||||
// PublicKey Hash
|
|
||||||
const childPublicKeySHA256 = new Sha256().process(new Uint8Array(this.childPublicKey)).finish().result
|
|
||||||
const _childPublicKeyHash = new RIPEMD160().update(Buffer.from(childPublicKeySHA256)).digest('hex')
|
|
||||||
this.childPublicKeyHash = _childPublicKeyHash
|
|
||||||
|
|
||||||
|
|
||||||
// Call deriveExtendedPublicChildKey // WIll be hardcoding the values...
|
|
||||||
deriveExtendedPublicChildKey(1, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
const derivePrivateChildKey = (cI) => {
|
|
||||||
|
|
||||||
let ib = []
|
|
||||||
ib.push((cI >> 24) & 0xff)
|
|
||||||
ib.push((cI >> 16) & 0xff)
|
|
||||||
ib.push((cI >> 8) & 0xff)
|
|
||||||
ib.push(cI & 0xff)
|
|
||||||
|
|
||||||
const s = [...this.publicKey].concat(ib)
|
|
||||||
|
|
||||||
const _hmacSha512 = new jsSHA("SHA-512", "UINT8ARRAY", { numRounds: 1, hmacKey: { value: this.chainCode, format: "UINT8ARRAY" } })
|
|
||||||
_hmacSha512.update(new Uint8Array(s))
|
|
||||||
|
|
||||||
|
|
||||||
const IL = BigInteger.fromByteArrayUnsigned([..._hmacSha512.getHMAC('UINT8ARRAY').slice(0, 32)])
|
|
||||||
this.childChainCode = _hmacSha512.getHMAC('UINT8ARRAY').slice(32, 64) // IR according to the SPEC
|
|
||||||
|
|
||||||
|
|
||||||
// SECP256k1 init
|
|
||||||
const epCurve = EllipticCurve.getSECCurveByName("secp256k1")
|
|
||||||
|
|
||||||
|
|
||||||
const ki = IL.add(BigInteger.fromByteArrayUnsigned(this.privateKey)).mod(epCurve.getN()) // parse256(IL) + kpar (mod n) ==> ki
|
|
||||||
this.childPrivateKey = ki.toByteArrayUnsigned()
|
|
||||||
|
|
||||||
// Call deriveExtendedPrivateChildKey
|
|
||||||
deriveExtendedPrivateChildKey(1, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const deriveExtendedPrivateChildKey = (i, childIndex) => {
|
|
||||||
|
|
||||||
// Serialization Variable
|
|
||||||
const s = []
|
|
||||||
|
|
||||||
// Append Version Byte
|
|
||||||
s.push(...(utils.int32ToBytes(this.versionBytes.mainnet.private)))
|
|
||||||
|
|
||||||
// Append Depth (using the index as depth)
|
|
||||||
i = parseInt(i)
|
|
||||||
s.push(i)
|
|
||||||
|
|
||||||
// Append Parent Fingerprint
|
|
||||||
s.push(...(this.publicKeyHash.slice(0, 4)))
|
|
||||||
|
|
||||||
// Append Child Index
|
|
||||||
s.push(childIndex >>> 24)
|
|
||||||
s.push((childIndex >>> 16) & 0xff)
|
|
||||||
s.push((childIndex >>> 8) & 0xff)
|
|
||||||
s.push(childIndex & 0xff)
|
|
||||||
|
|
||||||
// Append Chain Code
|
|
||||||
s.push(...this.childChainCode)
|
|
||||||
|
|
||||||
// Append 1 byte '0x00' (to make the key data 33 bytes, DO THIS ONLY FOR PRIVATE KEYS )
|
|
||||||
s.push(0)
|
|
||||||
|
|
||||||
// Append Private Key
|
|
||||||
s.push(...this.childPrivateKey)
|
|
||||||
|
|
||||||
// Generate CheckSum
|
|
||||||
const _s = new Uint8Array(s)
|
|
||||||
const _checkSum = new Sha256().process(new Sha256().process(_s).finish().result).finish().result
|
|
||||||
const checkSum = _checkSum.slice(0, 4)
|
|
||||||
|
|
||||||
// Append CheckSum
|
|
||||||
s.push(...checkSum) // And this brings us to the end of the serialization...
|
|
||||||
|
|
||||||
// Save to Private Key as Base58 encoded
|
|
||||||
this.xPrivateChildKey = Base58.encode(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
const deriveExtendedPublicChildKey = (i, childIndex) => {
|
|
||||||
|
|
||||||
// Serialization Variable
|
|
||||||
const s = []
|
|
||||||
|
|
||||||
// Append Version Byte
|
|
||||||
s.push(...(utils.int32ToBytes(this.versionBytes.mainnet.public)))
|
|
||||||
|
|
||||||
// Append Depth
|
|
||||||
i = parseInt(i)
|
|
||||||
s.push(i)
|
|
||||||
|
|
||||||
// Append Parent Fingerprint
|
|
||||||
s.push(...(this.publicKeyHash.slice(0, 4)))
|
|
||||||
|
|
||||||
// Append Child Index
|
|
||||||
s.push(childIndex >>> 24)
|
|
||||||
s.push((childIndex >>> 16) & 0xff)
|
|
||||||
s.push((childIndex >>> 8) & 0xff)
|
|
||||||
s.push(childIndex & 0xff)
|
|
||||||
|
|
||||||
// Append Chain Code
|
|
||||||
s.push(...this.childChainCode)
|
|
||||||
|
|
||||||
// Append Public Key
|
|
||||||
s.push(...this.childPublicKey)
|
|
||||||
|
|
||||||
// Generate CheckSum
|
|
||||||
const _s = new Uint8Array(s)
|
|
||||||
const _checkSum = new Sha256().process(new Sha256().process(_s).finish().result).finish().result
|
|
||||||
const checkSum = _checkSum.slice(0, 4)
|
|
||||||
|
|
||||||
// Append CheckSum
|
|
||||||
s.push(...checkSum) // And this brings us to the end of the serialization...
|
|
||||||
|
|
||||||
|
|
||||||
// Save to Public Key as Base58 encoded
|
|
||||||
this.xPublicChildKey = Base58.encode(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* GRAND CHILD KEYS
|
|
||||||
*
|
|
||||||
* NOTE: I know this is not the best way to generate this (even though it works the way it ought)
|
|
||||||
* Things to rewrite will be and not limited to deriving this through a for loop, removing hard code values, etc...
|
|
||||||
*/
|
|
||||||
|
|
||||||
const derivePublicGrandChildKey = () => {
|
|
||||||
|
|
||||||
const _privateKey = [...this.grandChildPrivateKey]
|
|
||||||
const privateKeyBigInt = BigInteger.fromByteArrayUnsigned(_privateKey)
|
|
||||||
|
|
||||||
|
|
||||||
const epCurve = EllipticCurve.getSECCurveByName("secp256k1")
|
|
||||||
const curvePoints = epCurve.getG().multiply(privateKeyBigInt)
|
|
||||||
|
|
||||||
const x = curvePoints.getX().toBigInteger()
|
|
||||||
const y = curvePoints.getY().toBigInteger()
|
|
||||||
|
|
||||||
// Compressed Public Key (33 bytes)
|
|
||||||
this.grandChildPublicKey = EllipticCurve.integerToBytes(x, 32)
|
|
||||||
|
|
||||||
|
|
||||||
if (y.isEven()) {
|
|
||||||
this.grandChildPublicKey.unshift(0x02) // append point indicator
|
|
||||||
} else {
|
|
||||||
this.grandChildPublicKey.unshift(0x03) // append point indicator
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// PublicKey Hash
|
|
||||||
const grandChildPublicKeySHA256 = new Sha256().process(new Uint8Array(this.grandChildPublicKey)).finish().result
|
|
||||||
const _grandChildPublicKeyHash = new RIPEMD160().update(Buffer.from(grandChildPublicKeySHA256)).digest('hex')
|
|
||||||
this.grandChildPublicKeyHash = _grandChildPublicKeyHash
|
|
||||||
|
|
||||||
|
|
||||||
// Call deriveExtendedPublicChildKey // WIll be hardcoding the values...
|
|
||||||
deriveExtendedPublicGrandChildKey(2, 0)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Derive Litecoin Legacy Address
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Append Address Prefix
|
|
||||||
let prefix = [this.versionBytes.mainnet.prefix]
|
|
||||||
if (2 == this.versionBytes.mainnet.prefix.length) {
|
|
||||||
prefix = [this.versionBytes.mainnet.prefix[0]]
|
|
||||||
prefix.push([this.versionBytes.mainnet.prefix[1]])
|
|
||||||
}
|
|
||||||
|
|
||||||
const k = prefix.concat(...this.grandChildPublicKeyHash)
|
|
||||||
|
|
||||||
// Derive Checksum
|
|
||||||
const _addressCheckSum = new Sha256().process(new Sha256().process(new Uint8Array(k)).finish().result).finish().result
|
|
||||||
const addressCheckSum = _addressCheckSum.slice(0, 4)
|
|
||||||
|
|
||||||
// Append CheckSum
|
|
||||||
const _litecoinLegacyAddress = k.concat(...addressCheckSum)
|
|
||||||
|
|
||||||
// Convert to Base58
|
|
||||||
this.litecoinLegacyAddress = Base58.encode(_litecoinLegacyAddress)
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Derive TESTNET Litecoin Legacy Address
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Append Version Byte
|
|
||||||
const tK = [this.versionBytes.testnet.prefix].concat(...this.grandChildPublicKeyHash)
|
|
||||||
|
|
||||||
// Derive Checksum
|
|
||||||
const _tAddressCheckSum = new Sha256().process(new Sha256().process(new Uint8Array(tK)).finish().result).finish().result
|
|
||||||
const tAddressCheckSum = _tAddressCheckSum.slice(0, 4)
|
|
||||||
|
|
||||||
// Append CheckSum
|
|
||||||
const _tlitecoinLegacyAddress = tK.concat(...tAddressCheckSum)
|
|
||||||
|
|
||||||
// Convert to Base58
|
|
||||||
this._tlitecoinLegacyAddress = Base58.encode(_tlitecoinLegacyAddress)
|
|
||||||
}
|
|
||||||
|
|
||||||
const derivePrivateGrandChildKey = (cI, i) => {
|
|
||||||
|
|
||||||
let ib = []
|
|
||||||
ib.push((cI >> 24) & 0xff)
|
|
||||||
ib.push((cI >> 16) & 0xff)
|
|
||||||
ib.push((cI >> 8) & 0xff)
|
|
||||||
ib.push(cI & 0xff)
|
|
||||||
|
|
||||||
const s = [...this.childPublicKey].concat(ib)
|
|
||||||
|
|
||||||
|
|
||||||
const _hmacSha512 = new jsSHA("SHA-512", "UINT8ARRAY", { numRounds: 1, hmacKey: { value: this.childChainCode, format: "UINT8ARRAY" } })
|
|
||||||
_hmacSha512.update(new Uint8Array(s))
|
|
||||||
|
|
||||||
|
|
||||||
const IL = BigInteger.fromByteArrayUnsigned([..._hmacSha512.getHMAC('UINT8ARRAY').slice(0, 32)])
|
|
||||||
this.grandChildChainCode = _hmacSha512.getHMAC('UINT8ARRAY').slice(32, 64) // IR according to the SPEC
|
|
||||||
|
|
||||||
// SECP256k1 init
|
|
||||||
const epCurve = EllipticCurve.getSECCurveByName("secp256k1")
|
|
||||||
|
|
||||||
|
|
||||||
const ki = IL.add(BigInteger.fromByteArrayUnsigned(this.childPrivateKey)).mod(epCurve.getN()) // parse256(IL) + kpar (mod n) ==> ki
|
|
||||||
this.grandChildPrivateKey = ki.toByteArrayUnsigned()
|
|
||||||
|
|
||||||
|
|
||||||
// Call deriveExtendedPrivateChildKey
|
|
||||||
deriveExtendedPrivateGrandChildKey(2, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const deriveExtendedPrivateGrandChildKey = (i, childIndex) => {
|
|
||||||
|
|
||||||
// Serialization Variable
|
|
||||||
const s = []
|
|
||||||
|
|
||||||
// Append Version Byte
|
|
||||||
s.push(...(utils.int32ToBytes(this.versionBytes.mainnet.private)))
|
|
||||||
|
|
||||||
// Append Depth (using the index as depth)
|
|
||||||
i = parseInt(i)
|
|
||||||
s.push(i)
|
|
||||||
|
|
||||||
// Append Parent Fingerprint
|
|
||||||
s.push(...(this.childPublicKeyHash.slice(0, 4)))
|
|
||||||
|
|
||||||
// Append Child Index
|
|
||||||
s.push(childIndex >>> 24)
|
|
||||||
s.push((childIndex >>> 16) & 0xff)
|
|
||||||
s.push((childIndex >>> 8) & 0xff)
|
|
||||||
s.push(childIndex & 0xff)
|
|
||||||
|
|
||||||
// Append Chain Code
|
|
||||||
s.push(...this.grandChildChainCode)
|
|
||||||
|
|
||||||
// Append 1 byte '0x00' (to make the key data 33 bytes, DO THIS ONLY FOR PRIVATE KEYS )
|
|
||||||
s.push(0)
|
|
||||||
|
|
||||||
// Append Private Key
|
|
||||||
s.push(...this.grandChildPrivateKey)
|
|
||||||
|
|
||||||
// Generate CheckSum
|
|
||||||
const _s = new Uint8Array(s)
|
|
||||||
const _checkSum = new Sha256().process(new Sha256().process(_s).finish().result).finish().result
|
|
||||||
const checkSum = _checkSum.slice(0, 4)
|
|
||||||
|
|
||||||
// Append CheckSum
|
|
||||||
s.push(...checkSum) // And this brings us to the end of the serialization...
|
|
||||||
|
|
||||||
// Save to Private Key as Base58 encoded
|
|
||||||
this.xPrivateGrandChildKey = Base58.encode(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
const deriveExtendedPublicGrandChildKey = (i, childIndex) => {
|
|
||||||
|
|
||||||
// Serialization Variable
|
|
||||||
const s = []
|
|
||||||
|
|
||||||
// Append Version Byte
|
|
||||||
s.push(...(utils.int32ToBytes(this.versionBytes.mainnet.public)))
|
|
||||||
|
|
||||||
// Append Depth
|
|
||||||
i = parseInt(i)
|
|
||||||
s.push(i)
|
|
||||||
|
|
||||||
// Append Parent Fingerprint
|
|
||||||
s.push(...(this.childPublicKeyHash.slice(0, 4)))
|
|
||||||
|
|
||||||
// Append Child Index
|
|
||||||
s.push(childIndex >>> 24)
|
|
||||||
s.push((childIndex >>> 16) & 0xff)
|
|
||||||
s.push((childIndex >>> 8) & 0xff)
|
|
||||||
s.push(childIndex & 0xff)
|
|
||||||
|
|
||||||
// Append Chain Code
|
|
||||||
s.push(...this.grandChildChainCode)
|
|
||||||
|
|
||||||
// Append Public Key
|
|
||||||
s.push(...this.grandChildPublicKey)
|
|
||||||
|
|
||||||
// Generate CheckSum
|
|
||||||
const _s = new Uint8Array(s)
|
|
||||||
const _checkSum = new Sha256().process(new Sha256().process(_s).finish().result).finish().result
|
|
||||||
const checkSum = _checkSum.slice(0, 4)
|
|
||||||
|
|
||||||
// Append CheckSum
|
|
||||||
s.push(...checkSum) // And this brings us to the end of the serialization...
|
|
||||||
|
|
||||||
// Save to Public Key as Base58 encoded
|
|
||||||
this.xPublicGrandChildKey = Base58.encode(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Hard Code value..
|
|
||||||
let childIndex = 0
|
|
||||||
|
|
||||||
// Call derivePrivateChildKey //Hard code value
|
|
||||||
derivePrivateChildKey(childIndex)
|
|
||||||
|
|
||||||
// Call derivePublicChildKey
|
|
||||||
derivePublicChildKey()
|
|
||||||
|
|
||||||
|
|
||||||
// Call derivePrivateGrandChildKey // Hard Code value...
|
|
||||||
derivePrivateGrandChildKey(0, 2)
|
|
||||||
|
|
||||||
// Call derivePublicGrandChildKey
|
|
||||||
derivePublicGrandChildKey()
|
|
||||||
}
|
|
||||||
|
|
||||||
returnWallet() {
|
|
||||||
|
|
||||||
// Will be limiting the exported Wallet Object to just the Master keys and Legacy Addresses
|
|
||||||
|
|
||||||
const wallet = {
|
|
||||||
derivedMasterPrivateKey: this.masterPrivateKey,
|
|
||||||
derivedMasterPublicKey: this.masterPublicKey,
|
|
||||||
_tDerivedMasterPrivateKey: this._tMasterPrivateKey,
|
|
||||||
_tDerivedmasterPublicKey: this._tmasterPublicKey,
|
|
||||||
seed58: this.seed58,
|
|
||||||
// derivedPrivateChildKey: this.xPrivateChildKey,
|
|
||||||
// derivedPublicChildKey: this.xPublicChildKey,
|
|
||||||
// derivedPrivateGrandChildKey: this.xPrivateGrandChildKey,
|
|
||||||
// derivedPublicGrandChildKey: this.xPublicGrandChildKey,
|
|
||||||
address: this.litecoinLegacyAddress,
|
|
||||||
_taddress: this._tlitecoinLegacyAddress
|
|
||||||
}
|
|
||||||
|
|
||||||
this.wallet = wallet
|
|
||||||
return wallet
|
|
||||||
}
|
|
||||||
}
|
|
881
src/encryption/AltcoinHDWallet.ts
Normal file
881
src/encryption/AltcoinHDWallet.ts
Normal file
@ -0,0 +1,881 @@
|
|||||||
|
// @ts-nocheck
|
||||||
|
import Base58 from './Base58.js';
|
||||||
|
import { Sha256, Sha512 } from 'asmcrypto.js';
|
||||||
|
import jsSHA from 'jssha';
|
||||||
|
import RIPEMD160 from './ripemd160.js';
|
||||||
|
import utils from '../utils/utils.js';
|
||||||
|
import { BigInteger, EllipticCurve } from './ecbn';
|
||||||
|
import { Buffer } from 'buffer';
|
||||||
|
|
||||||
|
export default class AltcoinHDWallet {
|
||||||
|
constructor(addressParams) {
|
||||||
|
/**
|
||||||
|
* Seed - 32 bytes
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.seed = new Uint8Array(32);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Version Bytes - 4 byte
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.versionBytes = addressParams;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Depth - 1 byte
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.depth = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parent Fingerprint - 4 bytes
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.parentFingerprint = '0x00000000'; // master key
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Child Index - 4 bytes
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.childIndex = '0x00000000'; // master key
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chain Code - 32 bytes
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.chainCode = new Uint8Array(32);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key Data - 33 bytes
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.keyData = new Uint8Array(33);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seed Hash - 64 bytes
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.seedHash = new Uint8Array(64);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private Key - 32 bytes
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.privateKey = new Uint8Array(32);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public Key - 33 bytes (compressed)
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.publicKey = new Uint8Array(33);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public Key Hash160 (used to derive the parent fingerprint for derived)
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.publicKeyHash = new Uint8Array(20);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Master Private Key (Base58 encoded)
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.masterPrivateKey = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Master Public Key (Base58 encoded)
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.masterPublicKey = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testnet Master Private Key (Base58 encoded) - THIS IS TESTNET
|
||||||
|
*/
|
||||||
|
|
||||||
|
this._tMasterPrivateKey = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testnet Master Public Key (Base58 encoded) - THIS IS TESTNET
|
||||||
|
*/
|
||||||
|
|
||||||
|
this._tmasterPublicKey = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Child Keys Derivation from the Parent Keys
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Child Private Key - 32 bytes
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.childPrivateKey = new Uint8Array(32);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Child Chain Code - 32 bytes
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.childChainCode = new Uint8Array(32);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Child Public Key - 33 bytes (compressed)
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.childPublicKey = new Uint8Array(33);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Child Public Key Hash160 (used to derive the parent fingerprint for derived)
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.childPublicKeyHash = new Uint8Array(20);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extended Private Child Key - Base58 encoded
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.xPrivateChildKey = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extended Public Child Key - Base58 encoded
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.xPublicChildKey = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grand Child Keys Derivation from the Child Keys
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grand Child Private Key - 32 bytes
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.grandChildPrivateKey = new Uint8Array(32);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grand Child Chain Code - 32 bytes
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.grandChildChainCode = new Uint8Array(32);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grand Child Public Key - 33 bytes (compressed)
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.grandChildPublicKey = new Uint8Array(33);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grand Public Key Hash160 (used to derive the parent fingerprint for derived)
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.grandChildPublicKeyHash = new Uint8Array(20);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extended Private Grand Child Key - Base58 encoded
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.xPrivateGrandChildKey = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extended Public Grand Child Key - Base58 encoded
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.xPublicGrandChildKey = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Litecoin Legacy Address - Derived from the Grand Child Public Key Hash
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.litecoinLegacyAddress = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TESTNET Litecoin Legacy Address (Derived from the Grand Child Public Key Hash) - THIS IS TESTNET
|
||||||
|
*/
|
||||||
|
|
||||||
|
this._tlitecoinLegacyAddress = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wallet - Wallet Object (keys...)
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.wallet = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
setSeed(seed) {
|
||||||
|
this.seed = seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
createWallet(seed, isBIP44, indicator = null) {
|
||||||
|
// Set Seeed
|
||||||
|
this.setSeed(seed);
|
||||||
|
|
||||||
|
// Generate Seed Hash
|
||||||
|
this.generateSeedHash(this.seed, isBIP44, indicator);
|
||||||
|
|
||||||
|
// Generate Private Key
|
||||||
|
this.generatePrivateKey(this.seedHash);
|
||||||
|
|
||||||
|
// Generate Chain Code
|
||||||
|
this.generateChainCode(this.seedHash);
|
||||||
|
|
||||||
|
// Generate Public Key from Private Key
|
||||||
|
this.generatePublicKey(this.privateKey);
|
||||||
|
|
||||||
|
// Generate Mainnet Master Private Key
|
||||||
|
this.generateMainnetMasterPrivateKey();
|
||||||
|
|
||||||
|
// Generate Mainnet Master Public Key
|
||||||
|
this.generateMainnetMasterPublicKey();
|
||||||
|
|
||||||
|
// Generate Testnet Master Private Key
|
||||||
|
this.generateTestnetMasterPrivateKey();
|
||||||
|
|
||||||
|
// Generate Testnet Master Public Key
|
||||||
|
this.generateTestnetMasterPublicKey();
|
||||||
|
|
||||||
|
// Generate Child and Grand Child Keys
|
||||||
|
this.generateDerivedChildKeys();
|
||||||
|
|
||||||
|
// Return Wallet Object Specification
|
||||||
|
return this.returnWallet();
|
||||||
|
}
|
||||||
|
|
||||||
|
generateSeedHash(seed, isBIP44, indicator = null) {
|
||||||
|
let buffer;
|
||||||
|
|
||||||
|
if (isBIP44) {
|
||||||
|
buffer = utils.appendBuffer(
|
||||||
|
seed.reverse(),
|
||||||
|
utils.int32ToBytes(indicator)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
if (indicator !== null) {
|
||||||
|
const indicatorString = utils.stringtoUTF8Array(indicator);
|
||||||
|
buffer = utils.appendBuffer(seed.reverse(), indicatorString);
|
||||||
|
} else {
|
||||||
|
buffer = seed.reverse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const _reverseSeedHash = new Sha256().process(buffer).finish().result;
|
||||||
|
this.seedHash = new Sha512()
|
||||||
|
.process(utils.appendBuffer(seed, _reverseSeedHash))
|
||||||
|
.finish().result;
|
||||||
|
}
|
||||||
|
|
||||||
|
generatePrivateKey(seedHash) {
|
||||||
|
const SECP256K1_CURVE_ORDER = new BigInteger(
|
||||||
|
'0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141'
|
||||||
|
);
|
||||||
|
|
||||||
|
const privateKeyHash = seedHash.slice(0, 32);
|
||||||
|
|
||||||
|
this.seed58 = Base58.encode(privateKeyHash);
|
||||||
|
|
||||||
|
const _privateKeyHash = [...privateKeyHash];
|
||||||
|
let privateKeyBigInt = BigInteger.fromByteArrayUnsigned(_privateKeyHash);
|
||||||
|
|
||||||
|
const privateKey = privateKeyBigInt
|
||||||
|
.mod(SECP256K1_CURVE_ORDER.subtract(BigInteger.ONE))
|
||||||
|
.add(BigInteger.ONE);
|
||||||
|
this.privateKey = privateKey.toByteArrayUnsigned();
|
||||||
|
}
|
||||||
|
|
||||||
|
generateChainCode(seedHash) {
|
||||||
|
this.chainCode = new Sha256()
|
||||||
|
.process(seedHash.slice(32, 64))
|
||||||
|
.finish().result;
|
||||||
|
}
|
||||||
|
|
||||||
|
generatePublicKey(privateKey) {
|
||||||
|
const _privateKey = [...privateKey];
|
||||||
|
const privateKeyBigInt = BigInteger.fromByteArrayUnsigned(_privateKey);
|
||||||
|
|
||||||
|
const epCurve = EllipticCurve.getSECCurveByName('secp256k1');
|
||||||
|
const curvePoints = epCurve.getG().multiply(privateKeyBigInt);
|
||||||
|
|
||||||
|
const x = curvePoints.getX().toBigInteger();
|
||||||
|
const y = curvePoints.getY().toBigInteger();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deriving Uncompressed Public Key (65 bytes)
|
||||||
|
*
|
||||||
|
* const publicKeyBytes = EllipticCurve.integerToBytes(x, 32)
|
||||||
|
* this.publicKey = publicKeyBytes.concat(EllipticCurve.integerToBytes(y, 32))
|
||||||
|
* this.publicKey.unshift(0x04) // append point indicator
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Compressed Public Key (33 bytes)
|
||||||
|
this.publicKey = EllipticCurve.integerToBytes(x, 32);
|
||||||
|
|
||||||
|
if (y.isEven()) {
|
||||||
|
this.publicKey.unshift(0x02); // append point indicator
|
||||||
|
} else {
|
||||||
|
this.publicKey.unshift(0x03); // append point indicator
|
||||||
|
}
|
||||||
|
|
||||||
|
// PublicKey Hash
|
||||||
|
const publicKeySHA256 = new Sha256()
|
||||||
|
.process(new Uint8Array(this.publicKey))
|
||||||
|
.finish().result;
|
||||||
|
const _publicKeyHash = new RIPEMD160()
|
||||||
|
.update(Buffer.from(publicKeySHA256))
|
||||||
|
.digest('hex');
|
||||||
|
this.publicKeyHash = _publicKeyHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
generateMainnetMasterPrivateKey() {
|
||||||
|
// Serialization Variable
|
||||||
|
const s = [];
|
||||||
|
|
||||||
|
// Append Version Byte
|
||||||
|
s.push(...utils.int32ToBytes(this.versionBytes.mainnet.private));
|
||||||
|
|
||||||
|
// Append Depth
|
||||||
|
s.push(this.depth);
|
||||||
|
|
||||||
|
// Append Parent Fingerprint
|
||||||
|
s.push(...utils.int32ToBytes(this.parentFingerprint));
|
||||||
|
|
||||||
|
// Append Child Number
|
||||||
|
s.push(...utils.int32ToBytes(this.childIndex));
|
||||||
|
|
||||||
|
// Append Chain Code
|
||||||
|
s.push(...this.chainCode);
|
||||||
|
|
||||||
|
// Append 1 byte '0x00' (to make the key data 33 bytes, DO THIS ONLY FOR PRIVATE KEYS )
|
||||||
|
s.push(0);
|
||||||
|
|
||||||
|
//if the private key length is less than 32 let's add leading zeros
|
||||||
|
if (this.privateKey.length < 32) {
|
||||||
|
for (let i = this.privateKey.length; i < 32; i++) {
|
||||||
|
s.push(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append Private Key
|
||||||
|
s.push(...this.privateKey);
|
||||||
|
|
||||||
|
// Generate CheckSum
|
||||||
|
const _s = new Uint8Array(s);
|
||||||
|
const _checkSum = new Sha256()
|
||||||
|
.process(new Sha256().process(_s).finish().result)
|
||||||
|
.finish().result;
|
||||||
|
const checkSum = _checkSum.slice(0, 4);
|
||||||
|
|
||||||
|
// Append CheckSum
|
||||||
|
s.push(...checkSum); // And this brings us to the end of the serialization...
|
||||||
|
|
||||||
|
// Save to Private Key as Base58 encoded
|
||||||
|
this.masterPrivateKey = Base58.encode(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
generateMainnetMasterPublicKey() {
|
||||||
|
// Serialization Variable
|
||||||
|
const s = [];
|
||||||
|
|
||||||
|
// Append Version Byte
|
||||||
|
s.push(...utils.int32ToBytes(this.versionBytes.mainnet.public));
|
||||||
|
|
||||||
|
// Append Depth
|
||||||
|
s.push(this.depth);
|
||||||
|
|
||||||
|
// Append Parent Fingerprint
|
||||||
|
s.push(...utils.int32ToBytes(this.parentFingerprint));
|
||||||
|
|
||||||
|
// Append Child Number
|
||||||
|
s.push(...utils.int32ToBytes(this.childIndex));
|
||||||
|
|
||||||
|
// Append Chain Code
|
||||||
|
s.push(...this.chainCode);
|
||||||
|
|
||||||
|
// Append Public Key
|
||||||
|
s.push(...this.publicKey);
|
||||||
|
|
||||||
|
// Generate CheckSum
|
||||||
|
const _s = new Uint8Array(s);
|
||||||
|
const _checkSum = new Sha256()
|
||||||
|
.process(new Sha256().process(_s).finish().result)
|
||||||
|
.finish().result;
|
||||||
|
const checkSum = _checkSum.slice(0, 4);
|
||||||
|
|
||||||
|
// Append CheckSum
|
||||||
|
s.push(...checkSum); // And this brings us to the end of the serialization...
|
||||||
|
|
||||||
|
// Save to Public Key as Base58 encoded
|
||||||
|
this.masterPublicKey = Base58.encode(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
generateTestnetMasterPrivateKey() {
|
||||||
|
// To be Used ONLY in Testnet...
|
||||||
|
|
||||||
|
// Serialization Variable
|
||||||
|
const s = [];
|
||||||
|
|
||||||
|
// Append Version Byte
|
||||||
|
s.push(...utils.int32ToBytes(this.versionBytes.testnet.private));
|
||||||
|
|
||||||
|
// Append Depth
|
||||||
|
s.push(this.depth);
|
||||||
|
|
||||||
|
// Append Parent Fingerprint
|
||||||
|
s.push(...utils.int32ToBytes(this.parentFingerprint));
|
||||||
|
|
||||||
|
// Append Child Number
|
||||||
|
s.push(...utils.int32ToBytes(this.childIndex));
|
||||||
|
|
||||||
|
// Append Chain Code
|
||||||
|
s.push(...this.chainCode);
|
||||||
|
|
||||||
|
// Append 1 byte '0x00' (to make the key data 33 bytes, DO THIS ONLY FOR PRIVATE KEYS )
|
||||||
|
s.push(0);
|
||||||
|
|
||||||
|
// Append Private Key
|
||||||
|
s.push(...this.privateKey);
|
||||||
|
|
||||||
|
// Generate CheckSum
|
||||||
|
const _s = new Uint8Array(s);
|
||||||
|
const _checkSum = new Sha256()
|
||||||
|
.process(new Sha256().process(_s).finish().result)
|
||||||
|
.finish().result;
|
||||||
|
const checkSum = _checkSum.slice(0, 4);
|
||||||
|
|
||||||
|
// Append CheckSum
|
||||||
|
s.push(...checkSum); // And this brings us to the end of the serialization...
|
||||||
|
|
||||||
|
// Save to Private Key as Base58 encoded
|
||||||
|
this._tMasterPrivateKey = Base58.encode(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
generateTestnetMasterPublicKey() {
|
||||||
|
// To be Used ONLY in Testnet...
|
||||||
|
|
||||||
|
// Serialization Variable
|
||||||
|
const s = [];
|
||||||
|
|
||||||
|
// Append Version Byte
|
||||||
|
s.push(...utils.int32ToBytes(this.versionBytes.testnet.public));
|
||||||
|
|
||||||
|
// Append Depth
|
||||||
|
s.push(this.depth);
|
||||||
|
|
||||||
|
// Append Parent Fingerprint
|
||||||
|
s.push(...utils.int32ToBytes(this.parentFingerprint));
|
||||||
|
|
||||||
|
// Append Child Number
|
||||||
|
s.push(...utils.int32ToBytes(this.childIndex));
|
||||||
|
|
||||||
|
// Append Chain Code
|
||||||
|
s.push(...this.chainCode);
|
||||||
|
|
||||||
|
// Append Private Key
|
||||||
|
s.push(...this.publicKey);
|
||||||
|
|
||||||
|
// Generate CheckSum
|
||||||
|
const _s = new Uint8Array(s);
|
||||||
|
const _checkSum = new Sha256()
|
||||||
|
.process(new Sha256().process(_s).finish().result)
|
||||||
|
.finish().result;
|
||||||
|
const checkSum = _checkSum.slice(0, 4);
|
||||||
|
|
||||||
|
// Append CheckSum
|
||||||
|
s.push(...checkSum); // And this brings us to the end of the serialization...
|
||||||
|
|
||||||
|
// Save to Private Key as Base58 encoded
|
||||||
|
this._tmasterPublicKey = Base58.encode(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
generateDerivedChildKeys() {
|
||||||
|
// SPEC INFO: https://en.bitcoin.it/wiki/BIP_0032#Child_key_derivation_.28CKD.29_functions
|
||||||
|
// NOTE: will not be using some of derivations func as the value is known. (So I'd rather shove in the values and rewrite out the derivations later ?)
|
||||||
|
|
||||||
|
// NOTE: I "re-wrote" and "reduplicate" the code for child and grandChild keys derivations inorder to get the child and grandchild from the child
|
||||||
|
// TODO: Make this more better in the future
|
||||||
|
|
||||||
|
const path = 'm/0/0';
|
||||||
|
// let p = path.split('/')
|
||||||
|
|
||||||
|
// Get Public kEY
|
||||||
|
const derivePublicChildKey = () => {
|
||||||
|
const _privateKey = [...this.childPrivateKey];
|
||||||
|
const privateKeyBigInt = BigInteger.fromByteArrayUnsigned(_privateKey);
|
||||||
|
|
||||||
|
const epCurve = EllipticCurve.getSECCurveByName('secp256k1');
|
||||||
|
const curvePoints = epCurve.getG().multiply(privateKeyBigInt);
|
||||||
|
|
||||||
|
const x = curvePoints.getX().toBigInteger();
|
||||||
|
const y = curvePoints.getY().toBigInteger();
|
||||||
|
|
||||||
|
// Compressed Public Key (33 bytes)
|
||||||
|
this.childPublicKey = EllipticCurve.integerToBytes(x, 32);
|
||||||
|
|
||||||
|
if (y.isEven()) {
|
||||||
|
this.childPublicKey.unshift(0x02); // append point indicator
|
||||||
|
} else {
|
||||||
|
this.childPublicKey.unshift(0x03); // append point indicator
|
||||||
|
}
|
||||||
|
|
||||||
|
// PublicKey Hash
|
||||||
|
const childPublicKeySHA256 = new Sha256()
|
||||||
|
.process(new Uint8Array(this.childPublicKey))
|
||||||
|
.finish().result;
|
||||||
|
const _childPublicKeyHash = new RIPEMD160()
|
||||||
|
.update(Buffer.from(childPublicKeySHA256))
|
||||||
|
.digest('hex');
|
||||||
|
this.childPublicKeyHash = _childPublicKeyHash;
|
||||||
|
|
||||||
|
// Call deriveExtendedPublicChildKey // WIll be hardcoding the values...
|
||||||
|
deriveExtendedPublicChildKey(1, 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
const derivePrivateChildKey = (cI) => {
|
||||||
|
let ib = [];
|
||||||
|
ib.push((cI >> 24) & 0xff);
|
||||||
|
ib.push((cI >> 16) & 0xff);
|
||||||
|
ib.push((cI >> 8) & 0xff);
|
||||||
|
ib.push(cI & 0xff);
|
||||||
|
|
||||||
|
const s = [...this.publicKey].concat(ib);
|
||||||
|
|
||||||
|
const _hmacSha512 = new jsSHA('SHA-512', 'UINT8ARRAY', {
|
||||||
|
numRounds: 1,
|
||||||
|
hmacKey: { value: this.chainCode, format: 'UINT8ARRAY' },
|
||||||
|
});
|
||||||
|
_hmacSha512.update(new Uint8Array(s));
|
||||||
|
|
||||||
|
const IL = BigInteger.fromByteArrayUnsigned([
|
||||||
|
..._hmacSha512.getHMAC('UINT8ARRAY').slice(0, 32),
|
||||||
|
]);
|
||||||
|
this.childChainCode = _hmacSha512.getHMAC('UINT8ARRAY').slice(32, 64); // IR according to the SPEC
|
||||||
|
|
||||||
|
// SECP256k1 init
|
||||||
|
const epCurve = EllipticCurve.getSECCurveByName('secp256k1');
|
||||||
|
|
||||||
|
const ki = IL.add(BigInteger.fromByteArrayUnsigned(this.privateKey)).mod(
|
||||||
|
epCurve.getN()
|
||||||
|
); // parse256(IL) + kpar (mod n) ==> ki
|
||||||
|
this.childPrivateKey = ki.toByteArrayUnsigned();
|
||||||
|
|
||||||
|
// Call deriveExtendedPrivateChildKey
|
||||||
|
deriveExtendedPrivateChildKey(1, 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
const deriveExtendedPrivateChildKey = (i, childIndex) => {
|
||||||
|
// Serialization Variable
|
||||||
|
const s = [];
|
||||||
|
|
||||||
|
// Append Version Byte
|
||||||
|
s.push(...utils.int32ToBytes(this.versionBytes.mainnet.private));
|
||||||
|
|
||||||
|
// Append Depth (using the index as depth)
|
||||||
|
i = parseInt(i);
|
||||||
|
s.push(i);
|
||||||
|
|
||||||
|
// Append Parent Fingerprint
|
||||||
|
s.push(...this.publicKeyHash.slice(0, 4));
|
||||||
|
|
||||||
|
// Append Child Index
|
||||||
|
s.push(childIndex >>> 24);
|
||||||
|
s.push((childIndex >>> 16) & 0xff);
|
||||||
|
s.push((childIndex >>> 8) & 0xff);
|
||||||
|
s.push(childIndex & 0xff);
|
||||||
|
|
||||||
|
// Append Chain Code
|
||||||
|
s.push(...this.childChainCode);
|
||||||
|
|
||||||
|
// Append 1 byte '0x00' (to make the key data 33 bytes, DO THIS ONLY FOR PRIVATE KEYS )
|
||||||
|
s.push(0);
|
||||||
|
|
||||||
|
// Append Private Key
|
||||||
|
s.push(...this.childPrivateKey);
|
||||||
|
|
||||||
|
// Generate CheckSum
|
||||||
|
const _s = new Uint8Array(s);
|
||||||
|
const _checkSum = new Sha256()
|
||||||
|
.process(new Sha256().process(_s).finish().result)
|
||||||
|
.finish().result;
|
||||||
|
const checkSum = _checkSum.slice(0, 4);
|
||||||
|
|
||||||
|
// Append CheckSum
|
||||||
|
s.push(...checkSum); // And this brings us to the end of the serialization...
|
||||||
|
|
||||||
|
// Save to Private Key as Base58 encoded
|
||||||
|
this.xPrivateChildKey = Base58.encode(s);
|
||||||
|
};
|
||||||
|
|
||||||
|
const deriveExtendedPublicChildKey = (i, childIndex) => {
|
||||||
|
// Serialization Variable
|
||||||
|
const s = [];
|
||||||
|
|
||||||
|
// Append Version Byte
|
||||||
|
s.push(...utils.int32ToBytes(this.versionBytes.mainnet.public));
|
||||||
|
|
||||||
|
// Append Depth
|
||||||
|
i = parseInt(i);
|
||||||
|
s.push(i);
|
||||||
|
|
||||||
|
// Append Parent Fingerprint
|
||||||
|
s.push(...this.publicKeyHash.slice(0, 4));
|
||||||
|
|
||||||
|
// Append Child Index
|
||||||
|
s.push(childIndex >>> 24);
|
||||||
|
s.push((childIndex >>> 16) & 0xff);
|
||||||
|
s.push((childIndex >>> 8) & 0xff);
|
||||||
|
s.push(childIndex & 0xff);
|
||||||
|
|
||||||
|
// Append Chain Code
|
||||||
|
s.push(...this.childChainCode);
|
||||||
|
|
||||||
|
// Append Public Key
|
||||||
|
s.push(...this.childPublicKey);
|
||||||
|
|
||||||
|
// Generate CheckSum
|
||||||
|
const _s = new Uint8Array(s);
|
||||||
|
const _checkSum = new Sha256()
|
||||||
|
.process(new Sha256().process(_s).finish().result)
|
||||||
|
.finish().result;
|
||||||
|
const checkSum = _checkSum.slice(0, 4);
|
||||||
|
|
||||||
|
// Append CheckSum
|
||||||
|
s.push(...checkSum); // And this brings us to the end of the serialization...
|
||||||
|
|
||||||
|
// Save to Public Key as Base58 encoded
|
||||||
|
this.xPublicChildKey = Base58.encode(s);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GRAND CHILD KEYS
|
||||||
|
*
|
||||||
|
* NOTE: I know this is not the best way to generate this (even though it works the way it ought)
|
||||||
|
* Things to rewrite will be and not limited to deriving this through a for loop, removing hard code values, etc...
|
||||||
|
*/
|
||||||
|
|
||||||
|
const derivePublicGrandChildKey = () => {
|
||||||
|
const _privateKey = [...this.grandChildPrivateKey];
|
||||||
|
const privateKeyBigInt = BigInteger.fromByteArrayUnsigned(_privateKey);
|
||||||
|
|
||||||
|
const epCurve = EllipticCurve.getSECCurveByName('secp256k1');
|
||||||
|
const curvePoints = epCurve.getG().multiply(privateKeyBigInt);
|
||||||
|
|
||||||
|
const x = curvePoints.getX().toBigInteger();
|
||||||
|
const y = curvePoints.getY().toBigInteger();
|
||||||
|
|
||||||
|
// Compressed Public Key (33 bytes)
|
||||||
|
this.grandChildPublicKey = EllipticCurve.integerToBytes(x, 32);
|
||||||
|
|
||||||
|
if (y.isEven()) {
|
||||||
|
this.grandChildPublicKey.unshift(0x02); // append point indicator
|
||||||
|
} else {
|
||||||
|
this.grandChildPublicKey.unshift(0x03); // append point indicator
|
||||||
|
}
|
||||||
|
|
||||||
|
// PublicKey Hash
|
||||||
|
const grandChildPublicKeySHA256 = new Sha256()
|
||||||
|
.process(new Uint8Array(this.grandChildPublicKey))
|
||||||
|
.finish().result;
|
||||||
|
const _grandChildPublicKeyHash = new RIPEMD160()
|
||||||
|
.update(Buffer.from(grandChildPublicKeySHA256))
|
||||||
|
.digest('hex');
|
||||||
|
this.grandChildPublicKeyHash = _grandChildPublicKeyHash;
|
||||||
|
|
||||||
|
// Call deriveExtendedPublicChildKey // WIll be hardcoding the values...
|
||||||
|
deriveExtendedPublicGrandChildKey(2, 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Derive Litecoin Legacy Address
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Append Address Prefix
|
||||||
|
let prefix = [this.versionBytes.mainnet.prefix];
|
||||||
|
if (2 == this.versionBytes.mainnet.prefix.length) {
|
||||||
|
prefix = [this.versionBytes.mainnet.prefix[0]];
|
||||||
|
prefix.push([this.versionBytes.mainnet.prefix[1]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const k = prefix.concat(...this.grandChildPublicKeyHash);
|
||||||
|
|
||||||
|
// Derive Checksum
|
||||||
|
const _addressCheckSum = new Sha256()
|
||||||
|
.process(new Sha256().process(new Uint8Array(k)).finish().result)
|
||||||
|
.finish().result;
|
||||||
|
const addressCheckSum = _addressCheckSum.slice(0, 4);
|
||||||
|
|
||||||
|
// Append CheckSum
|
||||||
|
const _litecoinLegacyAddress = k.concat(...addressCheckSum);
|
||||||
|
|
||||||
|
// Convert to Base58
|
||||||
|
this.litecoinLegacyAddress = Base58.encode(_litecoinLegacyAddress);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Derive TESTNET Litecoin Legacy Address
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Append Version Byte
|
||||||
|
const tK = [this.versionBytes.testnet.prefix].concat(
|
||||||
|
...this.grandChildPublicKeyHash
|
||||||
|
);
|
||||||
|
|
||||||
|
// Derive Checksum
|
||||||
|
const _tAddressCheckSum = new Sha256()
|
||||||
|
.process(new Sha256().process(new Uint8Array(tK)).finish().result)
|
||||||
|
.finish().result;
|
||||||
|
const tAddressCheckSum = _tAddressCheckSum.slice(0, 4);
|
||||||
|
|
||||||
|
// Append CheckSum
|
||||||
|
const _tlitecoinLegacyAddress = tK.concat(...tAddressCheckSum);
|
||||||
|
|
||||||
|
// Convert to Base58
|
||||||
|
this._tlitecoinLegacyAddress = Base58.encode(_tlitecoinLegacyAddress);
|
||||||
|
};
|
||||||
|
|
||||||
|
const derivePrivateGrandChildKey = (cI, i) => {
|
||||||
|
let ib = [];
|
||||||
|
ib.push((cI >> 24) & 0xff);
|
||||||
|
ib.push((cI >> 16) & 0xff);
|
||||||
|
ib.push((cI >> 8) & 0xff);
|
||||||
|
ib.push(cI & 0xff);
|
||||||
|
|
||||||
|
const s = [...this.childPublicKey].concat(ib);
|
||||||
|
|
||||||
|
const _hmacSha512 = new jsSHA('SHA-512', 'UINT8ARRAY', {
|
||||||
|
numRounds: 1,
|
||||||
|
hmacKey: { value: this.childChainCode, format: 'UINT8ARRAY' },
|
||||||
|
});
|
||||||
|
_hmacSha512.update(new Uint8Array(s));
|
||||||
|
|
||||||
|
const IL = BigInteger.fromByteArrayUnsigned([
|
||||||
|
..._hmacSha512.getHMAC('UINT8ARRAY').slice(0, 32),
|
||||||
|
]);
|
||||||
|
this.grandChildChainCode = _hmacSha512
|
||||||
|
.getHMAC('UINT8ARRAY')
|
||||||
|
.slice(32, 64); // IR according to the SPEC
|
||||||
|
|
||||||
|
// SECP256k1 init
|
||||||
|
const epCurve = EllipticCurve.getSECCurveByName('secp256k1');
|
||||||
|
|
||||||
|
const ki = IL.add(
|
||||||
|
BigInteger.fromByteArrayUnsigned(this.childPrivateKey)
|
||||||
|
).mod(epCurve.getN()); // parse256(IL) + kpar (mod n) ==> ki
|
||||||
|
this.grandChildPrivateKey = ki.toByteArrayUnsigned();
|
||||||
|
|
||||||
|
// Call deriveExtendedPrivateChildKey
|
||||||
|
deriveExtendedPrivateGrandChildKey(2, 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
const deriveExtendedPrivateGrandChildKey = (i, childIndex) => {
|
||||||
|
// Serialization Variable
|
||||||
|
const s = [];
|
||||||
|
|
||||||
|
// Append Version Byte
|
||||||
|
s.push(...utils.int32ToBytes(this.versionBytes.mainnet.private));
|
||||||
|
|
||||||
|
// Append Depth (using the index as depth)
|
||||||
|
i = parseInt(i);
|
||||||
|
s.push(i);
|
||||||
|
|
||||||
|
// Append Parent Fingerprint
|
||||||
|
s.push(...this.childPublicKeyHash.slice(0, 4));
|
||||||
|
|
||||||
|
// Append Child Index
|
||||||
|
s.push(childIndex >>> 24);
|
||||||
|
s.push((childIndex >>> 16) & 0xff);
|
||||||
|
s.push((childIndex >>> 8) & 0xff);
|
||||||
|
s.push(childIndex & 0xff);
|
||||||
|
|
||||||
|
// Append Chain Code
|
||||||
|
s.push(...this.grandChildChainCode);
|
||||||
|
|
||||||
|
// Append 1 byte '0x00' (to make the key data 33 bytes, DO THIS ONLY FOR PRIVATE KEYS )
|
||||||
|
s.push(0);
|
||||||
|
|
||||||
|
// Append Private Key
|
||||||
|
s.push(...this.grandChildPrivateKey);
|
||||||
|
|
||||||
|
// Generate CheckSum
|
||||||
|
const _s = new Uint8Array(s);
|
||||||
|
const _checkSum = new Sha256()
|
||||||
|
.process(new Sha256().process(_s).finish().result)
|
||||||
|
.finish().result;
|
||||||
|
const checkSum = _checkSum.slice(0, 4);
|
||||||
|
|
||||||
|
// Append CheckSum
|
||||||
|
s.push(...checkSum); // And this brings us to the end of the serialization...
|
||||||
|
|
||||||
|
// Save to Private Key as Base58 encoded
|
||||||
|
this.xPrivateGrandChildKey = Base58.encode(s);
|
||||||
|
};
|
||||||
|
|
||||||
|
const deriveExtendedPublicGrandChildKey = (i, childIndex) => {
|
||||||
|
// Serialization Variable
|
||||||
|
const s = [];
|
||||||
|
|
||||||
|
// Append Version Byte
|
||||||
|
s.push(...utils.int32ToBytes(this.versionBytes.mainnet.public));
|
||||||
|
|
||||||
|
// Append Depth
|
||||||
|
i = parseInt(i);
|
||||||
|
s.push(i);
|
||||||
|
|
||||||
|
// Append Parent Fingerprint
|
||||||
|
s.push(...this.childPublicKeyHash.slice(0, 4));
|
||||||
|
|
||||||
|
// Append Child Index
|
||||||
|
s.push(childIndex >>> 24);
|
||||||
|
s.push((childIndex >>> 16) & 0xff);
|
||||||
|
s.push((childIndex >>> 8) & 0xff);
|
||||||
|
s.push(childIndex & 0xff);
|
||||||
|
|
||||||
|
// Append Chain Code
|
||||||
|
s.push(...this.grandChildChainCode);
|
||||||
|
|
||||||
|
// Append Public Key
|
||||||
|
s.push(...this.grandChildPublicKey);
|
||||||
|
|
||||||
|
// Generate CheckSum
|
||||||
|
const _s = new Uint8Array(s);
|
||||||
|
const _checkSum = new Sha256()
|
||||||
|
.process(new Sha256().process(_s).finish().result)
|
||||||
|
.finish().result;
|
||||||
|
const checkSum = _checkSum.slice(0, 4);
|
||||||
|
|
||||||
|
// Append CheckSum
|
||||||
|
s.push(...checkSum); // And this brings us to the end of the serialization...
|
||||||
|
|
||||||
|
// Save to Public Key as Base58 encoded
|
||||||
|
this.xPublicGrandChildKey = Base58.encode(s);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Hard Code value..
|
||||||
|
let childIndex = 0;
|
||||||
|
|
||||||
|
// Call derivePrivateChildKey //Hard code value
|
||||||
|
derivePrivateChildKey(childIndex);
|
||||||
|
|
||||||
|
// Call derivePublicChildKey
|
||||||
|
derivePublicChildKey();
|
||||||
|
|
||||||
|
// Call derivePrivateGrandChildKey // Hard Code value...
|
||||||
|
derivePrivateGrandChildKey(0, 2);
|
||||||
|
|
||||||
|
// Call derivePublicGrandChildKey
|
||||||
|
derivePublicGrandChildKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
returnWallet() {
|
||||||
|
// Will be limiting the exported Wallet Object to just the Master keys and Legacy Addresses
|
||||||
|
|
||||||
|
const wallet = {
|
||||||
|
derivedMasterPrivateKey: this.masterPrivateKey,
|
||||||
|
derivedMasterPublicKey: this.masterPublicKey,
|
||||||
|
_tDerivedMasterPrivateKey: this._tMasterPrivateKey,
|
||||||
|
_tDerivedmasterPublicKey: this._tmasterPublicKey,
|
||||||
|
seed58: this.seed58,
|
||||||
|
// derivedPrivateChildKey: this.xPrivateChildKey,
|
||||||
|
// derivedPublicChildKey: this.xPublicChildKey,
|
||||||
|
// derivedPrivateGrandChildKey: this.xPrivateGrandChildKey,
|
||||||
|
// derivedPublicGrandChildKey: this.xPublicGrandChildKey,
|
||||||
|
address: this.litecoinLegacyAddress,
|
||||||
|
_taddress: this._tlitecoinLegacyAddress,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.wallet = wallet;
|
||||||
|
return wallet;
|
||||||
|
}
|
||||||
|
}
|
@ -1,14 +1,14 @@
|
|||||||
import { getBaseApi } from '../background';
|
import { getBaseApi } from '../background/background.ts';
|
||||||
import i18n from '../i18n/i18n';
|
import i18n from '../i18n/i18n.ts';
|
||||||
import {
|
import {
|
||||||
createSymmetricKeyAndNonce,
|
createSymmetricKeyAndNonce,
|
||||||
decryptGroupData,
|
decryptGroupData,
|
||||||
encryptDataGroup,
|
encryptDataGroup,
|
||||||
objectToBase64,
|
objectToBase64,
|
||||||
} from '../qdn/encryption/group-encryption';
|
} from '../qdn/encryption/group-encryption.ts';
|
||||||
import { publishData } from '../qdn/publish/pubish';
|
import { publishData } from '../qdn/publish/pubish.ts';
|
||||||
import { getData } from '../utils/chromeStorage';
|
import { getData } from '../utils/chromeStorage.ts';
|
||||||
import { RequestQueueWithPromise } from '../utils/queue/queue';
|
import { RequestQueueWithPromise } from '../utils/queue/queue.ts';
|
||||||
|
|
||||||
export const requestQueueGetPublicKeys = new RequestQueueWithPromise(10);
|
export const requestQueueGetPublicKeys = new RequestQueueWithPromise(10);
|
||||||
|
|
@ -1,7 +1,10 @@
|
|||||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||||
import { getBaseApiReact } from '../App';
|
import { getBaseApiReact } from '../App';
|
||||||
import { getData, storeData } from '../utils/chromeStorage';
|
import { getData, storeData } from '../utils/chromeStorage';
|
||||||
import { checkDifference, getNameInfoForOthers } from '../background';
|
import {
|
||||||
|
checkDifference,
|
||||||
|
getNameInfoForOthers,
|
||||||
|
} from '../background/background.ts';
|
||||||
import { lastPaymentSeenTimestampAtom } from '../atoms/global';
|
import { lastPaymentSeenTimestampAtom } from '../atoms/global';
|
||||||
import { subscribeToEvent, unsubscribeFromEvent } from '../utils/events';
|
import { subscribeToEvent, unsubscribeFromEvent } from '../utils/events';
|
||||||
import { useAtom } from 'jotai';
|
import { useAtom } from 'jotai';
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
import { useContext, useState } from 'react';
|
import { useContext, useState } from 'react';
|
||||||
import { executeEvent } from '../utils/events';
|
import { executeEvent } from '../utils/events';
|
||||||
import { getBaseApiReact, QORTAL_APP_CONTEXT } from '../App';
|
import { getBaseApiReact, QORTAL_APP_CONTEXT } from '../App';
|
||||||
import { createEndpoint } from '../background';
|
import { createEndpoint } from '../background/background.ts';
|
||||||
import {
|
import {
|
||||||
settingsLocalLastUpdatedAtom,
|
settingsLocalLastUpdatedAtom,
|
||||||
sortablePinnedAppsAtom,
|
sortablePinnedAppsAtom,
|
||||||
} from '../atoms/global';
|
} from '../atoms/global';
|
||||||
import { saveToLocalStorage } from '../components/Apps/AppsNavBarDesktop';
|
import { saveToLocalStorage } from '../components/Apps/AppsNavBarDesktop';
|
||||||
import { base64ToUint8Array } from '../qdn/encryption/group-encryption';
|
import { base64ToUint8Array } from '../qdn/encryption/group-encryption';
|
||||||
import { uint8ArrayToObject } from '../backgroundFunctions/encryption';
|
import { uint8ArrayToObject } from '../encryption/encryption.ts';
|
||||||
import { useSetAtom } from 'jotai';
|
import { useSetAtom } from 'jotai';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ import { decryptResource } from '../components/Group/Group';
|
|||||||
import {
|
import {
|
||||||
base64ToUint8Array,
|
base64ToUint8Array,
|
||||||
uint8ArrayToObject,
|
uint8ArrayToObject,
|
||||||
} from '../backgroundFunctions/encryption';
|
} from '../encryption/encryption';
|
||||||
import { useAtom, useSetAtom } from 'jotai';
|
import { useAtom, useSetAtom } from 'jotai';
|
||||||
|
|
||||||
function fetchFromLocalStorage(key) {
|
function fetchFromLocalStorage(key) {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
|
|
||||||
import Base58 from '../../deps/Base58';
|
import Base58 from '../../encryption/Base58';
|
||||||
import ed2curve from '../../deps/ed2curve';
|
import ed2curve from '../../encryption/ed2curve';
|
||||||
import nacl from '../../deps/nacl-fast';
|
import nacl from '../../encryption/nacl-fast';
|
||||||
import i18n from '../../i18n/i18n';
|
import i18n from '../../i18n/i18n';
|
||||||
|
|
||||||
export function base64ToUint8Array(base64: string) {
|
export function base64ToUint8Array(base64: string) {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
|
|
||||||
import { Buffer } from 'buffer';
|
import { Buffer } from 'buffer';
|
||||||
import Base58 from '../../deps/Base58';
|
import Base58 from '../../encryption/Base58';
|
||||||
import nacl from '../../deps/nacl-fast';
|
import nacl from '../../encryption/nacl-fast';
|
||||||
import utils from '../../utils/utils';
|
import utils from '../../utils/utils';
|
||||||
import { createEndpoint, getBaseApi } from '../../background';
|
import { createEndpoint, getBaseApi } from '../../background/background';
|
||||||
import { getData } from '../../utils/chromeStorage';
|
import { getData } from '../../utils/chromeStorage';
|
||||||
|
|
||||||
export async function reusableGet(endpoint) {
|
export async function reusableGet(endpoint) {
|
||||||
@ -30,6 +30,7 @@ async function reusablePost(endpoint, _body) {
|
|||||||
data = await response.clone().json();
|
data = await response.clone().json();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
data = await response.text();
|
data = await response.text();
|
||||||
|
<<<<<<< HEAD
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@ -70,6 +71,7 @@ async function uploadChunkWithRetry(endpoint, formData, index, maxRetries = 3) {
|
|||||||
await new Promise((res) => setTimeout(res, 10_000));
|
await new Promise((res) => setTimeout(res, 10_000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getKeyPair() {
|
async function getKeyPair() {
|
||||||
@ -87,6 +89,11 @@ export const publishData = async ({
|
|||||||
service,
|
service,
|
||||||
identifier,
|
identifier,
|
||||||
uploadType,
|
uploadType,
|
||||||
|
file,
|
||||||
|
service,
|
||||||
|
identifier,
|
||||||
|
uploadType,
|
||||||
|
isBase64,
|
||||||
filename,
|
filename,
|
||||||
withFee,
|
withFee,
|
||||||
title,
|
title,
|
||||||
@ -245,6 +252,7 @@ export const publishData = async ({
|
|||||||
return signAndProcessRes;
|
return signAndProcessRes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
const uploadData = async (registeredName: string, data: any, fee: number) => {
|
const uploadData = async (registeredName: string, data: any, fee: number) => {
|
||||||
console.log('data', uploadType, data);
|
console.log('data', uploadType, data);
|
||||||
let postBody = '';
|
let postBody = '';
|
||||||
@ -359,6 +367,82 @@ export const publishData = async ({
|
|||||||
|
|
||||||
const result = await response.text(); // Base58-encoded unsigned transaction
|
const result = await response.text(); // Base58-encoded unsigned transaction
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uploadData = async (registeredName: string, file: any, fee: number) => {
|
||||||
|
let postBody = '';
|
||||||
|
let urlSuffix = '';
|
||||||
|
|
||||||
|
if (file != null) {
|
||||||
|
// If we're sending zipped data, make sure to use the /zip version of the POST /arbitrary/* API
|
||||||
|
if (uploadType === 'zip') {
|
||||||
|
urlSuffix = '/zip';
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we're sending file data, use the /base64 version of the POST /arbitrary/* API
|
||||||
|
else if (uploadType === 'file') {
|
||||||
|
urlSuffix = '/base64';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Base64 encode the file to work around compatibility issues between javascript and java byte arrays
|
||||||
|
if (isBase64) {
|
||||||
|
postBody = file;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isBase64) {
|
||||||
|
let fileBuffer = new Uint8Array(await file.arrayBuffer());
|
||||||
|
postBody = Buffer.from(fileBuffer).toString('base64');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let uploadDataUrl = `/arbitrary/${service}/${registeredName}${urlSuffix}`;
|
||||||
|
if (identifier?.trim().length > 0) {
|
||||||
|
uploadDataUrl = `/arbitrary/${service}/${registeredName}/${identifier}${urlSuffix}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
uploadDataUrl = uploadDataUrl + `?fee=${fee}`;
|
||||||
|
|
||||||
|
if (filename != null && filename != 'undefined') {
|
||||||
|
uploadDataUrl =
|
||||||
|
uploadDataUrl + '&filename=' + encodeURIComponent(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (title != null && title != 'undefined') {
|
||||||
|
uploadDataUrl = uploadDataUrl + '&title=' + encodeURIComponent(title);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (description != null && description != 'undefined') {
|
||||||
|
uploadDataUrl =
|
||||||
|
uploadDataUrl + '&description=' + encodeURIComponent(description);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (category != null && category != 'undefined') {
|
||||||
|
uploadDataUrl =
|
||||||
|
uploadDataUrl + '&category=' + encodeURIComponent(category);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag1 != null && tag1 != 'undefined') {
|
||||||
|
uploadDataUrl = uploadDataUrl + '&tags=' + encodeURIComponent(tag1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag2 != null && tag2 != 'undefined') {
|
||||||
|
uploadDataUrl = uploadDataUrl + '&tags=' + encodeURIComponent(tag2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag3 != null && tag3 != 'undefined') {
|
||||||
|
uploadDataUrl = uploadDataUrl + '&tags=' + encodeURIComponent(tag3);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag4 != null && tag4 != 'undefined') {
|
||||||
|
uploadDataUrl = uploadDataUrl + '&tags=' + encodeURIComponent(tag4);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag5 != null && tag5 != 'undefined') {
|
||||||
|
uploadDataUrl = uploadDataUrl + '&tags=' + encodeURIComponent(tag5);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await reusablePost(uploadDataUrl, postBody);
|
||||||
|
>>>>>>> 2d01b3e (Create encryption folder and move files)
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -37,12 +37,17 @@ import {
|
|||||||
getAssetInfo,
|
getAssetInfo,
|
||||||
getPublicKey,
|
getPublicKey,
|
||||||
transferAsset,
|
transferAsset,
|
||||||
|
<<<<<<< HEAD
|
||||||
} from '../background';
|
} from '../background';
|
||||||
import {
|
import {
|
||||||
getAllUserNames,
|
getAllUserNames,
|
||||||
getNameInfo,
|
getNameInfo,
|
||||||
uint8ArrayToObject,
|
uint8ArrayToObject,
|
||||||
} from '../backgroundFunctions/encryption';
|
} from '../backgroundFunctions/encryption';
|
||||||
|
=======
|
||||||
|
} from '../background/background.ts';
|
||||||
|
import { getNameInfo, uint8ArrayToObject } from '../encryption/encryption.ts';
|
||||||
|
>>>>>>> 2d01b3e (Create encryption folder and move files)
|
||||||
import { showSaveFilePicker } from '../hooks/useQortalMessageListener';
|
import { showSaveFilePicker } from '../hooks/useQortalMessageListener';
|
||||||
import { getPublishesFromAdminsAdminSpace } from '../components/Chat/AdminSpaceInner';
|
import { getPublishesFromAdminsAdminSpace } from '../components/Chat/AdminSpaceInner';
|
||||||
import { extractComponents } from '../components/Chat/MessageDisplay';
|
import { extractComponents } from '../components/Chat/MessageDisplay';
|
||||||
@ -53,9 +58,9 @@ import {
|
|||||||
validateSecretKey,
|
validateSecretKey,
|
||||||
} from '../components/Group/Group';
|
} from '../components/Group/Group';
|
||||||
import { QORT_DECIMALS } from '../constants/constants';
|
import { QORT_DECIMALS } from '../constants/constants';
|
||||||
import Base58 from '../deps/Base58';
|
import Base58 from '../encryption/Base58.ts';
|
||||||
import ed2curve from '../deps/ed2curve';
|
import ed2curve from '../encryption/ed2curve.ts';
|
||||||
import nacl from '../deps/nacl-fast';
|
import nacl from '../encryption/nacl-fast.ts';
|
||||||
import {
|
import {
|
||||||
base64ToUint8Array,
|
base64ToUint8Array,
|
||||||
createSymmetricKeyAndNonce,
|
createSymmetricKeyAndNonce,
|
||||||
@ -74,7 +79,7 @@ import {
|
|||||||
getPermission,
|
getPermission,
|
||||||
isRunningGateway,
|
isRunningGateway,
|
||||||
setPermission,
|
setPermission,
|
||||||
} from '../qortalRequests';
|
} from './qortalRequests.ts';
|
||||||
import TradeBotCreateRequest from '../transactions/TradeBotCreateRequest';
|
import TradeBotCreateRequest from '../transactions/TradeBotCreateRequest';
|
||||||
import DeleteTradeOffer from '../transactions/TradeBotDeleteRequest';
|
import DeleteTradeOffer from '../transactions/TradeBotDeleteRequest';
|
||||||
import signTradeBotTransaction from '../transactions/signTradeBotTransaction';
|
import signTradeBotTransaction from '../transactions/signTradeBotTransaction';
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { gateways, getApiKeyFromStorage } from './background';
|
import { gateways, getApiKeyFromStorage } from '../background/background.ts';
|
||||||
import { listOfAllQortalRequests } from './hooks/useQortalMessageListener';
|
import { listOfAllQortalRequests } from '../hooks/useQortalMessageListener.tsx';
|
||||||
import {
|
import {
|
||||||
addForeignServer,
|
addForeignServer,
|
||||||
addGroupAdminRequest,
|
addGroupAdminRequest,
|
||||||
@ -63,9 +63,9 @@ import {
|
|||||||
signForeignFees,
|
signForeignFees,
|
||||||
multiPaymentWithPrivateData,
|
multiPaymentWithPrivateData,
|
||||||
transferAssetRequest,
|
transferAssetRequest,
|
||||||
} from './qortalRequests/get';
|
} from './get.ts';
|
||||||
import { getData, storeData } from './utils/chromeStorage';
|
import { getData, storeData } from '../utils/chromeStorage.ts';
|
||||||
import { executeEvent } from './utils/events';
|
import { executeEvent } from '../utils/events.ts';
|
||||||
|
|
||||||
function getLocalStorage(key) {
|
function getLocalStorage(key) {
|
||||||
return getData(key).catch((error) => {
|
return getData(key).catch((error) => {
|
@ -1,8 +1,8 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
|
|
||||||
import { QORT_DECIMALS, TX_TYPES } from '../constants/constants';
|
import { QORT_DECIMALS, TX_TYPES } from '../constants/constants';
|
||||||
import nacl from '../deps/nacl-fast';
|
import nacl from '../encryption/nacl-fast';
|
||||||
import Base58 from '../deps/Base58';
|
import Base58 from '../encryption/Base58';
|
||||||
import utils from '../utils/utils';
|
import utils from '../utils/utils';
|
||||||
export default class ChatBase {
|
export default class ChatBase {
|
||||||
static get utils() {
|
static get utils() {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
|
|
||||||
import ChatBase from './ChatBase';
|
import ChatBase from './ChatBase';
|
||||||
import nacl from '../deps/nacl-fast';
|
import nacl from '../encryption/nacl-fast';
|
||||||
import ed2curve from '../deps/ed2curve';
|
import ed2curve from '../encryption/ed2curve';
|
||||||
import { Sha256 } from 'asmcrypto.js';
|
import { Sha256 } from 'asmcrypto.js';
|
||||||
import { CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP } from '../constants/constants';
|
import { CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP } from '../constants/constants';
|
||||||
export default class ChatTransaction extends ChatBase {
|
export default class ChatTransaction extends ChatBase {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
|
|
||||||
import { DYNAMIC_FEE_TIMESTAMP } from '../constants/constants';
|
import { DYNAMIC_FEE_TIMESTAMP } from '../constants/constants';
|
||||||
import Base58 from '../deps/Base58';
|
import Base58 from '../encryption/Base58';
|
||||||
import publicKeyToAddress from '../utils/generateWallet/publicKeyToAddress';
|
import publicKeyToAddress from '../utils/generateWallet/publicKeyToAddress';
|
||||||
import TransactionBase from './TransactionBase';
|
import TransactionBase from './TransactionBase';
|
||||||
export default class RemoveRewardShareTransaction extends TransactionBase {
|
export default class RemoveRewardShareTransaction extends TransactionBase {
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
import TransactionBase from './TransactionBase';
|
import TransactionBase from './TransactionBase';
|
||||||
import { Sha256 } from 'asmcrypto.js';
|
import { Sha256 } from 'asmcrypto.js';
|
||||||
import nacl from '../deps/nacl-fast';
|
import nacl from '../encryption/nacl-fast';
|
||||||
import ed2curve from '../deps/ed2curve';
|
import ed2curve from '../encryption/ed2curve';
|
||||||
import { DYNAMIC_FEE_TIMESTAMP } from '../constants/constants';
|
import { DYNAMIC_FEE_TIMESTAMP } from '../constants/constants';
|
||||||
import publicKeyToAddress from '../utils/generateWallet/publicKeyToAddress';
|
import publicKeyToAddress from '../utils/generateWallet/publicKeyToAddress';
|
||||||
export default class RewardShareTransaction extends TransactionBase {
|
export default class RewardShareTransaction extends TransactionBase {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
|
|
||||||
import nacl from '../deps/nacl-fast';
|
import nacl from '../encryption/nacl-fast.js';
|
||||||
import Base58 from '../deps/Base58';
|
import Base58 from '../encryption/Base58.js';
|
||||||
import utils from '../utils/utils';
|
import utils from '../utils/utils';
|
||||||
import { QORT_DECIMALS, TX_TYPES } from '../constants/constants.js';
|
import { QORT_DECIMALS, TX_TYPES } from '../constants/constants.js';
|
||||||
export default class TransactionBase {
|
export default class TransactionBase {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
|
|
||||||
import nacl from '../deps/nacl-fast';
|
import nacl from '../encryption/nacl-fast';
|
||||||
import utils from '../utils/utils';
|
import utils from '../utils/utils';
|
||||||
|
|
||||||
export const signChat = (chatBytes, nonce, keyPair) => {
|
export const signChat = (chatBytes, nonce, keyPair) => {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
|
|
||||||
import nacl from '../deps/nacl-fast';
|
import nacl from '../encryption/nacl-fast';
|
||||||
import Base58 from '../deps/Base58';
|
import Base58 from '../encryption/Base58';
|
||||||
import utils from '../utils/utils';
|
import utils from '../utils/utils';
|
||||||
|
|
||||||
const signTradeBotTransaction = async (unsignedTxn, keyPair) => {
|
const signTradeBotTransaction = async (unsignedTxn, keyPair) => {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
|
|
||||||
import Base58 from '../deps/Base58';
|
import Base58 from '../encryption/Base58';
|
||||||
import ed2curve from '../deps/ed2curve';
|
import ed2curve from '../encryption/ed2curve';
|
||||||
import nacl from '../deps/nacl-fast';
|
import nacl from '../encryption/nacl-fast';
|
||||||
import { Sha256 } from 'asmcrypto.js';
|
import { Sha256 } from 'asmcrypto.js';
|
||||||
|
|
||||||
export const decryptChatMessage = (
|
export const decryptChatMessage = (
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
|
|
||||||
import { crypto } from '../constants/decryptWallet';
|
import { crypto } from '../constants/decryptWallet';
|
||||||
import Base58 from '../deps/Base58';
|
import Base58 from '../encryption/Base58';
|
||||||
import { AES_CBC, HmacSha512 } from 'asmcrypto.js';
|
import { AES_CBC, HmacSha512 } from 'asmcrypto.js';
|
||||||
import { doInitWorkers, kdf } from '../deps/kdf';
|
import { doInitWorkers, kdf } from '../encryption/kdf';
|
||||||
import i18n from 'i18next';
|
import i18n from 'i18next';
|
||||||
|
|
||||||
export const decryptStoredWallet = async (password, wallet) => {
|
export const decryptStoredWallet = async (password, wallet) => {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
|
|
||||||
import { crypto, walletVersion } from '../../constants/decryptWallet';
|
import { crypto, walletVersion } from '../../constants/decryptWallet';
|
||||||
import { doInitWorkers, kdf } from '../../deps/kdf';
|
import { doInitWorkers, kdf } from '../../encryption/kdf';
|
||||||
import PhraseWallet from './phrase-wallet';
|
import PhraseWallet from './phrase-wallet';
|
||||||
import * as WORDLISTS from './wordlists';
|
import * as WORDLISTS from './wordlists';
|
||||||
import FileSaver from 'file-saver';
|
import FileSaver from 'file-saver';
|
||||||
|
@ -3,208 +3,206 @@
|
|||||||
Copyright 2017-2018 @ irontiga and vbcs (original developer)
|
Copyright 2017-2018 @ irontiga and vbcs (original developer)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Base58 from '../../deps/Base58'
|
import Base58 from '../../encryption/Base58.js';
|
||||||
import {Sha256, Sha512} from 'asmcrypto.js'
|
import { Sha256, Sha512 } from 'asmcrypto.js';
|
||||||
import nacl from '../../deps/nacl-fast'
|
import nacl from '../../encryption/nacl-fast.js';
|
||||||
import utils from '../../utils/utils'
|
import utils from '../../utils/utils';
|
||||||
|
|
||||||
import {generateSaveWalletData} from './storeWallet.js'
|
import { generateSaveWalletData } from './storeWallet.js';
|
||||||
|
|
||||||
import publicKeyToAddress from './publicKeyToAddress'
|
import publicKeyToAddress from './publicKeyToAddress';
|
||||||
import AltcoinHDWallet from "../../deps/AltcoinHDWallet"
|
import AltcoinHDWallet from '../../encryption/AltcoinHDWallet.js';
|
||||||
|
|
||||||
export default class PhraseWallet {
|
export default class PhraseWallet {
|
||||||
constructor(seed, walletVersion) {
|
constructor(seed, walletVersion) {
|
||||||
|
this._walletVersion = walletVersion || 2;
|
||||||
|
this.seed = seed;
|
||||||
|
|
||||||
this._walletVersion = walletVersion || 2
|
this.savedSeedData = {};
|
||||||
this.seed = seed
|
this.hasBeenSaved = false;
|
||||||
|
}
|
||||||
|
|
||||||
this.savedSeedData = {}
|
set seed(seed) {
|
||||||
this.hasBeenSaved = false
|
this._byteSeed = seed;
|
||||||
}
|
this._base58Seed = Base58.encode(seed);
|
||||||
|
|
||||||
set seed(seed) {
|
this._addresses = [];
|
||||||
this._byteSeed = seed
|
|
||||||
this._base58Seed = Base58.encode(seed)
|
|
||||||
|
|
||||||
this._addresses = []
|
this.genAddress(0);
|
||||||
|
}
|
||||||
|
|
||||||
this.genAddress(0)
|
getAddress(nonce) {
|
||||||
}
|
return this._addresses[nonce];
|
||||||
|
}
|
||||||
|
|
||||||
getAddress(nonce) {
|
get addresses() {
|
||||||
return this._addresses[nonce]
|
return this._addresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
get addresses() {
|
get addressIDs() {
|
||||||
return this._addresses
|
return this._addresses.map((addr) => {
|
||||||
}
|
return addr.address;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
get addressIDs() {
|
get seed() {
|
||||||
return this._addresses.map(addr => {
|
return this._byteSeed;
|
||||||
return addr.address
|
}
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
get seed() {
|
addressExists(nonce) {
|
||||||
return this._byteSeed
|
return this._addresses[nonce] != undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
addressExists(nonce) {
|
_genAddressSeed(seed) {
|
||||||
return this._addresses[nonce] != undefined
|
let newSeed = new Sha512().process(seed).finish().result;
|
||||||
}
|
newSeed = new Sha512()
|
||||||
|
.process(utils.appendBuffer(newSeed, seed))
|
||||||
|
.finish().result;
|
||||||
|
return newSeed;
|
||||||
|
}
|
||||||
|
|
||||||
_genAddressSeed(seed) {
|
genAddress(nonce) {
|
||||||
let newSeed = new Sha512().process(seed).finish().result
|
if (nonce >= this._addresses.length) {
|
||||||
newSeed = new Sha512().process(utils.appendBuffer(newSeed, seed)).finish().result
|
this._addresses.length = nonce + 1;
|
||||||
return newSeed
|
}
|
||||||
}
|
|
||||||
|
|
||||||
genAddress(nonce) {
|
if (this.addressExists(nonce)) {
|
||||||
if (nonce >= this._addresses.length) {
|
return this.addresses[nonce];
|
||||||
this._addresses.length = nonce + 1
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (this.addressExists(nonce)) {
|
const nonceBytes = utils.int32ToBytes(nonce);
|
||||||
return this.addresses[nonce]
|
|
||||||
}
|
|
||||||
|
|
||||||
const nonceBytes = utils.int32ToBytes(nonce)
|
let addrSeed = new Uint8Array();
|
||||||
|
addrSeed = utils.appendBuffer(addrSeed, nonceBytes);
|
||||||
|
addrSeed = utils.appendBuffer(addrSeed, this._byteSeed);
|
||||||
|
addrSeed = utils.appendBuffer(addrSeed, nonceBytes);
|
||||||
|
|
||||||
let addrSeed = new Uint8Array()
|
if (this._walletVersion == 1) {
|
||||||
addrSeed = utils.appendBuffer(addrSeed, nonceBytes)
|
addrSeed = new Sha256()
|
||||||
addrSeed = utils.appendBuffer(addrSeed, this._byteSeed)
|
.process(new Sha256().process(addrSeed).finish().result)
|
||||||
addrSeed = utils.appendBuffer(addrSeed, nonceBytes)
|
.finish().result;
|
||||||
|
|
||||||
if (this._walletVersion == 1) {
|
addrSeed = this._byteSeed;
|
||||||
addrSeed = new Sha256().process(
|
} else {
|
||||||
new Sha256()
|
addrSeed = this._genAddressSeed(addrSeed).slice(0, 32);
|
||||||
.process(addrSeed)
|
}
|
||||||
.finish()
|
|
||||||
.result
|
|
||||||
).finish().result
|
|
||||||
|
|
||||||
addrSeed = this._byteSeed
|
const addrKeyPair = nacl.sign.keyPair.fromSeed(new Uint8Array(addrSeed));
|
||||||
} else {
|
|
||||||
addrSeed = this._genAddressSeed(addrSeed).slice(0, 32)
|
|
||||||
}
|
|
||||||
|
|
||||||
const addrKeyPair = nacl.sign.keyPair.fromSeed(new Uint8Array(addrSeed));
|
const address = publicKeyToAddress(addrKeyPair.publicKey);
|
||||||
|
const qoraAddress = publicKeyToAddress(addrKeyPair.publicKey, true);
|
||||||
|
|
||||||
const address = publicKeyToAddress(addrKeyPair.publicKey);
|
// Create Bitcoin HD Wallet
|
||||||
const qoraAddress = publicKeyToAddress(addrKeyPair.publicKey, true);
|
const btcSeed = [...addrSeed];
|
||||||
|
const btcWallet = new AltcoinHDWallet({
|
||||||
|
mainnet: {
|
||||||
|
private: 0x0488ade4,
|
||||||
|
public: 0x0488b21e,
|
||||||
|
prefix: 0,
|
||||||
|
},
|
||||||
|
testnet: {
|
||||||
|
private: 0x04358394,
|
||||||
|
public: 0x043587cf,
|
||||||
|
prefix: 0x6f,
|
||||||
|
},
|
||||||
|
}).createWallet(new Uint8Array(btcSeed), false);
|
||||||
|
|
||||||
// Create Bitcoin HD Wallet
|
// Create Litecoin HD Wallet
|
||||||
const btcSeed = [...addrSeed];
|
const ltcSeed = [...addrSeed];
|
||||||
const btcWallet = new AltcoinHDWallet({
|
const ltcWallet = new AltcoinHDWallet({
|
||||||
mainnet: {
|
mainnet: {
|
||||||
private: 0x0488ADE4,
|
private: 0x0488ade4,
|
||||||
public: 0x0488B21E,
|
public: 0x0488b21e,
|
||||||
prefix: 0
|
prefix: 0x30,
|
||||||
},
|
},
|
||||||
testnet: {
|
testnet: {
|
||||||
private: 0x04358394,
|
private: 0x04358394,
|
||||||
public: 0x043587CF,
|
public: 0x043587cf,
|
||||||
prefix: 0x6F
|
prefix: 0x6f,
|
||||||
}
|
},
|
||||||
}).createWallet(new Uint8Array(btcSeed), false);
|
}).createWallet(new Uint8Array(ltcSeed), false, 'LTC');
|
||||||
|
|
||||||
// Create Litecoin HD Wallet
|
// Create Dogecoin HD Wallet
|
||||||
const ltcSeed = [...addrSeed];
|
const dogeSeed = [...addrSeed];
|
||||||
const ltcWallet = new AltcoinHDWallet({
|
const dogeWallet = new AltcoinHDWallet({
|
||||||
mainnet: {
|
mainnet: {
|
||||||
private: 0x0488ADE4,
|
private: 0x02fac398,
|
||||||
public: 0x0488B21E,
|
public: 0x02facafd,
|
||||||
prefix: 0x30
|
prefix: 0x1e,
|
||||||
},
|
},
|
||||||
testnet: {
|
testnet: {
|
||||||
private: 0x04358394,
|
private: 0x04358394,
|
||||||
public: 0x043587CF,
|
public: 0x043587cf,
|
||||||
prefix: 0x6F
|
prefix: 0x71,
|
||||||
}
|
},
|
||||||
}).createWallet(new Uint8Array(ltcSeed), false, 'LTC');
|
}).createWallet(new Uint8Array(dogeSeed), false, 'DOGE');
|
||||||
|
|
||||||
// Create Dogecoin HD Wallet
|
// Create Digibyte HD Wallet
|
||||||
const dogeSeed = [...addrSeed];
|
const dgbSeed = [...addrSeed];
|
||||||
const dogeWallet = new AltcoinHDWallet({
|
const dgbWallet = new AltcoinHDWallet({
|
||||||
mainnet: {
|
mainnet: {
|
||||||
private: 0x02FAC398,
|
private: 0x0488ade4,
|
||||||
public: 0x02FACAFD,
|
public: 0x0488b21e,
|
||||||
prefix: 0x1E
|
prefix: 0x1e,
|
||||||
},
|
},
|
||||||
testnet: {
|
testnet: {
|
||||||
private: 0x04358394,
|
private: 0x04358394,
|
||||||
public: 0x043587CF,
|
public: 0x043587cf,
|
||||||
prefix: 0x71
|
prefix: 0x7e,
|
||||||
}
|
},
|
||||||
}).createWallet(new Uint8Array(dogeSeed), false, 'DOGE');
|
}).createWallet(new Uint8Array(dgbSeed), false, 'DGB');
|
||||||
|
|
||||||
// Create Digibyte HD Wallet
|
// Create Ravencoin HD Wallet
|
||||||
const dgbSeed = [...addrSeed];
|
const rvnSeed = [...addrSeed];
|
||||||
const dgbWallet = new AltcoinHDWallet({
|
const rvnWallet = new AltcoinHDWallet({
|
||||||
mainnet: {
|
mainnet: {
|
||||||
private: 0x0488ADE4,
|
private: 0x0488ade4,
|
||||||
public: 0x0488B21E,
|
public: 0x0488b21e,
|
||||||
prefix: 0x1E
|
prefix: 0x3c,
|
||||||
},
|
},
|
||||||
testnet: {
|
testnet: {
|
||||||
private: 0x04358394,
|
private: 0x04358394,
|
||||||
public: 0x043587CF,
|
public: 0x043587cf,
|
||||||
prefix: 0x7E
|
prefix: 0x6f,
|
||||||
}
|
},
|
||||||
}).createWallet(new Uint8Array(dgbSeed), false, 'DGB');
|
}).createWallet(new Uint8Array(rvnSeed), false, 'RVN');
|
||||||
|
|
||||||
// Create Ravencoin HD Wallet
|
// Create Pirate Chain HD Wallet
|
||||||
const rvnSeed = [...addrSeed];
|
const arrrSeed = [...addrSeed];
|
||||||
const rvnWallet = new AltcoinHDWallet({
|
const arrrWallet = new AltcoinHDWallet({
|
||||||
mainnet: {
|
mainnet: {
|
||||||
private: 0x0488ADE4,
|
private: 0x0488ade4,
|
||||||
public: 0x0488B21E,
|
public: 0x0488b21e,
|
||||||
prefix: 0x3C
|
prefix: [0x16, 0x9a],
|
||||||
},
|
},
|
||||||
testnet: {
|
testnet: {
|
||||||
private: 0x04358394,
|
private: 0x04358394,
|
||||||
public: 0x043587CF,
|
public: 0x043587cf,
|
||||||
prefix: 0x6F
|
prefix: [0x14, 0x51],
|
||||||
}
|
},
|
||||||
}).createWallet(new Uint8Array(rvnSeed), false, 'RVN');
|
}).createWallet(new Uint8Array(arrrSeed), false, 'ARRR');
|
||||||
|
|
||||||
// Create Pirate Chain HD Wallet
|
this._addresses[nonce] = {
|
||||||
const arrrSeed = [...addrSeed];
|
address,
|
||||||
const arrrWallet = new AltcoinHDWallet({
|
btcWallet,
|
||||||
mainnet: {
|
ltcWallet,
|
||||||
private: 0x0488ADE4,
|
dogeWallet,
|
||||||
public: 0x0488B21E,
|
dgbWallet,
|
||||||
prefix: [0x16, 0x9A]
|
rvnWallet,
|
||||||
},
|
arrrWallet,
|
||||||
testnet: {
|
qoraAddress,
|
||||||
private: 0x04358394,
|
keyPair: {
|
||||||
public: 0x043587CF,
|
publicKey: addrKeyPair.publicKey,
|
||||||
prefix: [0x14, 0x51]
|
privateKey: addrKeyPair.secretKey,
|
||||||
}
|
},
|
||||||
}).createWallet(new Uint8Array(arrrSeed), false, 'ARRR');
|
base58PublicKey: Base58.encode(addrKeyPair.publicKey),
|
||||||
|
seed: addrSeed,
|
||||||
|
nonce: nonce,
|
||||||
|
};
|
||||||
|
return this._addresses[nonce];
|
||||||
|
}
|
||||||
|
|
||||||
this._addresses[nonce] = {
|
generateSaveWalletData(...args) {
|
||||||
address,
|
return generateSaveWalletData(this, ...args);
|
||||||
btcWallet,
|
}
|
||||||
ltcWallet,
|
|
||||||
dogeWallet,
|
|
||||||
dgbWallet,
|
|
||||||
rvnWallet,
|
|
||||||
arrrWallet,
|
|
||||||
qoraAddress,
|
|
||||||
keyPair: {
|
|
||||||
publicKey: addrKeyPair.publicKey,
|
|
||||||
privateKey: addrKeyPair.secretKey
|
|
||||||
},
|
|
||||||
base58PublicKey: Base58.encode(addrKeyPair.publicKey),
|
|
||||||
seed: addrSeed,
|
|
||||||
nonce: nonce
|
|
||||||
}
|
|
||||||
return this._addresses[nonce]
|
|
||||||
}
|
|
||||||
|
|
||||||
generateSaveWalletData(...args) {
|
|
||||||
return generateSaveWalletData(this, ...args)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import Base58 from '../../deps/Base58';
|
import Base58 from '../../encryption/Base58.js';
|
||||||
import BROKEN_RIPEMD160 from '../../deps/broken-ripemd160';
|
import BROKEN_RIPEMD160 from '../../encryption/broken-ripemd160.js';
|
||||||
import RIPEMD160 from '../../deps/ripemd160';
|
import RIPEMD160 from '../../encryption/ripemd160.js';
|
||||||
import utils from '../../utils/utils';
|
import utils from '../../utils/utils';
|
||||||
import { Buffer } from 'buffer';
|
import { Buffer } from 'buffer';
|
||||||
import { Sha256 } from 'asmcrypto.js';
|
import { Sha256 } from 'asmcrypto.js';
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
|
|
||||||
import { AES_CBC, HmacSha512 } from 'asmcrypto.js';
|
import { AES_CBC, HmacSha512 } from 'asmcrypto.js';
|
||||||
import Base58 from '../../deps/Base58';
|
import Base58 from '../../encryption/Base58.js';
|
||||||
import { doInitWorkers, kdf } from '../../deps/kdf.js';
|
import { doInitWorkers, kdf } from '../../encryption/kdf.js';
|
||||||
import { crypto as cryptoVals } from '../../constants/decryptWallet.js';
|
import { crypto as cryptoVals } from '../../constants/decryptWallet.js';
|
||||||
|
|
||||||
const getRandomValues = crypto
|
const getRandomValues = crypto
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
|
|
||||||
import Base58 from '../deps/Base58';
|
import Base58 from '../encryption/Base58';
|
||||||
|
|
||||||
export const validateAddress = (address) => {
|
export const validateAddress = (address) => {
|
||||||
let isAddress = false;
|
let isAddress = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user