Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
createUnsignedTxn() {
const { state, props } = this;
const validContracts = need.contracts(props.contracts);
const validPoint = need.point(props.pointCursor);
// TODO: move this to a lib for validating things
const hexRegExp = /[0-9A-Fa-f]{64}/g;
if (hexRegExp.test(state.newNetworkSeed)) {
// derive network keys
const pair = kg.deriveNetworkKeys(state.newNetworkSeed);
const pencr = addHexPrefix(pair.crypt.public);
const pauth = addHexPrefix(pair.auth.public);
const txn = azimuth.ecliptic.configureKeys(
validContracts,
validPoint,
pencr,
pauth,
1,
state.discontinuity
);
return Just(txn);
}
export const generateWallet = async (point, ticket, boot) => {
const config = {
ticket: ticket,
seedSize: SEED_LENGTH_BYTES,
ship: point,
password: '',
revisions: {},
boot: boot,
};
// This is here to notify anyone who opens console because the thread
// hangs, blocking UI updates so this cannot be done in the UI
console.log('Generating Wallet for point address: ', point);
const wallet = await kg.generateWallet(config);
return wallet;
};
const deriveNetworkSeedFromMnemonic = async (
mnemonic,
passphrase,
revision
) => {
//NOTE revision is the point's on-chain revision number. since common uhdw
// usage derives the first key at revision/index 0, we need to decrement
// the on-chain revision number by one to get the number to derive with.
return Just(await kg.deriveNetworkSeed(mnemonic, passphrase, revision - 1));
};
async walletFromShards(shard1, shard2, shard3, pointName, passphrase) {
const s1 = shard1 === '' ? undefined : shard1;
const s2 = shard2 === '' ? undefined : shard2;
const s3 = shard3 === '' ? undefined : shard3;
let ticket = undefined;
try {
ticket = kg.combine([s1, s2, s3]);
} catch (_) {
// do nothing
}
if (ticket !== undefined) {
const uhdw = await urbitWalletFromTicket(ticket, pointName, passphrase);
this.props.setUrbitWallet(Just(uhdw));
}
}
async values => {
const ticket = values.useShards
? kg.combine([values.shard1, values.shard2, values.shard3])
: values.ticket;
try {
const _contracts = need.contracts(contracts);
const point = patp2dec(values.point);
await timeout(16); // allow ui events to flush
const urbitWallet = await urbitWalletFromTicket(
ticket,
point,
values.passphrase
);
const [isOwner, isTransferProxy] = await Promise.all([
azimuth.azimuth.isOwner(
_contracts,
const walletFromShards = async () => {
const s1 = shard1 === '' ? undefined : shard1;
const s2 = shard2 === '' ? undefined : shard2;
const s3 = shard3 === '' ? undefined : shard3;
let ticket = undefined;
try {
ticket = kg.combine([s1, s2, s3]);
} catch (_) {
// do nothing
}
if (ticket !== undefined) {
const uhdw = await urbitWalletFromTicket(ticket, pointName, passphrase);
setUrbitWallet(Just(uhdw));
}
};
checkKeysMatch(networkSeed, pointDetails) {
const crypub = pointDetails.encryptionKey;
const sgnpub = pointDetails.authenticationKey;
const { crypt, auth } = kg.deriveNetworkKeys(networkSeed);
const keysmatch =
crypub === addHexPrefix(crypt.public) &&
sgnpub === addHexPrefix(auth.public);
return keysmatch;
}
export const urbitWalletFromTicket = async (ticket, point, passphrase) => {
return await kg.generateWallet({
ticket: ticket,
ship: point,
passphrase: passphrase,
});
};
export const deriveNetworkKeys = seed => kg.deriveNetworkKeys(seed);
export const generateOwnershipWallet = (ship, ticket) =>
kg.generateOwnershipWallet({ ship, ticket });