Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private seedValidate ({ suri, type }: RequestSeedValidate): ResponseSeedValidate {
const { phrase } = keyExtractSuri(suri);
if (isHex(phrase)) {
assert(isHex(phrase, 256), 'Hex seed needs to be 256-bits');
} else {
// sadly isHex detects as string, so we need a cast here
assert(SEED_LENGTHS.includes((phrase as string).split(' ').length), `Mnemonic needs to contain ${SEED_LENGTHS.join(', ')} words`);
assert(mnemonicValidate(phrase), 'Not a valid mnemonic seed');
}
return {
address: keyring.createFromUri(suri, {}, type).address,
suri
};
}
useEffect(() => {
const allAddressessub = combineLatest([
// eslint-disable-next-line @typescript-eslint/unbound-method
accountObservable.subject.pipe(map(Object.values)),
// eslint-disable-next-line @typescript-eslint/unbound-method
addressObservable.subject.pipe(map(Object.values))
])
.pipe(map(flatten))
.subscribe(setAllAddresses);
return (): void => {
allAddressessub.unsubscribe();
};
}, []);
.then((): void => {
console.log('crypto initialized');
// load all the keyring data
keyring.loadAll({ store: new ExtensionStore(), type: 'sr25519' });
console.log('initialization completed');
})
.catch((error): void => {
const systemChain = _systemChain
? _systemChain.toString()
: '';
const isDevelopment = isTestChain(systemChain);
console.log('api: found chain', systemChain, JSON.stringify(properties));
// first setup the UI helpers
formatBalance.setDefaults({
decimals: tokenDecimals,
unit: tokenSymbol
});
TokenUnit.setAbbr(tokenSymbol);
// finally load the keyring
keyring.loadAll({
addressPrefix: ss58Format,
genesisHash: api.genesisHash,
isDevelopment,
ss58Format,
type: 'ed25519'
}, injectedAccounts);
const defaultSection = Object.keys(api.tx)[0];
const defaultMethod = Object.keys(api.tx[defaultSection])[0];
const apiDefaultTx = api.tx[defaultSection][defaultMethod];
const apiDefaultTxSudo =
(api.tx.system && api.tx.system.setCode) || // 2.x
(api.tx.consensus && api.tx.consensus.setCode) || // 1.x
apiDefaultTx; // other
const isSubstrateV2 = !!Object.keys(api.consts).length;
useEffect(() => {
const allAddressessub = combineLatest([
// eslint-disable-next-line @typescript-eslint/unbound-method
accountObservable.subject.pipe(map(Object.values)),
// eslint-disable-next-line @typescript-eslint/unbound-method
addressObservable.subject.pipe(map(Object.values))
])
.pipe(map(flatten))
.subscribe(setAllAddresses);
return (): void => {
allAddressessub.unsubscribe();
};
}, []);
const unlockError = this.unlockAccount(accountId as string, password);
if (unlockError) {
this.setState({ unlockError });
return;
}
}
if (payload) {
return makeExtrinsicSignature(
{
...payload,
...((isV2 && tip && !payload.tip) ? { tip: tip.toString() } : {})
},
queueTx,
keyring.getPair(accountId as string)
);
}
const submittable = extrinsic as SubmittableExtrinsic;
assert(submittable, 'Expected an extrinsic to be supplied to sendExtrinsic');
return isUnsigned
// eslint-disable-next-line @typescript-eslint/unbound-method
? this.makeExtrinsicCall(submittable, queueTx, submittable.send)
// eslint-disable-next-line @typescript-eslint/unbound-method
: this.makeExtrinsicCall(submittable, queueTx, submittable.signAndSend, keyring.getPair(accountId as string));
}
...((isV2 && tip && !payload.tip) ? { tip: tip.toString() } : {})
},
queueTx,
keyring.getPair(accountId as string)
);
}
const submittable = extrinsic as SubmittableExtrinsic;
assert(submittable, 'Expected an extrinsic to be supplied to sendExtrinsic');
return isUnsigned
// eslint-disable-next-line @typescript-eslint/unbound-method
? this.makeExtrinsicCall(submittable, queueTx, submittable.send)
// eslint-disable-next-line @typescript-eslint/unbound-method
: this.makeExtrinsicCall(submittable, queueTx, submittable.signAndSend, keyring.getPair(accountId as string));
}
useEffect(() => {
// eslint-disable-next-line @typescript-eslint/unbound-method
const accountsSub = accounts.subject.pipe(map(Object.values)).subscribe(values => {
const stash = values.filter(value =>
fromNullable(value.json.meta.tags)
.map(tags => tags.includes('stash'))
.getOrElse(undefined)
)[0];
const _messageToSign = fromNullable(stash)
.map(stash => `Pay KSMs to the Kusama account: ${stash.json.address}`)
.getOrElse('');
setMessageToSign(_messageToSign);
});
return (): void => accountsSub.unsubscribe();
}, []);
useEffect(() => {
// eslint-disable-next-line @typescript-eslint/unbound-method
const accountsSub = accounts.subject.pipe(map(Object.values)).subscribe(values => {
const _controller = values.filter(value => value.json.meta.tags && value.json.meta.tags.includes('controller'))[0];
const _stash = values.filter(value => value.json.meta.tags && value.json.meta.tags.includes('stash'))[0];
setController(_controller);
setStash(_stash);
});
return (): void => accountsSub.unsubscribe();
}, []);
useEffect(() => {
const accountsSub = accounts.subject
// eslint-disable-next-line @typescript-eslint/unbound-method
.pipe(map(Object.values), map(head))
.subscribe(setDefaultAccount);
return (): void => accountsSub.unsubscribe();
}, [api]);