本文整理汇总了TypeScript中bitgo-utxo-lib.HDNode.fromBase58方法的典型用法代码示例。如果您正苦于以下问题:TypeScript HDNode.fromBase58方法的具体用法?TypeScript HDNode.fromBase58怎么用?TypeScript HDNode.fromBase58使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bitgo-utxo-lib.HDNode
的用法示例。
在下文中一共展示了HDNode.fromBase58方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: co
return co(function *initiateRecovery() {
const keys = [];
const userKey = params.userKey; // Box A
let backupKey = params.backupKey; // Box B
const bitgoXpub = params.bitgoKey; // Box C
const destinationAddress = params.recoveryDestination;
const passphrase = params.walletPassphrase;
const isKrsRecovery = backupKey.startsWith('xpub') && !userKey.startsWith('xpub');
const isUnsignedSweep = backupKey.startsWith('xpub') && userKey.startsWith('xpub');
if (isKrsRecovery && _.isUndefined(config.krsProviders[params.krsProvider])) {
throw new Error('unknown key recovery service provider');
}
const validatePassphraseKey = function(userKey, passphrase): Promise<HDNode> {
try {
if (!userKey.startsWith('xprv') && !isUnsignedSweep) {
userKey = sjcl.decrypt(passphrase, userKey);
}
const userHDNode = HDNode.fromBase58(userKey);
return Promise.resolve(userHDNode);
} catch (e) {
throw new Error('Failed to decrypt user key with passcode - try again!');
}
};
const key = yield validatePassphraseKey(userKey, passphrase);
keys.push(key);
// Validate the backup key
try {
if (!backupKey.startsWith('xprv') && !isKrsRecovery && !isUnsignedSweep) {
backupKey = sjcl.decrypt(passphrase, backupKey);
}
const backupHDNode = HDNode.fromBase58(backupKey);
keys.push(backupHDNode);
} catch (e) {
throw new Error('Failed to decrypt backup key with passcode - try again!');
}
try {
const bitgoHDNode = HDNode.fromBase58(bitgoXpub);
keys.push(bitgoHDNode);
} catch (e) {
if (this.getFamily() !== 'xrp') {
// in XRP recoveries, the BitGo xpub is optional
throw new Error('Failed to parse bitgo xpub!');
}
}
// Validate the destination address
if (!this.isValidAddress(destinationAddress)) {
throw new Error('Invalid destination address!');
}
return keys;
}).call(this);
示例2: 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) {
try {
bitGoUtxoLib.HDNode.fromBase58(pub);
return true;
} catch (e) {
return false;
}
}
示例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?
*/
public isValidPub(pub: string): boolean {
try {
HDNode.fromBase58(pub);
return true;
} catch (e) {
return false;
}
}
示例4: function
const validatePassphraseKey = function(userKey, passphrase): Promise<HDNode> {
try {
if (!userKey.startsWith('xprv') && !isUnsignedSweep) {
userKey = sjcl.decrypt(passphrase, userKey);
}
const userHDNode = HDNode.fromBase58(userKey);
return Promise.resolve(userHDNode);
} catch (e) {
throw new Error('Failed to decrypt user key with passcode - try again!');
}
};
示例5: before
before(co(function *() {
tx = '0xf86c82015285012a05f200825208945208d8e80c6d1aef9be37b4bd19a9cf75ed93dc886b5e620f480008026a00e13f9e0e11337b2b0227e3412211d3625e43f1083fda399cc361dd4bf89083ba06c801a761e0aa3bc8db0ac2568d575b0fb306a1f04f4d5ba82ba3cc0ea0a83bd';
txid = '0x0ac669c5fef8294443c75a31e32c44b97bbc9e43a18ea8beabcc2a3b45eb6ffa';
bitgoKeyXprv = 'xprv9s21ZrQH143K3tpWBHWe31sLoXNRQ9AvRYJgitkKxQ4ATFQMwvr7hHNqYRUnS7PsjzB7aK1VxqHLuNQjj1sckJ2Jwo2qxmsvejwECSpFMfC';
const bitgoPrvBuffer = bitGoUtxoLib.HDNode.fromBase58(bitgoKeyXprv).getKey().getPrivateKeyBuffer();
bitgoSignature = '0xaa' + secp256k1.sign(Buffer.from(txid.slice(2), 'hex'), bitgoPrvBuffer).signature.toString('hex');
bitgo = new TestV2BitGo({ env: 'test' });
bitgo.initializeTestVars();
bgUrl = common.Environments[bitgo.getEnv()].uri;
const coin = bitgo.coin('teth');
ethWallet = coin.newWalletObject({ keys: ['user', 'backup', 'bitgo'] });
}));
示例6: it
it('should create and sign a trade payload', co(function *() {
const xprv = 'xprv9s21ZrQH143K2MUz7uPUBVzdmvJQE6fPEQCkR3mypPbZgijPqfmGH7pjijdjeJx3oCoxPWVbjC4VYHzgN6wqEfYnnbNjK7jm2CkrvWrvkbR';
const xpub = 'xpub661MyMwAqRbcEqZTDvvUYdwNKx8tdZPEbd8MDSBbNj8YZX4YPD5Wpv9Da2YzLC8ZNRhundXP7mVhhu9WdJChzZJFGLQD7tyY1KGfmjuBvcX';
const msScope = nock(microservicesUri)
.post('/api/trade/v1/payload')
.reply(200, {
payload: JSON.stringify({
walletId: 'walletId',
currency: 'tbtc',
amount: '100000000',
otherParties: ['test_counter_party_1'],
nonce: Date.now()
})
});
const platformScope = nock(bgUrl)
.get('/api/v2/ofc/key/keyid')
.reply(200, {
pub: xpub,
encryptedPrv: bitgo.encrypt({ input: xprv, password: TestV2BitGo.OFC_TEST_PASSWORD })
});
const { payload, signature } = yield trading.signTradePayload({
currency: 'tbtc',
amount: '100000000',
otherParties: ['test_counterparty_1'],
walletPassphrase: TestV2BitGo.OFC_TEST_PASSWORD
});
should.exist(payload);
// The payload should be a valid JSON object
// NOTE: we shouldn't do any more validation than this, as the schema is subject to change often
(() => { JSON.parse(payload); }).should.not.throw();
should.exist(signature);
// signature should be a hex string
signature.should.match(/^[0-9a-f]+$/);
const address = HDNode.fromBase58(xpub).getAddress();
bitcoinMessage.verify(payload, address, Buffer.from(signature, 'hex')).should.be.True();
msScope.isDone().should.be.True();
platformScope.isDone().should.be.True();
}));
示例7: it
it('should fail if the HSM signature signed the wrong HSM commitment digest', co(function *() {
let error = undefined;
const badTxid = '0xb4b3827a529c9166786e796528017889ac5027255b65b3fa2a3d3ad91244a12b';
const badTxidBuffer = Buffer.from(badTxid.slice(2), 'hex');
const xprvNode = bitGoUtxoLib.HDNode.fromBase58(bitgoKeyXprv);
const badSignature = '0xaa' + secp256k1.sign(badTxidBuffer, xprvNode.getKey().getPrivateKeyBuffer()).signature.toString('hex');
const badPrebuild = JSON.parse(JSON.stringify(prebuild));
badPrebuild.signature = badSignature;
nockBitGoKey();
try {
yield ethWallet.baseCoin.validateHopPrebuild(ethWallet, badPrebuild, buildParams);
} catch (e) {
error = e.message;
}
should.exist(error);
error.should.containEql("Hop txid signature invalid");
}));
示例8: signTransaction
/**
* Assemble keychain and half-sign prebuilt transaction
* @param params
* - txPrebuild
* - prv
* @returns {{txHex}}
*/
public signTransaction({ txPrebuild, prv }: SignTransactionOptions): HalfSignedTransaction {
if (_.isUndefined(txPrebuild) || !_.isObject(txPrebuild)) {
if (!_.isUndefined(txPrebuild) && !_.isObject(txPrebuild)) {
throw new Error(`txPrebuild must be an object, got type ${typeof txPrebuild}`);
}
throw new Error('missing txPrebuild parameter');
}
if (_.isUndefined(prv) || !_.isString(prv)) {
if (!_.isUndefined(prv) && !_.isString(prv)) {
throw new Error(`prv must be a string, got type ${typeof prv}`);
}
throw new Error('missing prv parameter to sign transaction');
}
const userKey = HDNode.fromBase58(prv).getKey();
const userPrivateKey: Buffer = userKey.getPrivateKeyBuffer();
const userAddress = rippleKeypairs.deriveAddress(userKey.getPublicKeyBuffer().toString('hex'));
const rippleLib = ripple();
const halfSigned = rippleLib.signWithPrivateKey(txPrebuild.txHex, userPrivateKey.toString('hex'), { signAs: userAddress });
return { halfSigned: { txHex: halfSigned.signedTransaction } };
}