在 secword2seed 和 secword2keypair 里 放松对 isSecword 的检查,因为isSecword在安卓和安卓微信里不成功!
This commit is contained in:
		
							parent
							
								
									7e1d2ef6e1
								
							
						
					
					
						commit
						e96b61ed0d
					
				
							
								
								
									
										17
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								index.js
									
									
									
									
									
								
							| @ -242,7 +242,6 @@ module.exports = { | ||||
|     //  据测试, Purpose和CoinType都可以任意其他值,不必要如规范所示;' 引号可有可无,导致的密钥不一样;
 | ||||
|     //  Account 最大为 0x7FFFFFFF, Change/Index 最大均为 0xFFFFFFFF(=4294967295)
 | ||||
|     //  但可以不断延伸下去:/xxx/xxx/xxx/xxx/...
 | ||||
|     if (this.isSecword(secword)){ | ||||
|     option=option||{} | ||||
|     option.coin=my.COIN_LIST.indexOf(option.coin)>=0?option.coin:my.COIN | ||||
| 
 | ||||
| @ -281,7 +280,6 @@ module.exports = { | ||||
|         pubkey: key.publicKey.toString('hex') | ||||
|       } | ||||
|     } | ||||
|     } | ||||
|     return null | ||||
|   } | ||||
|   , | ||||
| @ -322,9 +320,9 @@ module.exports = { | ||||
|     option.coin=my.COIN_LIST.indexOf(option.coin)>=0?option.coin:my.COIN | ||||
|     if (this.isSeckey(seckey) && seckey.length===64){ // 只能用于32字节的私钥(BTC, ETH)。也就是不能用于 TIC 的私钥。
 | ||||
|       let curve = my.CURVE_LIST.indexOf(option.curve)>=0?option.curve:my.CURVE // 默认为 secp256k1
 | ||||
|       // return new crypto.createECDH(curve).setPrivateKey(seckey,'hex').getPublicKey('hex', option.compress===false?'uncompressed':'compressed') // ecdh.getPublicKey(不加参数) 默认为 'compressed'。用 HBuilderX 2.6.4 打包成 app 后 setPrivateKey() 报错:TypeError: null is not an object (evaluating 'this.rand.getBytes')
 | ||||
|       // return new crypto.createECDH(curve).setPrivateKey(seckey,'hex').getPublicKey('hex', option.compress===false?'uncompressed':'compressed') // ecdh.getPublicKey(不加参数) 默认为 'compressed'。用 HBuilderX 2.6.4 打包成ios或安卓 app 后 setPrivateKey() 报错:TypeError: null is not an object (evaluating 'this.rand.getBytes')
 | ||||
|       // 从 nodejs 10.0 开始,还有 crypto.ECDH.convertKey 方法,更直接。但可惜,浏览器里不存在 crypto.ECDH。
 | ||||
|       return this.buf2hex(require('secp256k1').publicKeyCreate(Buffer.from(seckey, 'hex'), option.compress!==false)) // 可用于浏览器。secp256k1缺省或true时输出压缩公钥,false时输出非压缩公钥。
 | ||||
|       return this.buf2hex(secp256k1.publicKeyCreate(Buffer.from(seckey, 'hex'), option.compress!==false)) // 可用于浏览器。secp256k1缺省或true时输出压缩公钥,false时输出非压缩公钥。
 | ||||
|       // 或者 bitcorelib.PublicKey.fromPrivateKey(new bitcorelib.PrivateKey(seckey)).toString('hex') // 可用于浏览器
 | ||||
|       // 或者 const ecc = require('eccrypto')
 | ||||
|       // if (option.compress===false){
 | ||||
| @ -450,7 +448,8 @@ module.exports = { | ||||
|       let b64 = address.replace('-', '+').replace('_', '/') | ||||
|       let hex = Buffer.from(b64, 'base64').toString('hex') | ||||
|       let [all, prefix, position, checksum] = hex.match(/^([\da-fA-F]{2})([\da-fA-F]{40})([\da-fA-F]{6})$/) // 内容合法
 | ||||
|       return this.hash(this.hash(prefix+position)).slice(0,6) === checksum // [todo] 校验码里要不要包含 prefix?
 | ||||
|       if (this.hash(this.hash(prefix+position)).slice(0,6) === checksum) // [todo] 校验码里要不要包含 prefix?
 | ||||
|         return 'TIC' | ||||
|     } | ||||
|     return null | ||||
|   } | ||||
| @ -460,12 +459,8 @@ module.exports = { | ||||
|     return this.position2address(this.pubkey2position(pubkey, option), option) | ||||
|   } | ||||
|   , | ||||
|   secword2seed(secword, pass) { // 遵循bip39的算法。和 ether.HDNode.mnemonic2Seed 结果一样,是64字节的种子。
 | ||||
|     if (this.isSecword(secword)) { //  bip39.validateMnemonic(secword)) {
 | ||||
|       return bip39.mnemonicToSeedSync(secword, pass).toString('hex') // 结果一致于 new BitcoreMnemonic(secword).toSeed(pass).toString('hex') 或 ethers.HDNode.mnemonic2Seed(secword)
 | ||||
| //      return new BitcoreMnemonic(secword).toSeed(pass).toString('hex')
 | ||||
|     } | ||||
|     return null | ||||
|   secword2seed(secword, pass) { // 遵循bip39的算法。和 ether.HDNode.mnemonic2Seed 结果一样,是64字节的种子。其实
 | ||||
|     return bip39.mnemonicToSeedSync(secword, pass).toString('hex') // 结果一致于 new BitcoreMnemonic(secword).toSeed(pass).toString('hex') 或 ethers.HDNode.mnemonic2Seed(secword)。其实,bip39.mnemonicToSeedSync 也接受不合法的 secword,只要是个string就行。
 | ||||
|   } | ||||
|   , | ||||
|   randomSecword(lang='english'){ // accepts case-insensitive lang, such as 'chinese, cn, tw, en'
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user