From cdeb44f43fc062061b3473c6ada3a12dad83c82c Mon Sep 17 00:00:00 2001 From: Luk Lu Date: Sat, 10 Dec 2022 19:12:14 +0800 Subject: [PATCH] update to standard .gitignore --- .gitignore | 105 +++++++++++++++++++++++++++++++++-------------------- ticc.js | 63 +++++++------------------------- 2 files changed, 79 insertions(+), 89 deletions(-) diff --git a/.gitignore b/.gitignore index dc3e90b..46bb0da 100644 --- a/.gitignore +++ b/.gitignore @@ -1,63 +1,88 @@ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. -node_modules/ -/test/unit/coverage/ -/test/e2e/reports/ +### 目录 ################################################################# + +# 通用 .svn/ +.deploy_git/ .idea/ .sass-cache/ -.deploy_git/ +/test/unit/coverage/ +/test/e2e/reports/ +node_modules/ +*.apk +*.min.js +*.min.css +*.min.html +*.iml +*.njsproj +*.ntvs* +*.sw* +*.sln +*.suo .gitattributes -_desktop.ini -.DS_Store -.thumbnails -Thumbs.db -thumbs.db .umi .umi-production npm-debug.log* yarn-debug.log* yarn-error.log* +yarn.lock selenium-debug.log -package-lock.json -*.iml -*.njsproj -*.ntvs* -*.sln -*.suo -._* -.$* -~$* +Thumbs.db +thumbs.db +_desktop.ini -.bashrc_custom +# vue-cli 项目 +/dist/ + +# 来自 vue-cli 创建项目的 .gitignore +.project # hexo -db.json +/public/ -# 客户端 uniapp 项目 -/unpackage/* -!/unpackage/res/ +# Hardhat +/artifacts/ +/cache/ +# seafile 临时文件 +._* + +.$* + +# office 暂存文件 +~$* + +# 用户shell配置脚本 +.bashrc_custom + +# 苹果系统临时文件 +.DS_Store + +# 安卓缓存文件夹 +.thumbnails + +# local env files +.env.local +.env.*.local + +# hexo +/db.json + +# wo +envar-*.gitignore.js +# 服务端 /_archive/* /_datastore/* -/_logstore/* /_filestore/* +/_logstore/* /_webroot/* -/dist/ -*.apk -*.min.js -*.min.css -*.min.html -/pages4loader.json5 -envar-web-custom.js -envar-deploy-secret.js - -# hexo 项目 -public/ - -# 服务端(server or uniapp-uniCloud)项目 -envar-base-custom.js -envar-base-dynamic.js -envar-base-secret.js +/_ssl/* +# uniapp 客户端 +/unpackage/* +!/unpackage/res/ +package-lock.json +pages4loader.json5 +# 保留 !.gitkeep diff --git a/ticc.js b/ticc.js index 1869310..73e9524 100644 --- a/ticc.js +++ b/ticc.js @@ -114,7 +114,7 @@ class TicCrypto { * @return {Boolean} * @memberof TicCrypto */ - static is_secword ({ secword, mode = 'strict', lang } = {}) { + static is_secword ({ secword = '', mode = 'strict', lang } = {}) { // 注意 not all 12 words combinations are valid for both bitcore and bip39, because there are checksum in mnemonic. 另外,实际上bitcore和bip39对 12, 15, 18, 21, 24 长度的合法助记词都返回 true。 //// for bitcore-mnemonic. 注意,bitcore-mnemonic 对少于12词的会抛出异常,很蠢。 @@ -201,10 +201,7 @@ class TicCrypto { if (salt && typeof salt === 'string') data = data + this.hash_easy(salt) let inputEncoding = input // my.INPUT_LIST.includes(input)?input:my.INPUT // 'utf8', 'ascii' or 'latin1' for string data, default to utf8 if not specified; ignored for Buffer, TypedArray, or DataView. let outputEncoding = output === 'buf' ? undefined : output // (my.OUTPUT_LIST.includes(output)?output:my.OUTPUT) // output: 留空=》默认输出hex格式;或者手动指定 'buf', hex', 'latin1' or 'base64' - return crypto - .createHash(hasher) - .update(data, inputEncoding) - .digest(outputEncoding) + return crypto.createHash(hasher).update(data, inputEncoding).digest(outputEncoding) } return null } @@ -396,10 +393,7 @@ class TicCrypto { static pass_to_keypair ({ pass, hasher = my.HASHER } = {}) { // 如果使用其他机制,例如密码、随机数,不使用secword,也可生成keypair if (this.is_hashable({ data: pass })) { - var hashBuf = crypto - .createHash(hasher) - .update(pass) - .digest() + var hashBuf = crypto.createHash(hasher).update(pass).digest() var keypair = nacl.sign.keyPair.fromSeed(hashBuf) // nacl的seed要求是32字节 return { hash: hashBuf.toString('hex'), @@ -469,10 +463,7 @@ class TicCrypto { } if (tool === 'nacl') { // 采用自己的算法:bip39算法从secword到种子,hash后用 nacl.sign.keyPair.fromSeed()方法。 - let hashBuf = crypto - .createHash(hasher) - .update(this.secword_to_seed({ secword, pass })) - .digest() + let hashBuf = crypto.createHash(hasher).update(this.secword_to_seed({ secword, pass })).digest() let keypair = nacl.sign.keyPair.fromSeed(hashBuf) // nacl.sign.keyPair.fromSeed 要求32字节的种子,而 this.secword2seed生成的是64字节种子,所以要先做一次sha256 return { pubkey: Buffer.from(keypair.publicKey).toString('hex'), // 测试过 不能直接keypair.publicKey.toString('hex'),不是buffer类型 @@ -688,14 +679,8 @@ class TicCrypto { .digest('hex') .slice(-40) } else { - let h256buf = crypto - .createHash('sha256') - .update(Buffer.from(pubkey, 'hex')) - .digest() - let h160 = crypto - .createHash('ripemd160') - .update(h256buf) - .digest('hex') + let h256buf = crypto.createHash('sha256').update(Buffer.from(pubkey, 'hex')).digest() + let h160 = crypto.createHash('ripemd160').update(h256buf).digest('hex') return h160 } } @@ -718,9 +703,7 @@ class TicCrypto { if (coin === 'ETH' || coinFamily === 'ETH') { // 对以太坊,按照 EIP55,把纯位置转换为大小写敏感能自我验证的hex地址。仍然为20节=40符。 position = position.toLowerCase().replace('0x', '') - let hash = keccak('keccak256') - .update(position) - .digest('hex') + let hash = keccak('keccak256').update(position).digest('hex') address = '0x' for (var i = 0; i < position.length; i++) { if (parseInt(hash[i], 16) >= 8) { @@ -1100,10 +1083,7 @@ class TicCrypto { // hash为64hex字符,sig为128hex字符。返回用hex表达的距离。 if (this.is_signature({ sig: sig }) && this.is_hash({ hash })) { var hashSig = this.hash_easy(sig) // 把签名也转成32字节的哈希,同样长度方便比较 - return new BigInt(hash, 16) - .subtract(new BigInt(hashSig, 16)) - .abs() - .toString(16) + return new BigInt(hash, 16).subtract(new BigInt(hashSig, 16)).abs().toString(16) } return null } @@ -1322,10 +1302,7 @@ class TicCrypto { * @returns */ static b64_to_b64t (b64 = '') { - return b64 - .replace(/\+/g, '.') - .replace(/\//g, '_') - .replace(/=/g, '') + return b64.replace(/\+/g, '.').replace(/\//g, '_').replace(/=/g, '') } static b64t_to_b64 (b64t = '') { @@ -1399,9 +1376,7 @@ class TicCrypto { static hex_to_eip55 (hex) { if (/^(0x)?[\da-fA-F]+$/.test(hex)) { hex = hex.toLowerCase().replace('0x', '') - let hash = keccak('keccak256') - .update(hex) - .digest('hex') + let hash = keccak('keccak256').update(hex).digest('hex') let result = '' for (var i = 0; i < hex.length; i++) { if (parseInt(hash[i], 16) >= 8) { @@ -1457,11 +1432,7 @@ class TicCrypto { const pIdent = new BigInt('3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff0c', 16) // prime.add(1).divide(4); var signY = new Number(compressed[1]) - 2 var x = new BigInt(compressed.substr(2), 16) - var y = x - .modPow(3, prime) - .add(7) - .mod(prime) - .modPow(pIdent, prime) // y mod p = +-(x^3 + 7)^((p+1)/4) mod p + var y = x.modPow(3, prime).add(7).mod(prime).modPow(pIdent, prime) // y mod p = +-(x^3 + 7)^((p+1)/4) mod p if (y.mod(2).toJSNumber() !== signY) { // If the parity doesn't match it's the *other* root y = prime.subtract(y) // y = prime - y @@ -1527,21 +1498,15 @@ class TicCrypto { const fullHex = `01${multicodec[cidCodec]}${multialgo[cidAlgo]}${Number(cosh.length / 2).toString(16)}${cosh}` let converted = '' if (cidBase === 'b32') { - converted = this.hex_to_b32(fullHex) - .toLowerCase() - .replace(/=/g, '') + converted = this.hex_to_b32(fullHex).toLowerCase().replace(/=/g, '') } else if (cidBase === 'B32') { - converted = this.hex_to_b32(fullHex) - .toUpperCase() - .replace(/=/g, '') + converted = this.hex_to_b32(fullHex).toUpperCase().replace(/=/g, '') } else if (cidBase === 'b58') { converted = this.hex_to_b58(fullHex) } else if (cidBase === 'b64p') { converted = Buffer.from(fullHex, 'hex').toString('base64') } else if (cidBase === 'b64') { - converted = Buffer.from(fullHex, 'hex') - .toString('base64') - .replace(/=/g, '') + converted = Buffer.from(fullHex, 'hex').toString('base64').replace(/=/g, '') } return multibase[cidBase] + converted }