1

我想把这个用js写的函数写到dart

js中的函数


import {ec as EC} from 'elliptic'
import secp256k1 from 'secp256k1'
import sha3 from 'js-sha3'

const ec = new EC('secp256k1')

export function privateKeyToAddress(key) {
  const pubKey = ec
    .keyFromPrivate(key)
    .getPublic()
    .encode('array')

  return toHexString(sha3.keccak_256.array(pubKey.slice(1)).slice(12), true)
}

我尝试在 pub spec.yaml 中使用插件:

  secp256k1: ^0.2.2
  sha3: ^0.1.2
  quartet: ^0.1.1

我用飞镖编码:

String privateKey = "...."; // add a private key value
var pk = PrivateKey.fromHex(privateKey);
var pub = pk.publicKey;
var k = SHA3(256, KECCAK_PADDING, 256);
k.update(utf8.encode(slice(pub.toCompressedHex(), 1)));
var address = slice(HEX.encode(k.digest()), 12);
    

js函数和dart函数之间的结果(eq.地址值)在相同的私钥值下是不一样的......

请问你能帮帮我吗

4

0 回答 0