mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-02-22 23:08:07 +01:00
REF: upgrade bech32, bip39 and crypto-js
This commit is contained in:
parent
55cb3daf4d
commit
05c222f2cb
7 changed files with 89 additions and 58 deletions
|
@ -1,7 +1,6 @@
|
|||
import bech32 from 'bech32';
|
||||
import { bech32 } from 'bech32';
|
||||
import bolt11 from 'bolt11';
|
||||
const CryptoJS = require('crypto-js');
|
||||
|
||||
const createHash = require('create-hash');
|
||||
|
||||
/**
|
||||
|
@ -20,7 +19,7 @@ export default class Lnurl {
|
|||
}
|
||||
|
||||
static findlnurl(bodyOfText) {
|
||||
var res = /^(?:http.*[&?]lightning=|lightning:)?(lnurl1[02-9ac-hj-np-z]+)/.exec(bodyOfText.toLowerCase());
|
||||
const res = /^(?:http.*[&?]lightning=|lightning:)?(lnurl1[02-9ac-hj-np-z]+)/.exec(bodyOfText.toLowerCase());
|
||||
if (res) {
|
||||
return res[1];
|
||||
}
|
||||
|
@ -97,7 +96,14 @@ export default class Lnurl {
|
|||
if (!this._lnurlPayServicePayload) throw new Error('this._lnurlPayServicePayload is not set');
|
||||
if (!this._lnurlPayServicePayload.callback) throw new Error('this._lnurlPayServicePayload.callback is not set');
|
||||
if (amountSat < this._lnurlPayServicePayload.min || amountSat > this._lnurlPayServicePayload.max)
|
||||
throw new Error('amount is not right, ' + amountSat + ' should be between ' + this._lnurlPayServicePayload.min + ' and ' + this._lnurlPayServicePayload.max);
|
||||
throw new Error(
|
||||
'amount is not right, ' +
|
||||
amountSat +
|
||||
' should be between ' +
|
||||
this._lnurlPayServicePayload.min +
|
||||
' and ' +
|
||||
this._lnurlPayServicePayload.max,
|
||||
);
|
||||
const nonce = Math.floor(Math.random() * 2e16).toString(16);
|
||||
const separator = this._lnurlPayServicePayload.callback.indexOf('?') === -1 ? '?' : '&';
|
||||
const urlToFetch = this._lnurlPayServicePayload.callback + separator + 'amount=' + Math.floor(amountSat * 1000) + '&nonce=' + nonce;
|
||||
|
@ -131,8 +137,8 @@ export default class Lnurl {
|
|||
const data = reply;
|
||||
|
||||
// parse metadata and extract things from it
|
||||
var image;
|
||||
var description;
|
||||
let image;
|
||||
let description;
|
||||
const kvs = JSON.parse(data.metadata);
|
||||
for (let i = 0; i < kvs.length; i++) {
|
||||
const [k, v] = kvs[i];
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import bip39 from 'bip39';
|
||||
import * as bip39 from 'bip39';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import b58 from 'bs58check';
|
||||
|
||||
|
@ -1116,7 +1116,7 @@ export class AbstractHDElectrumWallet extends AbstractHDWallet {
|
|||
* @returns {string} Hex fingerprint
|
||||
*/
|
||||
static mnemonicToFingerprint(mnemonic) {
|
||||
const seed = bip39.mnemonicToSeed(mnemonic);
|
||||
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
||||
return AbstractHDElectrumWallet.seedToFingerprint(seed);
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ export class AbstractHDWallet extends LegacyWallet {
|
|||
*/
|
||||
_getSeed() {
|
||||
const mnemonic = this.secret;
|
||||
return bip39.mnemonicToSeed(mnemonic);
|
||||
return bip39.mnemonicToSeedSync(mnemonic);
|
||||
}
|
||||
|
||||
setSecret(newSecret) {
|
||||
|
@ -69,7 +69,7 @@ export class AbstractHDWallet extends LegacyWallet {
|
|||
}
|
||||
|
||||
getMnemonicToSeedHex() {
|
||||
return bip39.mnemonicToSeedHex(this.secret);
|
||||
return bip39.mnemonicToSeedSync(this.secret).toString('hex');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { AbstractHDElectrumWallet } from './abstract-hd-electrum-wallet';
|
||||
import bip39 from 'bip39';
|
||||
import * as bip39 from 'bip39';
|
||||
import b58 from 'bs58check';
|
||||
import { decodeUR } from 'bc-ur';
|
||||
const BlueElectrum = require('../../blue_modules/BlueElectrum');
|
||||
|
@ -298,7 +298,7 @@ export class MultisigHDWallet extends AbstractHDElectrumWallet {
|
|||
if (mnemonic.startsWith(ELECTRUM_SEED_PREFIX)) {
|
||||
seed = MultisigHDWallet.convertElectrumMnemonicToSeed(mnemonic);
|
||||
} else {
|
||||
seed = bip39.mnemonicToSeed(mnemonic);
|
||||
seed = bip39.mnemonicToSeedSync(mnemonic);
|
||||
}
|
||||
|
||||
const root = bitcoin.bip32.fromSeed(seed);
|
||||
|
@ -835,7 +835,7 @@ export class MultisigHDWallet extends AbstractHDElectrumWallet {
|
|||
// dont sign more than we need, otherwise there will be "Too many signatures" error
|
||||
continue;
|
||||
}
|
||||
let seed = bip39.mnemonicToSeed(cosigner);
|
||||
let seed = bip39.mnemonicToSeedSync(cosigner);
|
||||
if (cosigner.startsWith(ELECTRUM_SEED_PREFIX)) {
|
||||
seed = MultisigHDWallet.convertElectrumMnemonicToSeed(cosigner);
|
||||
}
|
||||
|
@ -979,7 +979,7 @@ export class MultisigHDWallet extends AbstractHDElectrumWallet {
|
|||
for (const [cosignerIndex, cosigner] of this._cosigners.entries()) {
|
||||
if (!MultisigHDWallet.isXpubString(cosigner)) {
|
||||
// ok this is a mnemonic, lets try to sign
|
||||
const seed = bip39.mnemonicToSeed(cosigner);
|
||||
const seed = bip39.mnemonicToSeedSync(cosigner);
|
||||
const hdRoot = bitcoin.bip32.fromSeed(seed);
|
||||
try {
|
||||
psbt.signInputHD(cc, hdRoot);
|
||||
|
@ -995,7 +995,7 @@ export class MultisigHDWallet extends AbstractHDElectrumWallet {
|
|||
// correctly points to `/internal/index`, so we extract pubkey from our stored mnemonics+path and
|
||||
// match it to the one provided in PSBT's input, and if we have a match - we are in luck! we can sign
|
||||
// with this private key.
|
||||
const seed = bip39.mnemonicToSeed(cosigner);
|
||||
const seed = bip39.mnemonicToSeedSync(cosigner);
|
||||
const root = HDNode.fromSeed(seed);
|
||||
const splt = derivation.path.split('/');
|
||||
const internal = +splt[splt.length - 2];
|
||||
|
|
99
package-lock.json
generated
99
package-lock.json
generated
|
@ -4519,27 +4519,14 @@
|
|||
}
|
||||
},
|
||||
"assert": {
|
||||
"version": "1.5.0",
|
||||
"resolved": "https://registry.npmjs.org/assert/-/assert-1.5.0.tgz",
|
||||
"integrity": "sha512-EDsgawzwoun2CZkCgtxJbv392v4nbk9XDD06zI+kQYoBM/3RBWLlEyJARDOmhAAosBjWACEkKL6S+lIZtcAubA==",
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/assert/-/assert-2.0.0.tgz",
|
||||
"integrity": "sha512-se5Cd+js9dXJnu6Ag2JFc00t+HmHOen+8Q+L7O9zI0PqQXr20uk2J0XQqMxZEeo5U50o8Nvmmx7dZrl+Ufr35A==",
|
||||
"requires": {
|
||||
"object-assign": "^4.1.1",
|
||||
"util": "0.10.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"inherits": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz",
|
||||
"integrity": "sha1-sX0I0ya0Qj5Wjv9xn5GwscvfafE="
|
||||
},
|
||||
"util": {
|
||||
"version": "0.10.3",
|
||||
"resolved": "https://registry.npmjs.org/util/-/util-0.10.3.tgz",
|
||||
"integrity": "sha1-evsa/lCAUkZInj23/g7TeTNqwPk=",
|
||||
"requires": {
|
||||
"inherits": "2.0.1"
|
||||
}
|
||||
}
|
||||
"es6-object-assign": "^1.1.0",
|
||||
"is-nan": "^1.2.1",
|
||||
"object-is": "^1.0.1",
|
||||
"util": "^0.12.0"
|
||||
}
|
||||
},
|
||||
"assert-plus": {
|
||||
|
@ -5277,9 +5264,9 @@
|
|||
}
|
||||
},
|
||||
"bech32": {
|
||||
"version": "1.1.4",
|
||||
"resolved": "https://registry.npmjs.org/bech32/-/bech32-1.1.4.tgz",
|
||||
"integrity": "sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ=="
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/bech32/-/bech32-2.0.0.tgz",
|
||||
"integrity": "sha512-LcknSilhIGatDAsY1ak2I8VtGaHNhgMSYVxFrGLXv+xLHytaKZKcaUJJUE7qmBr7h33o5YQwP55pMI0xmkpJwg=="
|
||||
},
|
||||
"big-integer": {
|
||||
"version": "1.6.48",
|
||||
|
@ -5339,15 +5326,21 @@
|
|||
}
|
||||
},
|
||||
"bip39": {
|
||||
"version": "2.6.0",
|
||||
"resolved": "https://registry.npmjs.org/bip39/-/bip39-2.6.0.tgz",
|
||||
"integrity": "sha512-RrnQRG2EgEoqO24ea+Q/fftuPUZLmrEM3qNhhGsA3PbaXaCW791LTzPuVyx/VprXQcTbPJ3K3UeTna8ZnVl2sg==",
|
||||
"version": "3.0.4",
|
||||
"resolved": "https://registry.npmjs.org/bip39/-/bip39-3.0.4.tgz",
|
||||
"integrity": "sha512-YZKQlb752TrUWqHWj7XAwCSjYEgGAk+/Aas3V7NyjQeZYsztO8JnQUaCWhcnL4T+jL8nvB8typ2jRPzTlgugNw==",
|
||||
"requires": {
|
||||
"@types/node": "11.11.6",
|
||||
"create-hash": "^1.1.0",
|
||||
"pbkdf2": "^3.0.9",
|
||||
"randombytes": "^2.0.1",
|
||||
"safe-buffer": "^5.0.1",
|
||||
"unorm": "^1.3.3"
|
||||
"randombytes": "^2.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/node": {
|
||||
"version": "11.11.6",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-11.11.6.tgz",
|
||||
"integrity": "sha512-Exw4yUWMBXM3X+8oqzJNRqZSwUAaS4+7NdvHqQuFi/d+synz++xmX3QIf+BFqneW8N31R8Ky+sikfZUXq07ggQ=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"bip66": {
|
||||
|
@ -5383,6 +5376,13 @@
|
|||
"typeforce": "^1.11.3",
|
||||
"varuint-bitcoin": "^1.0.4",
|
||||
"wif": "^2.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"bech32": {
|
||||
"version": "1.1.4",
|
||||
"resolved": "https://registry.npmjs.org/bech32/-/bech32-1.1.4.tgz",
|
||||
"integrity": "sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"bitcoinjs-message": {
|
||||
|
@ -5396,6 +5396,13 @@
|
|||
"create-hash": "^1.1.2",
|
||||
"secp256k1": "^3.0.1",
|
||||
"varuint-bitcoin": "^1.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"bech32": {
|
||||
"version": "1.1.4",
|
||||
"resolved": "https://registry.npmjs.org/bech32/-/bech32-1.1.4.tgz",
|
||||
"integrity": "sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"bl": {
|
||||
|
@ -5464,6 +5471,11 @@
|
|||
"secp256k1": "^3.4.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"bech32": {
|
||||
"version": "1.1.4",
|
||||
"resolved": "https://registry.npmjs.org/bech32/-/bech32-1.1.4.tgz",
|
||||
"integrity": "sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ=="
|
||||
},
|
||||
"bitcoinjs-lib": {
|
||||
"version": "3.3.2",
|
||||
"resolved": "https://registry.npmjs.org/bitcoinjs-lib/-/bitcoinjs-lib-3.3.2.tgz",
|
||||
|
@ -6472,9 +6484,9 @@
|
|||
}
|
||||
},
|
||||
"crypto-js": {
|
||||
"version": "3.1.9-1",
|
||||
"resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-3.1.9-1.tgz",
|
||||
"integrity": "sha1-/aGedh/Ad+Af+/3G6f38WeiAbNg="
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.0.0.tgz",
|
||||
"integrity": "sha512-bzHZN8Pn+gS7DQA6n+iUmBfl0hO5DJq++QP3U6uTucDtk/0iGpXd/Gg7CGR0p8tJhofJyaKoWBuJI4eAO00BBg=="
|
||||
},
|
||||
"css-select": {
|
||||
"version": "2.1.0",
|
||||
|
@ -7213,6 +7225,11 @@
|
|||
"is-symbol": "^1.0.2"
|
||||
}
|
||||
},
|
||||
"es6-object-assign": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/es6-object-assign/-/es6-object-assign-1.1.0.tgz",
|
||||
"integrity": "sha1-wsNYJlYkfDnqEHyx5mUrb58kUjw="
|
||||
},
|
||||
"es6-promise": {
|
||||
"version": "4.2.8",
|
||||
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz",
|
||||
|
@ -9798,6 +9815,15 @@
|
|||
"is-extglob": "^2.1.1"
|
||||
}
|
||||
},
|
||||
"is-nan": {
|
||||
"version": "1.3.2",
|
||||
"resolved": "https://registry.npmjs.org/is-nan/-/is-nan-1.3.2.tgz",
|
||||
"integrity": "sha512-E+zBKpQ2t6MEo1VsonYmluk9NxGrbzpeeLC2xIViuO2EjU2xsXsBPwTr3Ykv9l08UYEVEdWeRZNouaZqF6RN0w==",
|
||||
"requires": {
|
||||
"call-bind": "^1.0.0",
|
||||
"define-properties": "^1.1.3"
|
||||
}
|
||||
},
|
||||
"is-negative-zero": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.1.tgz",
|
||||
|
@ -18715,6 +18741,10 @@
|
|||
"object-assign": "^4.1.1"
|
||||
}
|
||||
},
|
||||
"scryptsy": {
|
||||
"version": "file:blue_modules/scryptsy",
|
||||
"integrity": "sha512-1CdSqHQowJBnMAFyPEBRfqag/YP9OF394FV+4YREIJX4ljD7OxvQRDayyoyyCk+senRjSkP6VnUNQmVQqB6g7w=="
|
||||
},
|
||||
"secp256k1": {
|
||||
"version": "3.8.0",
|
||||
"resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-3.8.0.tgz",
|
||||
|
@ -20084,11 +20114,6 @@
|
|||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
|
||||
"integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg=="
|
||||
},
|
||||
"unorm": {
|
||||
"version": "1.6.0",
|
||||
"resolved": "https://registry.npmjs.org/unorm/-/unorm-1.6.0.tgz",
|
||||
"integrity": "sha512-b2/KCUlYZUeA7JFUuRJZPUtr4gZvBh7tavtv4fvk4+KV9pfGiR6CQAQAWl49ZpR3ts2dk4FYkP7EIgDJoiOLDA=="
|
||||
},
|
||||
"unpipe": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
||||
|
|
10
package.json
10
package.json
|
@ -82,29 +82,29 @@
|
|||
"@react-native-community/blur": "3.6.0",
|
||||
"@react-native-community/masked-view": "0.1.10",
|
||||
"@react-native-community/push-notification-ios": "1.8.0",
|
||||
"@react-navigation/native": "5.9.4",
|
||||
"@react-navigation/drawer": "5.12.5",
|
||||
"@react-navigation/native": "5.9.4",
|
||||
"@react-navigation/stack": "5.14.4",
|
||||
"@remobile/react-native-qrcode-local-image": "https://github.com/BlueWallet/react-native-qrcode-local-image",
|
||||
"@sentry/react-native": "2.5.0-beta.1",
|
||||
"aez": "1.0.1",
|
||||
"amplitude-js": "7.4.4",
|
||||
"assert": "1.5.0",
|
||||
"assert": "2.0.0",
|
||||
"base-x": "3.0.8",
|
||||
"bc-bech32": "file:blue_modules/bc-bech32",
|
||||
"bc-ur": "file:blue_modules/bc-ur",
|
||||
"bech32": "1.1.4",
|
||||
"bech32": "2.0.0",
|
||||
"bignumber.js": "9.0.1",
|
||||
"bip21": "2.0.3",
|
||||
"bip32": "2.0.6",
|
||||
"bip39": "2.6.0",
|
||||
"bip39": "3.0.4",
|
||||
"bitcoinjs-lib": "5.2.0",
|
||||
"bitcoinjs-message": "2.2.0",
|
||||
"bolt11": "1.3.1",
|
||||
"buffer": "6.0.3",
|
||||
"buffer-reverse": "1.0.1",
|
||||
"coinselect": "3.1.12",
|
||||
"crypto-js": "3.1.9-1",
|
||||
"crypto-js": "4.0.0",
|
||||
"dayjs": "1.10.4",
|
||||
"detox": "18.12.0",
|
||||
"ecurve": "1.0.6",
|
||||
|
|
|
@ -158,7 +158,7 @@ export default class Selftest extends Component {
|
|||
const bip39 = require('bip39');
|
||||
const mnemonic =
|
||||
'honey risk juice trip orient galaxy win situate shoot anchor bounce remind horse traffic exotic since escape mimic ramp skin judge owner topple erode';
|
||||
const seed = bip39.mnemonicToSeed(mnemonic);
|
||||
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
||||
const root = bitcoin.bip32.fromSeed(seed);
|
||||
|
||||
const path = "m/49'/0'/0'/0/0";
|
||||
|
|
Loading…
Add table
Reference in a new issue