本文整理汇总了TypeScript中stellar-sdk.StrKey.isValidEd25519PublicKey方法的典型用法代码示例。如果您正苦于以下问题:TypeScript StrKey.isValidEd25519PublicKey方法的具体用法?TypeScript StrKey.isValidEd25519PublicKey怎么用?TypeScript StrKey.isValidEd25519PublicKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stellar-sdk.StrKey
的用法示例。
在下文中一共展示了StrKey.isValidEd25519PublicKey方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getAddressDetails
/**
* Process address into address and memo id
*
* @param address {String} the address
* @returns {Object} object containing address and memo id
*/
getAddressDetails(address) {
const destinationDetails = url.parse(address);
const queryDetails = querystring.parse(destinationDetails.query);
const destinationAddress = destinationDetails.pathname;
if (!stellar.StrKey.isValidEd25519PublicKey(destinationAddress)) {
throw new Error(`invalid address: ${address}`);
}
// address doesn't have a memo id
if (destinationDetails.pathname === address) {
return {
address: address,
memoId: null
};
}
if (!queryDetails.memoId) {
// if there are more properties, the query details need to contain the memo id property
throw new Error(`invalid address: ${address}`);
}
try {
new BigNumber(queryDetails.memoId);
} catch (e) {
throw new Error(`invalid address: ${address}`);
}
if (!this.isValidMemoId(queryDetails.memoId)) {
throw new Error(`invalid address: ${address}`);
}
return {
address: destinationAddress,
memoId: queryDetails.memoId
};
}
示例2: normalizeAddress
/**
* Validate and return address with appended memo id
*
* @param address {String} address
* @param memoId {String} memo id
* @returns {String} address with memo id
*/
normalizeAddress({ address, memoId }) {
if (!stellar.StrKey.isValidEd25519PublicKey(address)) {
throw new Error(`invalid address details: ${address}`);
}
if (this.isValidMemoId(memoId)) {
return `${address}?memoId=${memoId}`;
}
return address;
}
示例3: isValidPub
/**
* Return boolean indicating whether input is valid public key for the coin.
*
* @param {String} pub the pub to be checked
* @returns {Boolean} is it valid?
*/
isValidPub(pub) {
return stellar.StrKey.isValidEd25519PublicKey(pub);
}
示例4: co
return co(function *() {
const [userKey, backupKey] = this.initiateRecovery(params);
const isKrsRecovery = params.backupKey.startsWith('G') && !params.userKey.startsWith('G');
const isUnsignedSweep = params.backupKey.startsWith('G') && params.userKey.startsWith('G');
if (!stellar.StrKey.isValidEd25519PublicKey(params.rootAddress)) {
throw new Error(`Invalid wallet address: ${ params.rootAddress }`);
}
const accountDataUrl = `${ this.getHorizonUrl() }/accounts/${ params.rootAddress }`;
const destinationUrl = `${ this.getHorizonUrl() }/accounts/${ params.recoveryDestination }`;
let accountData;
try {
accountData = yield request.get(accountDataUrl).result();
} catch (e) {
throw new Error('Unable to reach the Stellar network via Horizon.');
}
// Now check if the destination account is empty or not
let unfundedDestination = false;
try {
yield request.get(destinationUrl);
} catch (e) {
if (e.status === 404) {
// If the destination account does not yet exist, horizon responds with 404
unfundedDestination = true;
}
}
if (!accountData.sequence || !accountData.balances) {
throw new Error('Horizon server error - unable to retrieve sequence ID or account balance');
}
const account = new stellar.Account(params.rootAddress, accountData.sequence);
// Stellar supports multiple assets on chain, we're only interested in the balances entry whose type is "native" (XLM)
const nativeBalanceInfo = accountData.balances.find(assetBalance => assetBalance['asset_type'] === 'native');
if (!nativeBalanceInfo) {
throw new Error('Provided wallet has a balance of 0 XLM, recovery aborted');
}
const walletBalance = this.bigUnitsToBaseUnits(nativeBalanceInfo.balance);
const minimumReserve = yield this.getMinimumReserve();
const baseTxFee = yield this.getBaseTransactionFee();
const recoveryAmount = walletBalance - minimumReserve - baseTxFee;
const formattedRecoveryAmount = (this.baseUnitsToBigUnits(recoveryAmount)).toString();
let txBuilder = new stellar.TransactionBuilder(account);
let operation;
if (unfundedDestination) { // In this case, we need to create the account
operation = stellar.Operation.createAccount({
destination: params.recoveryDestination,
startingBalance: formattedRecoveryAmount
});
} else { // Otherwise if the account already exists, we do a normal send
operation = stellar.Operation.payment({
destination: params.recoveryDestination,
asset: stellar.Asset.native(),
amount: formattedRecoveryAmount
});
}
txBuilder = txBuilder.addOperation(operation).build();
if (!isUnsignedSweep) {
txBuilder.sign(userKey);
}
if (!isKrsRecovery && !isUnsignedSweep) {
txBuilder.sign(backupKey);
}
const transaction: any = {
tx: txBuilder.toEnvelope().toXDR('base64'),
recoveryAmount
};
if (isKrsRecovery) {
transaction.backupKey = params.backupKey;
transaction.coin = this.getChain();
}
return transaction;
}).call(this);