Compare commits
No commits in common. "71eb5d5dceb522d4568141aad3bc99e24f470d02" and "e7f538b472c7e9ea4b539a7fca2ef3faf52d67d3" have entirely different histories.
71eb5d5dce
...
e7f538b472
29
ticc.js
29
ticc.js
@ -439,12 +439,8 @@ class TicCrypto {
|
|||||||
// 据测试, Purpose和CoinType都可以任意其他值,不必要如规范所示;' 引号可有可无,导致的密钥不一样;
|
// 据测试, Purpose和CoinType都可以任意其他值,不必要如规范所示;' 引号可有可无,导致的密钥不一样;
|
||||||
// Account 最大为 0x7FFFFFFF, Change/Index 最大均为 0xFFFFFFFF(=4294967295)
|
// Account 最大为 0x7FFFFFFF, Change/Index 最大均为 0xFFFFFFFF(=4294967295)
|
||||||
// 但可以不断延伸下去:/xxx/xxx/xxx/xxx/...
|
// 但可以不断延伸下去:/xxx/xxx/xxx/xxx/...
|
||||||
coin = coin?.toUpperCase?.() || my.COIN
|
coin = coin?.toUpperCase() || my.COIN
|
||||||
|
|
||||||
if (!this.is_secword(secword)) {
|
|
||||||
// 由于 secword_to_seed 可以对一切字符串都正常返回,为防止secword为空,在这里先做检查。
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
if (tool === 'nacl') {
|
if (tool === 'nacl') {
|
||||||
// 采用自己的算法:bip39算法从secword到种子,hash后用 nacl.sign.keyPair.fromSeed()方法。
|
// 采用自己的算法:bip39算法从secword到种子,hash后用 nacl.sign.keyPair.fromSeed()方法。
|
||||||
let hashBuf = crypto
|
let hashBuf = crypto
|
||||||
@ -480,6 +476,7 @@ class TicCrypto {
|
|||||||
pubkey: key.publicKey.toString('hex'),
|
pubkey: key.publicKey.toString('hex'),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -550,18 +547,18 @@ class TicCrypto {
|
|||||||
* @return {Object}
|
* @return {Object}
|
||||||
* @memberof TicCrypto
|
* @memberof TicCrypto
|
||||||
*/
|
*/
|
||||||
static secword_to_account ({ secword, coin = my.COIN, world, pass, pathRoot, pathIndex, path, tool, hasher } = {}) {
|
static secword_to_account ({ secword, coin = my.COIN, pass, pathRoot, pathIndex, path, tool, hasher } = {}) {
|
||||||
// account 比 keypair 多了 address 字段。
|
// account 比 keypair 多了 address 字段。
|
||||||
coin = coin?.toUpperCase?.() || my.COIN
|
coin = coin?.toUpperCase()
|
||||||
let kp = this.secword_to_keypair({ secword, coin, pass, pathRoot, pathIndex, path, tool, hasher })
|
let kp = this.secword_to_keypair({ secword, coin, pass, pathRoot, pathIndex, path, tool, hasher })
|
||||||
if (kp) {
|
if (kp) {
|
||||||
if (coin === 'ETH') {
|
if (coin === 'ETH') {
|
||||||
let uncompressedPubkey = this.decompress_pubkey(kp.pubkey)
|
let uncompressedPubkey = this.decompress_pubkey(kp.pubkey)
|
||||||
kp.address = this.pubkey_to_address({ pubkey: uncompressedPubkey, coin: 'ETH', world })
|
kp.address = this.pubkey_to_address({ pubkey: uncompressedPubkey, coin: 'ETH' })
|
||||||
} else {
|
} else {
|
||||||
kp.address = this.pubkey_to_address({ pubkey: kp.pubkey, coin, world })
|
kp.address = this.pubkey_to_address({ pubkey: kp.pubkey, coin })
|
||||||
}
|
}
|
||||||
return Object.assign(kp, { coin, world, secword })
|
return Object.assign(kp, { coin, secword })
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@ -575,8 +572,8 @@ class TicCrypto {
|
|||||||
* @return {String} address
|
* @return {String} address
|
||||||
* @memberof TicCrypto
|
* @memberof TicCrypto
|
||||||
*/
|
*/
|
||||||
static secword_to_address ({ secword, coin = my.COIN, world, pass, pathRoot, pathIndex, path, tool, hasher } = {}) {
|
static secword_to_address ({ secword, coin, world, pass, pathRoot, pathIndex, path, tool, hasher } = {}) {
|
||||||
coin = coin?.toUpperCase?.() || my.COIN
|
coin = coin?.toUpperCase() || my.COIN
|
||||||
let kp = this.secword_to_keypair({ secword, coin, pass, pathRoot, pathIndex, path, tool, hasher })
|
let kp = this.secword_to_keypair({ secword, coin, pass, pathRoot, pathIndex, path, tool, hasher })
|
||||||
if (kp) {
|
if (kp) {
|
||||||
let address
|
let address
|
||||||
@ -806,7 +803,7 @@ class TicCrypto {
|
|||||||
* @return {Boolean}
|
* @return {Boolean}
|
||||||
* @memberof TicCrypto
|
* @memberof TicCrypto
|
||||||
*/
|
*/
|
||||||
static which_chain_address ({ address }) {
|
static is_chain_address ({ address }) {
|
||||||
if (/^(0x)?[\da-fA-F]{40}$/.test(address)) {
|
if (/^(0x)?[\da-fA-F]{40}$/.test(address)) {
|
||||||
return 'ETH'
|
return 'ETH'
|
||||||
} else if (/^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{26,34}$/.test(address) && address.length !== 32) {
|
} else if (/^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{26,34}$/.test(address) && address.length !== 32) {
|
||||||
@ -850,7 +847,7 @@ class TicCrypto {
|
|||||||
* @return {*}
|
* @return {*}
|
||||||
* @memberof TicCrypto
|
* @memberof TicCrypto
|
||||||
*/
|
*/
|
||||||
static secword_to_seed ({ secword, pass } = {}) {
|
static secword_to_seed ({ secword, pass }) {
|
||||||
// 遵循bip39的算法。和 ether.HDNode.mnemonic2Seed 结果一样,是64字节的种子。
|
// 遵循bip39的算法。和 ether.HDNode.mnemonic2Seed 结果一样,是64字节的种子。
|
||||||
// !!! 警告,bip39.mnemonicToSeedSync 也接受不合法的 secword,只要是个string,或者是 undefined/null/0/''/false(这几个的结果都一样)
|
// !!! 警告,bip39.mnemonicToSeedSync 也接受不合法的 secword,只要是个string,或者是 undefined/null/0/''/false(这几个的结果都一样)
|
||||||
return bip39.mnemonicToSeedSync(secword, pass).toString('hex') // 结果一致与 new BitcoreMnemonic(secword).toSeed(pass).toString('hex') 或 ethers.HDNode.mnemonic2Seed(secword)。
|
return bip39.mnemonicToSeedSync(secword, pass).toString('hex') // 结果一致与 new BitcoreMnemonic(secword).toSeed(pass).toString('hex') 或 ethers.HDNode.mnemonic2Seed(secword)。
|
||||||
@ -936,9 +933,9 @@ class TicCrypto {
|
|||||||
* @return {*}
|
* @return {*}
|
||||||
* @memberof TicCrypto
|
* @memberof TicCrypto
|
||||||
*/
|
*/
|
||||||
static randomize_account ({ lang, wordCount, coin, world, pass, pathRoot, pathIndex, path, tool, hasher } = {}) {
|
static randomize_account ({ lang, wordCount, coin, pass, pathRoot, pathIndex, path, tool, hasher } = {}) {
|
||||||
let secword = this.randomize_secword({ lang, wordCount })
|
let secword = this.randomize_secword({ lang, wordCount })
|
||||||
return this.secword_to_account({ secword, coin, world, pass, pathRoot, pathIndex, path, tool, hasher })
|
return this.secword_to_account({ secword, coin, pass, pathRoot, pathIndex, path, tool, hasher })
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user