XO Wallet Integration Part IV
This commit is contained in:
@@ -13,11 +13,8 @@ import {
|
||||
Mnemonic,
|
||||
calculateBalanceSats,
|
||||
calculateBalanceTokens,
|
||||
encodeExtendedJson,
|
||||
} from '@xocash/primitives';
|
||||
|
||||
import { hash256, binToHex, hexToBin, utf8ToBin } from '@bitauth/libauth';
|
||||
|
||||
export const DERIVATION_PATH = "m/44'/145'/0'";
|
||||
export const ADDRESS_GAP = 20;
|
||||
|
||||
@@ -112,7 +109,7 @@ export class WalletHD extends BaseWallet {
|
||||
|
||||
// Instantiate the HDPrivateNode from the type specified in our genesis data.
|
||||
if ('seed' in genesisData) {
|
||||
this.hdPrivateNode = HDPrivateNode.fromSeed(hexToBin(genesisData.seed));
|
||||
this.hdPrivateNode = HDPrivateNode.fromSeed(genesisData.seed);
|
||||
} else if ('mnemonic' in genesisData) {
|
||||
this.hdPrivateNode = HDPrivateNode.fromMnemonic(
|
||||
Mnemonic.fromPhrase(genesisData.mnemonic),
|
||||
@@ -126,40 +123,6 @@ export class WalletHD extends BaseWallet {
|
||||
this.wallets[CHAIN_INTERNAL] = [];
|
||||
}
|
||||
|
||||
async getId() {
|
||||
// NOTE: Use the cache to optimize future calls.
|
||||
return binToHex(
|
||||
await this.cache.getOrSet('walletId', async () =>
|
||||
this.deriveKey('walletId'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
async deriveKey(keyName: string): Promise<Uint8Array> {
|
||||
// Hash the genesis data using Hash256 and the key ("WalletID") for this derivation using Hash256.
|
||||
const genesisDataHashed = hash256(
|
||||
utf8ToBin(encodeExtendedJson(this.genesisData)),
|
||||
);
|
||||
const keyHashed = hash256(utf8ToBin(keyName));
|
||||
|
||||
// Combine the hashes and do one final hash for good measure.
|
||||
return hash256(new Uint8Array([...genesisDataHashed, ...keyHashed]));
|
||||
}
|
||||
|
||||
async getEncryptionKey() {
|
||||
// NOTE: Use the cache to optimize future calls.
|
||||
return await this.cache.getOrSet('encryptionKey', async () =>
|
||||
this.deriveKey('encryptionKey'),
|
||||
);
|
||||
}
|
||||
|
||||
async getSigningKey() {
|
||||
// NOTE: Use the cache to optimize future calls.
|
||||
return this.cache.getOrSet('signingKey', async () =>
|
||||
this.deriveKey('signingKey'),
|
||||
);
|
||||
}
|
||||
|
||||
async start() {
|
||||
// Get the address gap.
|
||||
// TODO: This should come from activities.
|
||||
|
||||
Reference in New Issue
Block a user