本文整理匯總了TypeScript中jQuery.Deferred.resolve方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Deferred.resolve方法的具體用法?TypeScript Deferred.resolve怎麽用?TypeScript Deferred.resolve使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類jQuery.Deferred
的用法示例。
在下文中一共展示了Deferred.resolve方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: scryptAsync
scryptAsync(passphrase, salt, {N: 262144, r: 1, p: 8, dkLen: 32}, function(derivedKey) {
derivedKey = new Buffer(derivedKey)
// ciphertext is private key encrypted with aes-128-ctr
let aesctr = new aesjs.ModeOfOperation.ctr(derivedKey.slice(0, 16), new aesjs.Counter(iv))
let ciphertext = aesctr.encrypt(privateKey)
var result = {
address: address,
crypto: {
cipher: "aes-128-ctr",
cipherparams: {
iv: iv.toString('hex'),
},
ciphertext: new Buffer(ciphertext).toString('hex'),
kdf: "scrypt",
kdfparams: {
dklen: 32,
n: 262144,
r: 1,
p: 8,
salt: salt.toString('hex'),
},
mac: sha3.digest(Buffer.concat([derivedKey.slice(16, 32), new Buffer(ciphertext)])).toString('hex'),
},
id: uuid.v4({random: randomBytes(16)}),
version: 3,
}
deferred.resolve({
result: JSON.stringify(result)
})
})
示例2:
that.node.getLatestTxBlock(function(err, data2) {
if (err || !data2.result) {
deferred.reject(err)
} else {
deferred.resolve({
networkId: data1.result,
latestTxBlock: data2.result.header.BlockNum
})
}
})
示例3: function
this.node.createTransaction(txn, function(err, data) {
if (err || data.error) {
deferred.reject(err)
} else {
deferred.resolve({
txId: data.result
})
}
that.endLoading()
})
示例4: decryptWalletFile
/**
* process a keystore json file to retrieve the private key and import the account data
* uses this.walletData to import data and this.userWallet to store data separately
* @param {string} passphrase - the passphrase of the keystore json entered by the user
* @returns {Promise} Promise object containing boolean - if imported successfully or not
*/
decryptWalletFile(passphrase): Promise<any> {
let that = this
var deferred = new $.Deferred()
// use the passphrase and keystore json file to get private key
if (passphrase && passphrase.length >= 8) {
let walletJson = JSON.parse(this.walletData.encryptedWalletFile)
let ciphertext = new Buffer(walletJson['crypto']['ciphertext'], 'hex')
let iv = new Buffer(walletJson['crypto']['cipherparams']['iv'], 'hex')
let salt = new Buffer(walletJson['crypto']['kdfparams']['salt'], 'hex')
let kdfparams = walletJson['crypto']['kdfparams']
// recreate the derived key using scrypt and the same parameters
scryptAsync(passphrase, salt, {N: kdfparams['n'], r: kdfparams['r'], p: kdfparams['p'], dkLen: kdfparams['dklen']}, function(derivedKey) {
derivedKey = new Buffer(derivedKey, 'hex')
// check passphrase using mac
let mac = sha3.digest(Buffer.concat([derivedKey.slice(16, 32), ciphertext])).toString('hex')
if (mac.toLowerCase() !== walletJson['crypto']['mac'].toLowerCase()) {
// Incorrect passphrase
deferred.resolve({result: false})
}
let aesctr = new aesjs.ModeOfOperation.ctr(derivedKey.slice(0, 16), new aesjs.Counter(iv))
let decryptedSeed = aesctr.decrypt(ciphertext);
deferred.resolve({
result: new Buffer(decryptedSeed).toString('hex')
})
})
} else {
deferred.resolve({result: false})
}
return deferred.promise()
}