@ethersproject/json-wallets
Advanced tools
@@ -1,1 +0,1 @@ | ||
| export declare const version = "json-wallets/5.0.0-beta.132"; | ||
| export declare const version = "json-wallets/5.0.0-beta.133"; |
@@ -1,1 +0,1 @@ | ||
| export const version = "json-wallets/5.0.0-beta.132"; | ||
| export const version = "json-wallets/5.0.0-beta.133"; |
+10
-11
@@ -20,18 +20,17 @@ "use strict"; | ||
| export function decrypt(json, password) { | ||
| let data = JSON.parse(json); | ||
| const data = JSON.parse(json); | ||
| password = getPassword(password); | ||
| // Ethereum Address | ||
| let ethaddr = getAddress(searchPath(data, "ethaddr")); | ||
| const ethaddr = getAddress(searchPath(data, "ethaddr")); | ||
| // Encrypted Seed | ||
| let encseed = looseArrayify(searchPath(data, "encseed")); | ||
| const encseed = looseArrayify(searchPath(data, "encseed")); | ||
| if (!encseed || (encseed.length % 16) !== 0) { | ||
| logger.throwArgumentError("invalid encseed", "json", json); | ||
| } | ||
| let key = arrayify(pbkdf2(password, password, 2000, 32, "sha256")).slice(0, 16); | ||
| let iv = encseed.slice(0, 16); | ||
| let encryptedSeed = encseed.slice(16); | ||
| const key = arrayify(pbkdf2(password, password, 2000, 32, "sha256")).slice(0, 16); | ||
| const iv = encseed.slice(0, 16); | ||
| const encryptedSeed = encseed.slice(16); | ||
| // Decrypt the seed | ||
| let aesCbc = new aes.ModeOfOperation.cbc(key, iv); | ||
| let seed = arrayify(aesCbc.decrypt(encryptedSeed)); | ||
| seed = aes.padding.pkcs7.strip(seed); | ||
| const aesCbc = new aes.ModeOfOperation.cbc(key, iv); | ||
| const seed = aes.padding.pkcs7.strip(arrayify(aesCbc.decrypt(encryptedSeed))); | ||
| // This wallet format is weird... Convert the binary encoded hex to a string. | ||
@@ -42,4 +41,4 @@ let seedHex = ""; | ||
| } | ||
| let seedHexBytes = toUtf8Bytes(seedHex); | ||
| let privateKey = keccak256(seedHexBytes); | ||
| const seedHexBytes = toUtf8Bytes(seedHex); | ||
| const privateKey = keccak256(seedHexBytes); | ||
| return new CrowdsaleAccount({ | ||
@@ -46,0 +45,0 @@ _isCrowdsaleAccount: true, |
+1
-1
@@ -10,3 +10,3 @@ "use strict"; | ||
| } | ||
| let account = decryptCrowdsale(json, password); | ||
| const account = decryptCrowdsale(json, password); | ||
| if (progressCallback) { | ||
@@ -13,0 +13,0 @@ progressCallback(1); |
+153
-200
| "use strict"; | ||
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
| function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
| return new (P || (P = Promise))(function (resolve, reject) { | ||
| function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
| function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
| function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
| step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
| }); | ||
| }; | ||
| import aes from "aes-js"; | ||
| import scrypt from "scrypt-js"; | ||
| import * as scrypt from "scrypt-js"; | ||
| import uuid from "uuid"; | ||
@@ -21,118 +30,90 @@ import { getAddress } from "@ethersproject/address"; | ||
| export function decrypt(json, password, progressCallback) { | ||
| let data = JSON.parse(json); | ||
| let passwordBytes = getPassword(password); | ||
| let decrypt = function (key, ciphertext) { | ||
| let cipher = searchPath(data, "crypto/cipher"); | ||
| if (cipher === "aes-128-ctr") { | ||
| let iv = looseArrayify(searchPath(data, "crypto/cipherparams/iv")); | ||
| let counter = new aes.Counter(iv); | ||
| let aesCtr = new aes.ModeOfOperation.ctr(key, counter); | ||
| return arrayify(aesCtr.decrypt(ciphertext)); | ||
| } | ||
| return null; | ||
| }; | ||
| let computeMAC = function (derivedHalf, ciphertext) { | ||
| return keccak256(concat([derivedHalf, ciphertext])); | ||
| }; | ||
| let getAccount = function (key, reject) { | ||
| let ciphertext = looseArrayify(searchPath(data, "crypto/ciphertext")); | ||
| let computedMAC = hexlify(computeMAC(key.slice(16, 32), ciphertext)).substring(2); | ||
| if (computedMAC !== searchPath(data, "crypto/mac").toLowerCase()) { | ||
| reject(new Error("invalid password")); | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| const data = JSON.parse(json); | ||
| const passwordBytes = getPassword(password); | ||
| const decrypt = function (key, ciphertext) { | ||
| const cipher = searchPath(data, "crypto/cipher"); | ||
| if (cipher === "aes-128-ctr") { | ||
| const iv = looseArrayify(searchPath(data, "crypto/cipherparams/iv")); | ||
| const counter = new aes.Counter(iv); | ||
| const aesCtr = new aes.ModeOfOperation.ctr(key, counter); | ||
| return arrayify(aesCtr.decrypt(ciphertext)); | ||
| } | ||
| return null; | ||
| } | ||
| let privateKey = decrypt(key.slice(0, 16), ciphertext); | ||
| let mnemonicKey = key.slice(32, 64); | ||
| if (!privateKey) { | ||
| reject(new Error("unsupported cipher")); | ||
| return null; | ||
| } | ||
| let address = computeAddress(privateKey); | ||
| if (data.address) { | ||
| let check = data.address.toLowerCase(); | ||
| if (check.substring(0, 2) !== "0x") { | ||
| check = "0x" + check; | ||
| } | ||
| try { | ||
| if (getAddress(check) !== address) { | ||
| reject(new Error("address mismatch")); | ||
| return null; | ||
| }; | ||
| const computeMAC = function (derivedHalf, ciphertext) { | ||
| return keccak256(concat([derivedHalf, ciphertext])); | ||
| }; | ||
| const getAccount = function (key) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| const ciphertext = looseArrayify(searchPath(data, "crypto/ciphertext")); | ||
| const computedMAC = hexlify(computeMAC(key.slice(16, 32), ciphertext)).substring(2); | ||
| if (computedMAC !== searchPath(data, "crypto/mac").toLowerCase()) { | ||
| throw new Error("invalid password"); | ||
| } | ||
| } | ||
| catch (e) { } | ||
| } | ||
| let account = { | ||
| _isKeystoreAccount: true, | ||
| address: address, | ||
| privateKey: hexlify(privateKey) | ||
| const privateKey = decrypt(key.slice(0, 16), ciphertext); | ||
| const mnemonicKey = key.slice(32, 64); | ||
| if (!privateKey) { | ||
| throw new Error("unsupported cipher"); | ||
| } | ||
| const address = computeAddress(privateKey); | ||
| if (data.address) { | ||
| let check = data.address.toLowerCase(); | ||
| if (check.substring(0, 2) !== "0x") { | ||
| check = "0x" + check; | ||
| } | ||
| if (getAddress(check) !== address) { | ||
| throw new Error("address mismatch"); | ||
| } | ||
| } | ||
| const account = { | ||
| _isKeystoreAccount: true, | ||
| address: address, | ||
| privateKey: hexlify(privateKey) | ||
| }; | ||
| // Version 0.1 x-ethers metadata must contain an encrypted mnemonic phrase | ||
| if (searchPath(data, "x-ethers/version") === "0.1") { | ||
| const mnemonicCiphertext = looseArrayify(searchPath(data, "x-ethers/mnemonicCiphertext")); | ||
| const mnemonicIv = looseArrayify(searchPath(data, "x-ethers/mnemonicCounter")); | ||
| const mnemonicCounter = new aes.Counter(mnemonicIv); | ||
| const mnemonicAesCtr = new aes.ModeOfOperation.ctr(mnemonicKey, mnemonicCounter); | ||
| const path = searchPath(data, "x-ethers/path") || defaultPath; | ||
| const entropy = arrayify(mnemonicAesCtr.decrypt(mnemonicCiphertext)); | ||
| const mnemonic = entropyToMnemonic(entropy); | ||
| const node = HDNode.fromMnemonic(mnemonic).derivePath(path); | ||
| if (node.privateKey != account.privateKey) { | ||
| throw new Error("mnemonic mismatch"); | ||
| } | ||
| account.mnemonic = node.mnemonic; | ||
| account.path = node.path; | ||
| } | ||
| return new KeystoreAccount(account); | ||
| }); | ||
| }; | ||
| // Version 0.1 x-ethers metadata must contain an encrypted mnemonic phrase | ||
| if (searchPath(data, "x-ethers/version") === "0.1") { | ||
| let mnemonicCiphertext = looseArrayify(searchPath(data, "x-ethers/mnemonicCiphertext")); | ||
| let mnemonicIv = looseArrayify(searchPath(data, "x-ethers/mnemonicCounter")); | ||
| let mnemonicCounter = new aes.Counter(mnemonicIv); | ||
| let mnemonicAesCtr = new aes.ModeOfOperation.ctr(mnemonicKey, mnemonicCounter); | ||
| let path = searchPath(data, "x-ethers/path") || defaultPath; | ||
| let entropy = arrayify(mnemonicAesCtr.decrypt(mnemonicCiphertext)); | ||
| let mnemonic = entropyToMnemonic(entropy); | ||
| let node = HDNode.fromMnemonic(mnemonic).derivePath(path); | ||
| if (node.privateKey != account.privateKey) { | ||
| reject(new Error("mnemonic mismatch")); | ||
| return null; | ||
| } | ||
| account.mnemonic = node.mnemonic; | ||
| account.path = node.path; | ||
| } | ||
| return new KeystoreAccount(account); | ||
| }; | ||
| return new Promise(function (resolve, reject) { | ||
| let kdf = searchPath(data, "crypto/kdf"); | ||
| const kdf = searchPath(data, "crypto/kdf"); | ||
| if (kdf && typeof (kdf) === "string") { | ||
| if (kdf.toLowerCase() === "scrypt") { | ||
| let salt = looseArrayify(searchPath(data, "crypto/kdfparams/salt")); | ||
| let N = parseInt(searchPath(data, "crypto/kdfparams/n")); | ||
| let r = parseInt(searchPath(data, "crypto/kdfparams/r")); | ||
| let p = parseInt(searchPath(data, "crypto/kdfparams/p")); | ||
| const salt = looseArrayify(searchPath(data, "crypto/kdfparams/salt")); | ||
| const N = parseInt(searchPath(data, "crypto/kdfparams/n")); | ||
| const r = parseInt(searchPath(data, "crypto/kdfparams/r")); | ||
| const p = parseInt(searchPath(data, "crypto/kdfparams/p")); | ||
| if (!N || !r || !p) { | ||
| reject(new Error("unsupported key-derivation function parameters")); | ||
| return; | ||
| throw new Error("unsupported key-derivation function parameters"); | ||
| } | ||
| // Make sure N is a power of 2 | ||
| if ((N & (N - 1)) !== 0) { | ||
| reject(new Error("unsupported key-derivation function parameter value for N")); | ||
| return; | ||
| throw new Error("unsupported key-derivation function parameter value for N"); | ||
| } | ||
| let dkLen = parseInt(searchPath(data, "crypto/kdfparams/dklen")); | ||
| const dkLen = parseInt(searchPath(data, "crypto/kdfparams/dklen")); | ||
| if (dkLen !== 32) { | ||
| reject(new Error("unsupported key-derivation derived-key length")); | ||
| return; | ||
| throw new Error("unsupported key-derivation derived-key length"); | ||
| } | ||
| if (progressCallback) { | ||
| progressCallback(0); | ||
| } | ||
| scrypt(passwordBytes, salt, N, r, p, 64, function (error, progress, key) { | ||
| if (error) { | ||
| error.progress = progress; | ||
| reject(error); | ||
| } | ||
| else if (key) { | ||
| key = arrayify(key); | ||
| let account = getAccount(key, reject); | ||
| if (!account) { | ||
| return; | ||
| } | ||
| if (progressCallback) { | ||
| progressCallback(1); | ||
| } | ||
| resolve(account); | ||
| } | ||
| else if (progressCallback) { | ||
| return progressCallback(progress); | ||
| } | ||
| }); | ||
| const key = yield scrypt.scrypt(passwordBytes, salt, N, r, p, 64, progressCallback); | ||
| //key = arrayify(key); | ||
| return getAccount(key); | ||
| } | ||
| else if (kdf.toLowerCase() === "pbkdf2") { | ||
| let salt = looseArrayify(searchPath(data, "crypto/kdfparams/salt")); | ||
| const salt = looseArrayify(searchPath(data, "crypto/kdfparams/salt")); | ||
| let prfFunc = null; | ||
| let prf = searchPath(data, "crypto/kdfparams/prf"); | ||
| const prf = searchPath(data, "crypto/kdfparams/prf"); | ||
| if (prf === "hmac-sha256") { | ||
@@ -145,25 +126,14 @@ prfFunc = "sha256"; | ||
| else { | ||
| reject(new Error("unsupported prf")); | ||
| return; | ||
| throw new Error("unsupported prf"); | ||
| } | ||
| let c = parseInt(searchPath(data, "crypto/kdfparams/c")); | ||
| let dkLen = parseInt(searchPath(data, "crypto/kdfparams/dklen")); | ||
| const c = parseInt(searchPath(data, "crypto/kdfparams/c")); | ||
| const dkLen = parseInt(searchPath(data, "crypto/kdfparams/dklen")); | ||
| if (dkLen !== 32) { | ||
| reject(new Error("unsupported key-derivation derived-key length")); | ||
| return; | ||
| throw new Error("unsupported key-derivation derived-key length"); | ||
| } | ||
| let key = arrayify(pbkdf2(passwordBytes, salt, c, dkLen, prfFunc)); | ||
| let account = getAccount(key, reject); | ||
| if (!account) { | ||
| return; | ||
| } | ||
| resolve(account); | ||
| const key = arrayify(pbkdf2(passwordBytes, salt, c, dkLen, prfFunc)); | ||
| return getAccount(key); | ||
| } | ||
| else { | ||
| reject(new Error("unsupported key-derivation function")); | ||
| } | ||
| } | ||
| else { | ||
| reject(new Error("unsupported key-derivation function")); | ||
| } | ||
| throw new Error("unsupported key-derivation function"); | ||
| }); | ||
@@ -177,3 +147,3 @@ } | ||
| if (account.mnemonic != null) { | ||
| let node = HDNode.fromMnemonic(account.mnemonic).derivePath(account.path || defaultPath); | ||
| const node = HDNode.fromMnemonic(account.mnemonic).derivePath(account.path || defaultPath); | ||
| if (node.privateKey != account.privateKey) { | ||
@@ -198,4 +168,4 @@ throw new Error("mnemonic mismatch"); | ||
| } | ||
| let privateKey = arrayify(account.privateKey); | ||
| let passwordBytes = getPassword(password); | ||
| const privateKey = arrayify(account.privateKey); | ||
| const passwordBytes = getPassword(password); | ||
| let entropy = null; | ||
@@ -257,81 +227,64 @@ let path = account.path; | ||
| } | ||
| return new Promise(function (resolve, reject) { | ||
| if (progressCallback) { | ||
| progressCallback(0); | ||
| // We take 64 bytes: | ||
| // - 32 bytes As normal for the Web3 secret storage (derivedKey, macPrefix) | ||
| // - 32 bytes AES key to encrypt mnemonic with (required here to be Ethers Wallet) | ||
| return scrypt.scrypt(passwordBytes, salt, N, r, p, 64, progressCallback).then((key) => { | ||
| key = arrayify(key); | ||
| // This will be used to encrypt the wallet (as per Web3 secret storage) | ||
| const derivedKey = key.slice(0, 16); | ||
| const macPrefix = key.slice(16, 32); | ||
| // This will be used to encrypt the mnemonic phrase (if any) | ||
| const mnemonicKey = key.slice(32, 64); | ||
| // Encrypt the private key | ||
| const counter = new aes.Counter(iv); | ||
| const aesCtr = new aes.ModeOfOperation.ctr(derivedKey, counter); | ||
| const ciphertext = arrayify(aesCtr.encrypt(privateKey)); | ||
| // Compute the message authentication code, used to check the password | ||
| const mac = keccak256(concat([macPrefix, ciphertext])); | ||
| // See: https://github.com/ethereum/wiki/wiki/Web3-Secret-Storage-Definition | ||
| const data = { | ||
| address: account.address.substring(2).toLowerCase(), | ||
| id: uuid.v4({ random: uuidRandom }), | ||
| version: 3, | ||
| Crypto: { | ||
| cipher: "aes-128-ctr", | ||
| cipherparams: { | ||
| iv: hexlify(iv).substring(2), | ||
| }, | ||
| ciphertext: hexlify(ciphertext).substring(2), | ||
| kdf: "scrypt", | ||
| kdfparams: { | ||
| salt: hexlify(salt).substring(2), | ||
| n: N, | ||
| dklen: 32, | ||
| p: p, | ||
| r: r | ||
| }, | ||
| mac: mac.substring(2) | ||
| } | ||
| }; | ||
| // If we have a mnemonic, encrypt it into the JSON wallet | ||
| if (entropy) { | ||
| const mnemonicIv = randomBytes(16); | ||
| const mnemonicCounter = new aes.Counter(mnemonicIv); | ||
| const mnemonicAesCtr = new aes.ModeOfOperation.ctr(mnemonicKey, mnemonicCounter); | ||
| const mnemonicCiphertext = arrayify(mnemonicAesCtr.encrypt(entropy)); | ||
| const now = new Date(); | ||
| const timestamp = (now.getUTCFullYear() + "-" + | ||
| zpad(now.getUTCMonth() + 1, 2) + "-" + | ||
| zpad(now.getUTCDate(), 2) + "T" + | ||
| zpad(now.getUTCHours(), 2) + "-" + | ||
| zpad(now.getUTCMinutes(), 2) + "-" + | ||
| zpad(now.getUTCSeconds(), 2) + ".0Z"); | ||
| data["x-ethers"] = { | ||
| client: client, | ||
| gethFilename: ("UTC--" + timestamp + "--" + data.address), | ||
| mnemonicCounter: hexlify(mnemonicIv).substring(2), | ||
| mnemonicCiphertext: hexlify(mnemonicCiphertext).substring(2), | ||
| path: path, | ||
| version: "0.1" | ||
| }; | ||
| } | ||
| // We take 64 bytes: | ||
| // - 32 bytes As normal for the Web3 secret storage (derivedKey, macPrefix) | ||
| // - 32 bytes AES key to encrypt mnemonic with (required here to be Ethers Wallet) | ||
| scrypt(passwordBytes, salt, N, r, p, 64, function (error, progress, key) { | ||
| if (error) { | ||
| error.progress = progress; | ||
| reject(error); | ||
| } | ||
| else if (key) { | ||
| key = arrayify(key); | ||
| // This will be used to encrypt the wallet (as per Web3 secret storage) | ||
| let derivedKey = key.slice(0, 16); | ||
| let macPrefix = key.slice(16, 32); | ||
| // This will be used to encrypt the mnemonic phrase (if any) | ||
| let mnemonicKey = key.slice(32, 64); | ||
| // Encrypt the private key | ||
| let counter = new aes.Counter(iv); | ||
| let aesCtr = new aes.ModeOfOperation.ctr(derivedKey, counter); | ||
| let ciphertext = arrayify(aesCtr.encrypt(privateKey)); | ||
| // Compute the message authentication code, used to check the password | ||
| let mac = keccak256(concat([macPrefix, ciphertext])); | ||
| // See: https://github.com/ethereum/wiki/wiki/Web3-Secret-Storage-Definition | ||
| let data = { | ||
| address: account.address.substring(2).toLowerCase(), | ||
| id: uuid.v4({ random: uuidRandom }), | ||
| version: 3, | ||
| Crypto: { | ||
| cipher: "aes-128-ctr", | ||
| cipherparams: { | ||
| iv: hexlify(iv).substring(2), | ||
| }, | ||
| ciphertext: hexlify(ciphertext).substring(2), | ||
| kdf: "scrypt", | ||
| kdfparams: { | ||
| salt: hexlify(salt).substring(2), | ||
| n: N, | ||
| dklen: 32, | ||
| p: p, | ||
| r: r | ||
| }, | ||
| mac: mac.substring(2) | ||
| } | ||
| }; | ||
| // If we have a mnemonic, encrypt it into the JSON wallet | ||
| if (entropy) { | ||
| let mnemonicIv = randomBytes(16); | ||
| let mnemonicCounter = new aes.Counter(mnemonicIv); | ||
| let mnemonicAesCtr = new aes.ModeOfOperation.ctr(mnemonicKey, mnemonicCounter); | ||
| let mnemonicCiphertext = arrayify(mnemonicAesCtr.encrypt(entropy)); | ||
| let now = new Date(); | ||
| let timestamp = (now.getUTCFullYear() + "-" + | ||
| zpad(now.getUTCMonth() + 1, 2) + "-" + | ||
| zpad(now.getUTCDate(), 2) + "T" + | ||
| zpad(now.getUTCHours(), 2) + "-" + | ||
| zpad(now.getUTCMinutes(), 2) + "-" + | ||
| zpad(now.getUTCSeconds(), 2) + ".0Z"); | ||
| data["x-ethers"] = { | ||
| client: client, | ||
| gethFilename: ("UTC--" + timestamp + "--" + data.address), | ||
| mnemonicCounter: hexlify(mnemonicIv).substring(2), | ||
| mnemonicCiphertext: hexlify(mnemonicCiphertext).substring(2), | ||
| path: path, | ||
| version: "0.1" | ||
| }; | ||
| } | ||
| if (progressCallback) { | ||
| progressCallback(1); | ||
| } | ||
| resolve(JSON.stringify(data)); | ||
| } | ||
| else if (progressCallback) { | ||
| return progressCallback(progress); | ||
| } | ||
| }); | ||
| return JSON.stringify(data); | ||
| }); | ||
| } |
+2
-16
| "use strict"; | ||
| import { arrayify } from "@ethersproject/bytes"; | ||
| //import { Description } from "@ethersproject/properties"; | ||
| import { toUtf8Bytes, UnicodeNormalizationForm } from '@ethersproject/strings'; | ||
| /* | ||
| export class Account extends Description implements ExternallyOwnedAccount { | ||
| readonly address: string; | ||
| readonly privateKey: string; | ||
| readonly mnemonic?: string; | ||
| readonly path?: string; | ||
| // static isAccount(value: any): value is Account { | ||
| // return Description._isType(value); | ||
| // } | ||
| } | ||
| //defineReadOnly(Account, "name", "Account"); | ||
| */ | ||
| export function looseArrayify(hexString) { | ||
@@ -39,7 +25,7 @@ if (typeof (hexString) === 'string' && hexString.substring(0, 2) !== '0x') { | ||
| let currentChild = object; | ||
| let comps = path.toLowerCase().split('/'); | ||
| const comps = path.toLowerCase().split('/'); | ||
| for (let i = 0; i < comps.length; i++) { | ||
| // Search for a child object with a case-insensitive matching key | ||
| let matchingChild = null; | ||
| for (let key in currentChild) { | ||
| for (const key in currentChild) { | ||
| if (key.toLowerCase() === comps[i]) { | ||
@@ -46,0 +32,0 @@ matchingChild = currentChild[key]; |
@@ -1,1 +0,1 @@ | ||
| export declare const version = "json-wallets/5.0.0-beta.132"; | ||
| export declare const version = "json-wallets/5.0.0-beta.133"; |
+1
-1
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.version = "json-wallets/5.0.0-beta.132"; | ||
| exports.version = "json-wallets/5.0.0-beta.133"; |
+1
-2
@@ -57,4 +57,3 @@ "use strict"; | ||
| var aesCbc = new aes_js_1.default.ModeOfOperation.cbc(key, iv); | ||
| var seed = bytes_1.arrayify(aesCbc.decrypt(encryptedSeed)); | ||
| seed = aes_js_1.default.padding.pkcs7.strip(seed); | ||
| var seed = aes_js_1.default.padding.pkcs7.strip(bytes_1.arrayify(aesCbc.decrypt(encryptedSeed))); | ||
| // This wallet format is weird... Convert the binary encoded hex to a string. | ||
@@ -61,0 +60,0 @@ var seedHex = ""; |
+217
-219
@@ -15,8 +15,51 @@ "use strict"; | ||
| })(); | ||
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
| function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
| return new (P || (P = Promise))(function (resolve, reject) { | ||
| function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
| function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
| function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
| step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
| }); | ||
| }; | ||
| var __generator = (this && this.__generator) || function (thisArg, body) { | ||
| var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
| return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
| function verb(n) { return function (v) { return step([n, v]); }; } | ||
| function step(op) { | ||
| if (f) throw new TypeError("Generator is already executing."); | ||
| while (_) try { | ||
| if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
| if (y = 0, t) op = [op[0] & 2, t.value]; | ||
| switch (op[0]) { | ||
| case 0: case 1: t = op; break; | ||
| case 4: _.label++; return { value: op[1], done: false }; | ||
| case 5: _.label++; y = op[1]; op = [0]; continue; | ||
| case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
| default: | ||
| if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
| if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
| if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
| if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
| if (t[2]) _.ops.pop(); | ||
| _.trys.pop(); continue; | ||
| } | ||
| op = body.call(thisArg, _); | ||
| } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
| if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
| } | ||
| }; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| var __importStar = (this && this.__importStar) || function (mod) { | ||
| if (mod && mod.__esModule) return mod; | ||
| var result = {}; | ||
| if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
| result["default"] = mod; | ||
| return result; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var aes_js_1 = __importDefault(require("aes-js")); | ||
| var scrypt_js_1 = __importDefault(require("scrypt-js")); | ||
| var scrypt = __importStar(require("scrypt-js")); | ||
| var uuid_1 = __importDefault(require("uuid")); | ||
@@ -45,148 +88,120 @@ var address_1 = require("@ethersproject/address"); | ||
| function decrypt(json, password, progressCallback) { | ||
| var data = JSON.parse(json); | ||
| var passwordBytes = utils_1.getPassword(password); | ||
| var decrypt = function (key, ciphertext) { | ||
| var cipher = utils_1.searchPath(data, "crypto/cipher"); | ||
| if (cipher === "aes-128-ctr") { | ||
| var iv = utils_1.looseArrayify(utils_1.searchPath(data, "crypto/cipherparams/iv")); | ||
| var counter = new aes_js_1.default.Counter(iv); | ||
| var aesCtr = new aes_js_1.default.ModeOfOperation.ctr(key, counter); | ||
| return bytes_1.arrayify(aesCtr.decrypt(ciphertext)); | ||
| } | ||
| return null; | ||
| }; | ||
| var computeMAC = function (derivedHalf, ciphertext) { | ||
| return keccak256_1.keccak256(bytes_1.concat([derivedHalf, ciphertext])); | ||
| }; | ||
| var getAccount = function (key, reject) { | ||
| var ciphertext = utils_1.looseArrayify(utils_1.searchPath(data, "crypto/ciphertext")); | ||
| var computedMAC = bytes_1.hexlify(computeMAC(key.slice(16, 32), ciphertext)).substring(2); | ||
| if (computedMAC !== utils_1.searchPath(data, "crypto/mac").toLowerCase()) { | ||
| reject(new Error("invalid password")); | ||
| return null; | ||
| } | ||
| var privateKey = decrypt(key.slice(0, 16), ciphertext); | ||
| var mnemonicKey = key.slice(32, 64); | ||
| if (!privateKey) { | ||
| reject(new Error("unsupported cipher")); | ||
| return null; | ||
| } | ||
| var address = transactions_1.computeAddress(privateKey); | ||
| if (data.address) { | ||
| var check = data.address.toLowerCase(); | ||
| if (check.substring(0, 2) !== "0x") { | ||
| check = "0x" + check; | ||
| } | ||
| try { | ||
| if (address_1.getAddress(check) !== address) { | ||
| reject(new Error("address mismatch")); | ||
| return null; | ||
| } | ||
| } | ||
| catch (e) { } | ||
| } | ||
| var account = { | ||
| _isKeystoreAccount: true, | ||
| address: address, | ||
| privateKey: bytes_1.hexlify(privateKey) | ||
| }; | ||
| // Version 0.1 x-ethers metadata must contain an encrypted mnemonic phrase | ||
| if (utils_1.searchPath(data, "x-ethers/version") === "0.1") { | ||
| var mnemonicCiphertext = utils_1.looseArrayify(utils_1.searchPath(data, "x-ethers/mnemonicCiphertext")); | ||
| var mnemonicIv = utils_1.looseArrayify(utils_1.searchPath(data, "x-ethers/mnemonicCounter")); | ||
| var mnemonicCounter = new aes_js_1.default.Counter(mnemonicIv); | ||
| var mnemonicAesCtr = new aes_js_1.default.ModeOfOperation.ctr(mnemonicKey, mnemonicCounter); | ||
| var path = utils_1.searchPath(data, "x-ethers/path") || hdnode_1.defaultPath; | ||
| var entropy = bytes_1.arrayify(mnemonicAesCtr.decrypt(mnemonicCiphertext)); | ||
| var mnemonic = hdnode_1.entropyToMnemonic(entropy); | ||
| var node = hdnode_1.HDNode.fromMnemonic(mnemonic).derivePath(path); | ||
| if (node.privateKey != account.privateKey) { | ||
| reject(new Error("mnemonic mismatch")); | ||
| return null; | ||
| } | ||
| account.mnemonic = node.mnemonic; | ||
| account.path = node.path; | ||
| } | ||
| return new KeystoreAccount(account); | ||
| }; | ||
| return new Promise(function (resolve, reject) { | ||
| var kdf = utils_1.searchPath(data, "crypto/kdf"); | ||
| if (kdf && typeof (kdf) === "string") { | ||
| if (kdf.toLowerCase() === "scrypt") { | ||
| var salt = utils_1.looseArrayify(utils_1.searchPath(data, "crypto/kdfparams/salt")); | ||
| var N = parseInt(utils_1.searchPath(data, "crypto/kdfparams/n")); | ||
| var r = parseInt(utils_1.searchPath(data, "crypto/kdfparams/r")); | ||
| var p = parseInt(utils_1.searchPath(data, "crypto/kdfparams/p")); | ||
| if (!N || !r || !p) { | ||
| reject(new Error("unsupported key-derivation function parameters")); | ||
| return; | ||
| } | ||
| // Make sure N is a power of 2 | ||
| if ((N & (N - 1)) !== 0) { | ||
| reject(new Error("unsupported key-derivation function parameter value for N")); | ||
| return; | ||
| } | ||
| var dkLen = parseInt(utils_1.searchPath(data, "crypto/kdfparams/dklen")); | ||
| if (dkLen !== 32) { | ||
| reject(new Error("unsupported key-derivation derived-key length")); | ||
| return; | ||
| } | ||
| if (progressCallback) { | ||
| progressCallback(0); | ||
| } | ||
| scrypt_js_1.default(passwordBytes, salt, N, r, p, 64, function (error, progress, key) { | ||
| if (error) { | ||
| error.progress = progress; | ||
| reject(error); | ||
| return __awaiter(this, void 0, void 0, function () { | ||
| var data, passwordBytes, decrypt, computeMAC, getAccount, kdf, salt, N, r, p, dkLen, key, salt, prfFunc, prf, c, dkLen, key; | ||
| return __generator(this, function (_a) { | ||
| switch (_a.label) { | ||
| case 0: | ||
| data = JSON.parse(json); | ||
| passwordBytes = utils_1.getPassword(password); | ||
| decrypt = function (key, ciphertext) { | ||
| var cipher = utils_1.searchPath(data, "crypto/cipher"); | ||
| if (cipher === "aes-128-ctr") { | ||
| var iv = utils_1.looseArrayify(utils_1.searchPath(data, "crypto/cipherparams/iv")); | ||
| var counter = new aes_js_1.default.Counter(iv); | ||
| var aesCtr = new aes_js_1.default.ModeOfOperation.ctr(key, counter); | ||
| return bytes_1.arrayify(aesCtr.decrypt(ciphertext)); | ||
| } | ||
| return null; | ||
| }; | ||
| computeMAC = function (derivedHalf, ciphertext) { | ||
| return keccak256_1.keccak256(bytes_1.concat([derivedHalf, ciphertext])); | ||
| }; | ||
| getAccount = function (key) { | ||
| return __awaiter(this, void 0, void 0, function () { | ||
| var ciphertext, computedMAC, privateKey, mnemonicKey, address, check, account, mnemonicCiphertext, mnemonicIv, mnemonicCounter, mnemonicAesCtr, path, entropy, mnemonic, node; | ||
| return __generator(this, function (_a) { | ||
| ciphertext = utils_1.looseArrayify(utils_1.searchPath(data, "crypto/ciphertext")); | ||
| computedMAC = bytes_1.hexlify(computeMAC(key.slice(16, 32), ciphertext)).substring(2); | ||
| if (computedMAC !== utils_1.searchPath(data, "crypto/mac").toLowerCase()) { | ||
| throw new Error("invalid password"); | ||
| } | ||
| privateKey = decrypt(key.slice(0, 16), ciphertext); | ||
| mnemonicKey = key.slice(32, 64); | ||
| if (!privateKey) { | ||
| throw new Error("unsupported cipher"); | ||
| } | ||
| address = transactions_1.computeAddress(privateKey); | ||
| if (data.address) { | ||
| check = data.address.toLowerCase(); | ||
| if (check.substring(0, 2) !== "0x") { | ||
| check = "0x" + check; | ||
| } | ||
| if (address_1.getAddress(check) !== address) { | ||
| throw new Error("address mismatch"); | ||
| } | ||
| } | ||
| account = { | ||
| _isKeystoreAccount: true, | ||
| address: address, | ||
| privateKey: bytes_1.hexlify(privateKey) | ||
| }; | ||
| // Version 0.1 x-ethers metadata must contain an encrypted mnemonic phrase | ||
| if (utils_1.searchPath(data, "x-ethers/version") === "0.1") { | ||
| mnemonicCiphertext = utils_1.looseArrayify(utils_1.searchPath(data, "x-ethers/mnemonicCiphertext")); | ||
| mnemonicIv = utils_1.looseArrayify(utils_1.searchPath(data, "x-ethers/mnemonicCounter")); | ||
| mnemonicCounter = new aes_js_1.default.Counter(mnemonicIv); | ||
| mnemonicAesCtr = new aes_js_1.default.ModeOfOperation.ctr(mnemonicKey, mnemonicCounter); | ||
| path = utils_1.searchPath(data, "x-ethers/path") || hdnode_1.defaultPath; | ||
| entropy = bytes_1.arrayify(mnemonicAesCtr.decrypt(mnemonicCiphertext)); | ||
| mnemonic = hdnode_1.entropyToMnemonic(entropy); | ||
| node = hdnode_1.HDNode.fromMnemonic(mnemonic).derivePath(path); | ||
| if (node.privateKey != account.privateKey) { | ||
| throw new Error("mnemonic mismatch"); | ||
| } | ||
| account.mnemonic = node.mnemonic; | ||
| account.path = node.path; | ||
| } | ||
| return [2 /*return*/, new KeystoreAccount(account)]; | ||
| }); | ||
| }); | ||
| }; | ||
| kdf = utils_1.searchPath(data, "crypto/kdf"); | ||
| if (!(kdf && typeof (kdf) === "string")) return [3 /*break*/, 3]; | ||
| if (!(kdf.toLowerCase() === "scrypt")) return [3 /*break*/, 2]; | ||
| salt = utils_1.looseArrayify(utils_1.searchPath(data, "crypto/kdfparams/salt")); | ||
| N = parseInt(utils_1.searchPath(data, "crypto/kdfparams/n")); | ||
| r = parseInt(utils_1.searchPath(data, "crypto/kdfparams/r")); | ||
| p = parseInt(utils_1.searchPath(data, "crypto/kdfparams/p")); | ||
| if (!N || !r || !p) { | ||
| throw new Error("unsupported key-derivation function parameters"); | ||
| } | ||
| else if (key) { | ||
| key = bytes_1.arrayify(key); | ||
| var account = getAccount(key, reject); | ||
| if (!account) { | ||
| return; | ||
| // Make sure N is a power of 2 | ||
| if ((N & (N - 1)) !== 0) { | ||
| throw new Error("unsupported key-derivation function parameter value for N"); | ||
| } | ||
| dkLen = parseInt(utils_1.searchPath(data, "crypto/kdfparams/dklen")); | ||
| if (dkLen !== 32) { | ||
| throw new Error("unsupported key-derivation derived-key length"); | ||
| } | ||
| return [4 /*yield*/, scrypt.scrypt(passwordBytes, salt, N, r, p, 64, progressCallback)]; | ||
| case 1: | ||
| key = _a.sent(); | ||
| //key = arrayify(key); | ||
| return [2 /*return*/, getAccount(key)]; | ||
| case 2: | ||
| if (kdf.toLowerCase() === "pbkdf2") { | ||
| salt = utils_1.looseArrayify(utils_1.searchPath(data, "crypto/kdfparams/salt")); | ||
| prfFunc = null; | ||
| prf = utils_1.searchPath(data, "crypto/kdfparams/prf"); | ||
| if (prf === "hmac-sha256") { | ||
| prfFunc = "sha256"; | ||
| } | ||
| if (progressCallback) { | ||
| progressCallback(1); | ||
| else if (prf === "hmac-sha512") { | ||
| prfFunc = "sha512"; | ||
| } | ||
| resolve(account); | ||
| else { | ||
| throw new Error("unsupported prf"); | ||
| } | ||
| c = parseInt(utils_1.searchPath(data, "crypto/kdfparams/c")); | ||
| dkLen = parseInt(utils_1.searchPath(data, "crypto/kdfparams/dklen")); | ||
| if (dkLen !== 32) { | ||
| throw new Error("unsupported key-derivation derived-key length"); | ||
| } | ||
| key = bytes_1.arrayify(pbkdf2_1.pbkdf2(passwordBytes, salt, c, dkLen, prfFunc)); | ||
| return [2 /*return*/, getAccount(key)]; | ||
| } | ||
| else if (progressCallback) { | ||
| return progressCallback(progress); | ||
| } | ||
| }); | ||
| _a.label = 3; | ||
| case 3: throw new Error("unsupported key-derivation function"); | ||
| } | ||
| else if (kdf.toLowerCase() === "pbkdf2") { | ||
| var salt = utils_1.looseArrayify(utils_1.searchPath(data, "crypto/kdfparams/salt")); | ||
| var prfFunc = null; | ||
| var prf = utils_1.searchPath(data, "crypto/kdfparams/prf"); | ||
| if (prf === "hmac-sha256") { | ||
| prfFunc = "sha256"; | ||
| } | ||
| else if (prf === "hmac-sha512") { | ||
| prfFunc = "sha512"; | ||
| } | ||
| else { | ||
| reject(new Error("unsupported prf")); | ||
| return; | ||
| } | ||
| var c = parseInt(utils_1.searchPath(data, "crypto/kdfparams/c")); | ||
| var dkLen = parseInt(utils_1.searchPath(data, "crypto/kdfparams/dklen")); | ||
| if (dkLen !== 32) { | ||
| reject(new Error("unsupported key-derivation derived-key length")); | ||
| return; | ||
| } | ||
| var key = bytes_1.arrayify(pbkdf2_1.pbkdf2(passwordBytes, salt, c, dkLen, prfFunc)); | ||
| var account = getAccount(key, reject); | ||
| if (!account) { | ||
| return; | ||
| } | ||
| resolve(account); | ||
| } | ||
| else { | ||
| reject(new Error("unsupported key-derivation function")); | ||
| } | ||
| } | ||
| else { | ||
| reject(new Error("unsupported key-derivation function")); | ||
| } | ||
| }); | ||
| }); | ||
@@ -279,82 +294,65 @@ } | ||
| } | ||
| return new Promise(function (resolve, reject) { | ||
| if (progressCallback) { | ||
| progressCallback(0); | ||
| // We take 64 bytes: | ||
| // - 32 bytes As normal for the Web3 secret storage (derivedKey, macPrefix) | ||
| // - 32 bytes AES key to encrypt mnemonic with (required here to be Ethers Wallet) | ||
| return scrypt.scrypt(passwordBytes, salt, N, r, p, 64, progressCallback).then(function (key) { | ||
| key = bytes_1.arrayify(key); | ||
| // This will be used to encrypt the wallet (as per Web3 secret storage) | ||
| var derivedKey = key.slice(0, 16); | ||
| var macPrefix = key.slice(16, 32); | ||
| // This will be used to encrypt the mnemonic phrase (if any) | ||
| var mnemonicKey = key.slice(32, 64); | ||
| // Encrypt the private key | ||
| var counter = new aes_js_1.default.Counter(iv); | ||
| var aesCtr = new aes_js_1.default.ModeOfOperation.ctr(derivedKey, counter); | ||
| var ciphertext = bytes_1.arrayify(aesCtr.encrypt(privateKey)); | ||
| // Compute the message authentication code, used to check the password | ||
| var mac = keccak256_1.keccak256(bytes_1.concat([macPrefix, ciphertext])); | ||
| // See: https://github.com/ethereum/wiki/wiki/Web3-Secret-Storage-Definition | ||
| var data = { | ||
| address: account.address.substring(2).toLowerCase(), | ||
| id: uuid_1.default.v4({ random: uuidRandom }), | ||
| version: 3, | ||
| Crypto: { | ||
| cipher: "aes-128-ctr", | ||
| cipherparams: { | ||
| iv: bytes_1.hexlify(iv).substring(2), | ||
| }, | ||
| ciphertext: bytes_1.hexlify(ciphertext).substring(2), | ||
| kdf: "scrypt", | ||
| kdfparams: { | ||
| salt: bytes_1.hexlify(salt).substring(2), | ||
| n: N, | ||
| dklen: 32, | ||
| p: p, | ||
| r: r | ||
| }, | ||
| mac: mac.substring(2) | ||
| } | ||
| }; | ||
| // If we have a mnemonic, encrypt it into the JSON wallet | ||
| if (entropy) { | ||
| var mnemonicIv = random_1.randomBytes(16); | ||
| var mnemonicCounter = new aes_js_1.default.Counter(mnemonicIv); | ||
| var mnemonicAesCtr = new aes_js_1.default.ModeOfOperation.ctr(mnemonicKey, mnemonicCounter); | ||
| var mnemonicCiphertext = bytes_1.arrayify(mnemonicAesCtr.encrypt(entropy)); | ||
| var now = new Date(); | ||
| var timestamp = (now.getUTCFullYear() + "-" + | ||
| utils_1.zpad(now.getUTCMonth() + 1, 2) + "-" + | ||
| utils_1.zpad(now.getUTCDate(), 2) + "T" + | ||
| utils_1.zpad(now.getUTCHours(), 2) + "-" + | ||
| utils_1.zpad(now.getUTCMinutes(), 2) + "-" + | ||
| utils_1.zpad(now.getUTCSeconds(), 2) + ".0Z"); | ||
| data["x-ethers"] = { | ||
| client: client, | ||
| gethFilename: ("UTC--" + timestamp + "--" + data.address), | ||
| mnemonicCounter: bytes_1.hexlify(mnemonicIv).substring(2), | ||
| mnemonicCiphertext: bytes_1.hexlify(mnemonicCiphertext).substring(2), | ||
| path: path, | ||
| version: "0.1" | ||
| }; | ||
| } | ||
| // We take 64 bytes: | ||
| // - 32 bytes As normal for the Web3 secret storage (derivedKey, macPrefix) | ||
| // - 32 bytes AES key to encrypt mnemonic with (required here to be Ethers Wallet) | ||
| scrypt_js_1.default(passwordBytes, salt, N, r, p, 64, function (error, progress, key) { | ||
| if (error) { | ||
| error.progress = progress; | ||
| reject(error); | ||
| } | ||
| else if (key) { | ||
| key = bytes_1.arrayify(key); | ||
| // This will be used to encrypt the wallet (as per Web3 secret storage) | ||
| var derivedKey = key.slice(0, 16); | ||
| var macPrefix = key.slice(16, 32); | ||
| // This will be used to encrypt the mnemonic phrase (if any) | ||
| var mnemonicKey = key.slice(32, 64); | ||
| // Encrypt the private key | ||
| var counter = new aes_js_1.default.Counter(iv); | ||
| var aesCtr = new aes_js_1.default.ModeOfOperation.ctr(derivedKey, counter); | ||
| var ciphertext = bytes_1.arrayify(aesCtr.encrypt(privateKey)); | ||
| // Compute the message authentication code, used to check the password | ||
| var mac = keccak256_1.keccak256(bytes_1.concat([macPrefix, ciphertext])); | ||
| // See: https://github.com/ethereum/wiki/wiki/Web3-Secret-Storage-Definition | ||
| var data = { | ||
| address: account.address.substring(2).toLowerCase(), | ||
| id: uuid_1.default.v4({ random: uuidRandom }), | ||
| version: 3, | ||
| Crypto: { | ||
| cipher: "aes-128-ctr", | ||
| cipherparams: { | ||
| iv: bytes_1.hexlify(iv).substring(2), | ||
| }, | ||
| ciphertext: bytes_1.hexlify(ciphertext).substring(2), | ||
| kdf: "scrypt", | ||
| kdfparams: { | ||
| salt: bytes_1.hexlify(salt).substring(2), | ||
| n: N, | ||
| dklen: 32, | ||
| p: p, | ||
| r: r | ||
| }, | ||
| mac: mac.substring(2) | ||
| } | ||
| }; | ||
| // If we have a mnemonic, encrypt it into the JSON wallet | ||
| if (entropy) { | ||
| var mnemonicIv = random_1.randomBytes(16); | ||
| var mnemonicCounter = new aes_js_1.default.Counter(mnemonicIv); | ||
| var mnemonicAesCtr = new aes_js_1.default.ModeOfOperation.ctr(mnemonicKey, mnemonicCounter); | ||
| var mnemonicCiphertext = bytes_1.arrayify(mnemonicAesCtr.encrypt(entropy)); | ||
| var now = new Date(); | ||
| var timestamp = (now.getUTCFullYear() + "-" + | ||
| utils_1.zpad(now.getUTCMonth() + 1, 2) + "-" + | ||
| utils_1.zpad(now.getUTCDate(), 2) + "T" + | ||
| utils_1.zpad(now.getUTCHours(), 2) + "-" + | ||
| utils_1.zpad(now.getUTCMinutes(), 2) + "-" + | ||
| utils_1.zpad(now.getUTCSeconds(), 2) + ".0Z"); | ||
| data["x-ethers"] = { | ||
| client: client, | ||
| gethFilename: ("UTC--" + timestamp + "--" + data.address), | ||
| mnemonicCounter: bytes_1.hexlify(mnemonicIv).substring(2), | ||
| mnemonicCiphertext: bytes_1.hexlify(mnemonicCiphertext).substring(2), | ||
| path: path, | ||
| version: "0.1" | ||
| }; | ||
| } | ||
| if (progressCallback) { | ||
| progressCallback(1); | ||
| } | ||
| resolve(JSON.stringify(data)); | ||
| } | ||
| else if (progressCallback) { | ||
| return progressCallback(progress); | ||
| } | ||
| }); | ||
| return JSON.stringify(data); | ||
| }); | ||
| } | ||
| exports.encrypt = encrypt; |
+0
-14
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var bytes_1 = require("@ethersproject/bytes"); | ||
| //import { Description } from "@ethersproject/properties"; | ||
| var strings_1 = require("@ethersproject/strings"); | ||
| /* | ||
| export class Account extends Description implements ExternallyOwnedAccount { | ||
| readonly address: string; | ||
| readonly privateKey: string; | ||
| readonly mnemonic?: string; | ||
| readonly path?: string; | ||
| // static isAccount(value: any): value is Account { | ||
| // return Description._isType(value); | ||
| // } | ||
| } | ||
| //defineReadOnly(Account, "name", "Account"); | ||
| */ | ||
| function looseArrayify(hexString) { | ||
@@ -20,0 +6,0 @@ if (typeof (hexString) === 'string' && hexString.substring(0, 2) !== '0x') { |
+3
-3
| { | ||
| "name": "@ethersproject/json-wallets", | ||
| "version": "5.0.0-beta.132", | ||
| "version": "5.0.0-beta.133", | ||
| "description": "Wallet management utilities for KeyStore and Crowdsale JSON wallets.", | ||
@@ -22,3 +22,3 @@ "main": "./lib/index.js", | ||
| "aes-js": "3.0.0", | ||
| "scrypt-js": "2.0.4", | ||
| "scrypt-js": "3.0.0", | ||
| "uuid": "2.0.1" | ||
@@ -42,3 +42,3 @@ }, | ||
| "ethereum": "donations.ethers.eth", | ||
| "tarballHash": "0xab2892299474552aaf1a668910e0cdb9960cee61ba516b48beb5710f68455bc7" | ||
| "tarballHash": "0xee2f333ff6799cb86c0539957b746c57098d9050bd0760bed576d42ceb150825" | ||
| } |
+3
-5
@@ -25,7 +25,5 @@ declare module "aes-js" { | ||
| declare module "scrypt-js" { | ||
| export class ScryptError extends Error { | ||
| progress: number; | ||
| } | ||
| export type ScryptCallback = (error: ScryptError, progress: number, key: Uint8Array) => void; | ||
| export default function(password: Uint8Array, salt: Uint8Array, N: number, r: number, p: number, dkLen: number, callback: ScryptCallback): void; | ||
| export type ProgressCallback = (progress: number) => boolean | void; | ||
| export function scrypt(password: Uint8Array, salt: Uint8Array, N: number, r: number, p: number, dkLen: number, callback?: ProgressCallback): Promise<Uint8Array>; | ||
| export function scryptSync(password: Uint8Array, salt: Uint8Array, N: number, r: number, p: number, dkLen: number): Uint8Array; | ||
| } | ||
@@ -32,0 +30,0 @@ |
53314
1.69%1143
-6.46%+ Added
- Removed
Updated