Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
replace @starcoin/stc-ed25519 with @noble/ed25519, because the latest…
… @noble/ed25519 supports BigInt already
  • Loading branch information
wk3368 committed Mar 25, 2022
1 parent 8782e3c commit e96ede7
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -41,7 +41,7 @@
"@ethersproject/properties": "^5.0.4",
"@ethersproject/sha2": "^5.0.4",
"@ethersproject/web": "^5.0.9",
"@starcoin/stc-ed25519": "^0.1.0",
"@noble/ed25519": "^1.6.0",
"bech32": "^2.0.0",
"ethereumjs-util": "5.1.0",
"fs": "^0.0.1-security",
Expand Down Expand Up @@ -104,4 +104,4 @@
"prettier": {
"singleQuote": true
}
}
}
4 changes: 2 additions & 2 deletions src/encoding/index.ts
@@ -1,6 +1,6 @@
import { arrayify, BytesLike, hexlify } from '@ethersproject/bytes';
import { addHexPrefix, stripHexPrefix } from 'ethereumjs-util';
import * as ed from '@starcoin/stc-ed25519';
import * as ed from '@noble/ed25519';
import { sha3_256 } from 'js-sha3';
import { createUserTransactionHasher } from "../crypto_hash";
import { BcsDeserializer, BcsSerializer } from '../lib/runtime/bcs';
Expand Down Expand Up @@ -268,7 +268,7 @@ export function typeTagFromSCS(bcs_data: starcoin_types.TypeTag): TypeTag {

export async function privateKeyToPublicKey(privateKey: string): Promise<string> {
const publicKey = await ed.getPublicKey(stripHexPrefix(privateKey))
return addHexPrefix(publicKey)
return hexlify(publicKey)
}

// singleMulti: 0-single, 1-multi
Expand Down
2 changes: 1 addition & 1 deletion src/utils/account.ts
@@ -1,5 +1,5 @@

import { utils } from '@starcoin/stc-ed25519';
import { utils } from '@noble/ed25519';
import { addHexPrefix, stripHexPrefix } from 'ethereumjs-util';
import { hexlify, arrayify } from '@ethersproject/bytes';
import { privateKeyToPublicKey, publicKeyToAuthKey, publicKeyToAddress, encodeReceiptIdentifier, bcsEncode } from "../encoding";
Expand Down
2 changes: 1 addition & 1 deletion src/utils/multi-sign.spec.ts
Expand Up @@ -5,7 +5,7 @@ import { readFileSync, writeFileSync } from 'fs';
import { hexlify, arrayify } from '@ethersproject/bytes';
import { addHexPrefix } from 'ethereumjs-util';
import { BigNumber } from '@ethersproject/bignumber';
import { utils as ed25519Utils } from '@starcoin/stc-ed25519';
import { utils as ed25519Utils } from '@noble/ed25519';
import { JsonRpcProvider } from '../providers';
import { bcsEncode, bcsDecode } from '../encoding';
import { BcsSerializer, BcsDeserializer } from '../lib/runtime/bcs';
Expand Down
5 changes: 3 additions & 2 deletions src/utils/signed-message.ts
@@ -1,4 +1,4 @@
import * as ed from '@starcoin/stc-ed25519';
import * as ed from '@noble/ed25519';
import { addHexPrefix, stripHexPrefix } from 'ethereumjs-util';
import { arrayify, hexlify, BytesLike } from '@ethersproject/bytes';
import { BcsSerializer, BcsDeserializer } from '../lib/runtime/bcs';
Expand Down Expand Up @@ -45,7 +45,8 @@ export async function signMessage(msg: string, privateKeyHex: string): Promise<R
const msgBytes = new Uint8Array(Buffer.from(msg, 'utf8'))
const signingMessage = new SigningMessage(msgBytes);
const signingMessageBytes = getEd25519SignMsgBytes(signingMessage)
const publicKeyHex = await <string><unknown>ed.getPublicKey(stripHexPrefix(privateKeyHex));
const publicKeyBytes = await ed.getPublicKey(stripHexPrefix(privateKeyHex));
const publicKeyHex = hexlify(publicKeyBytes)
const signatureBytes = await ed.sign(signingMessageBytes, stripHexPrefix(privateKeyHex))
const signatureHex = hexlify(signatureBytes)
return Promise.resolve({ publicKey: publicKeyHex, signature: signatureHex })
Expand Down
2 changes: 1 addition & 1 deletion src/utils/tx.ts
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import * as ed from '@starcoin/stc-ed25519';
import * as ed from '@noble/ed25519';
import { stripHexPrefix, addHexPrefix } from 'ethereumjs-util';
import { arrayify, hexlify, isHexString } from '@ethersproject/bytes';
import { bytes, Seq, uint8 } from '../lib/runtime/serde';
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Expand Up @@ -1372,6 +1372,11 @@
"@types/yargs" "^15.0.0"
chalk "^4.0.0"

"@noble/ed25519@^1.6.0":
version "1.6.0"
resolved "https://registry.yarnpkg.com/@noble/ed25519/-/ed25519-1.6.0.tgz#b55f7c9e532b478bf1d7c4f609e1f3a37850b583"
integrity sha512-UKju89WV37IUALIMfKhKW3psO8AqmrE/GvH6QbPKjzolQ98zM7WmGUeY+xdIgSf5tqPFf75ZCYMgym6E9Jsw3Q==

"@nodelib/fs.scandir@2.1.4":
version "2.1.4"
resolved "https://registry.npm.taobao.org/@nodelib/fs.scandir/download/@nodelib/fs.scandir-2.1.4.tgz"
Expand Down Expand Up @@ -1462,11 +1467,6 @@
dependencies:
"@sinonjs/commons" "^1.7.0"

"@starcoin/stc-ed25519@^0.1.0":
version "0.1.0"
resolved "https://registry.npmjs.org/@starcoin/stc-ed25519/-/stc-ed25519-0.1.0.tgz#56e65b388889a5953e01806cc3deaa20ddaf8174"
integrity sha512-H3oz8fNQD604Ak0cSNTDcbfzLxsB9XAKw1aJO7iBPuZWcHF8bgn7xxOzsinx5V5LGaPeleWc/Qw4vCKnK6cxHQ==

"@types/babel__core@^7.0.0", "@types/babel__core@^7.1.7":
version "7.1.14"
resolved "https://registry.npm.taobao.org/@types/babel__core/download/@types/babel__core-7.1.14.tgz?cache=0&sync_timestamp=1616202213220&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40types%2Fbabel__core%2Fdownload%2F%40types%2Fbabel__core-7.1.14.tgz"
Expand Down

0 comments on commit e96ede7

Please sign in to comment.