Skip to content

Commit

Permalink
fix: speed up secp256k1 keygen (#551)
Browse files Browse the repository at this point in the history
fixes #549
  • Loading branch information
mirceanis committed Jun 7, 2021
1 parent 9dea353 commit 75e356c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/kms-local/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"@ethersproject/abstract-provider": "^5.1.0",
"@ethersproject/abstract-signer": "^5.1.0",
"@ethersproject/bytes": "^5.1.0",
"@ethersproject/random": "^5.3.0",
"@ethersproject/signing-key": "^5.3.0",
"@ethersproject/strings": "^5.1.0",
"@ethersproject/transactions": "^5.1.1",
"@ethersproject/wallet": "^5.1.0",
Expand Down
5 changes: 4 additions & 1 deletion packages/kms-local/src/key-management-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { TransactionRequest } from '@ethersproject/abstract-provider'
import { toUtf8Bytes, toUtf8String } from '@ethersproject/strings'
import { parse } from '@ethersproject/transactions'
import { Wallet } from '@ethersproject/wallet'
import { SigningKey } from '@ethersproject/signing-key'
import { randomBytes } from "@ethersproject/random";
import Debug from 'debug'
import { arrayify } from '@ethersproject/bytes'
const debug = Debug('veramo:kms:local')
Expand All @@ -39,7 +41,8 @@ export class KeyManagementSystem extends AbstractKeyManagementSystem {
break
}
case 'Secp256k1': {
const keyPair = Wallet.createRandom()._signingKey()
const privateBytes = randomBytes(32)
const keyPair = new SigningKey(privateBytes)
const publicKeyHex = keyPair.publicKey.substring(2)
const privateKeyHex = keyPair.privateKey.substring(2)
key = {
Expand Down
41 changes: 40 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,13 @@
dependencies:
"@ethersproject/logger" "^5.1.0"

"@ethersproject/bytes@^5.3.0":
version "5.3.0"
resolved "https://registry.yarnpkg.com/@ethersproject/bytes/-/bytes-5.3.0.tgz#473e0da7f831d535b2002be05e6f4ca3729a1bc9"
integrity sha512-rqLJjdVqCcn7glPer7Fxh87PRqlnRScVAoxcIP3PmOUNApMWJ6yRdOFfo2KvPAdO7Le3yEI1o0YW+Yvr7XCYvw==
dependencies:
"@ethersproject/logger" "^5.3.0"

"@ethersproject/constants@^5.1.0":
version "5.1.0"
resolved "https://registry.yarnpkg.com/@ethersproject/constants/-/constants-5.1.0.tgz#4e7da6367ea0e9be87585d8b09f3fccf384b1452"
Expand Down Expand Up @@ -778,6 +785,11 @@
resolved "https://registry.yarnpkg.com/@ethersproject/logger/-/logger-5.1.0.tgz#4cdeeefac029373349d5818f39c31b82cc6d9bbf"
integrity sha512-wtUaD1lBX10HBXjjKV9VHCBnTdUaKQnQ2XSET1ezglqLdPdllNOIlLfhyCRqXm5xwcjExVI5ETokOYfjPtaAlw==

"@ethersproject/logger@^5.3.0":
version "5.3.0"
resolved "https://registry.yarnpkg.com/@ethersproject/logger/-/logger-5.3.0.tgz#7a69fa1d4ca0d4b7138da1627eb152f763d84dd0"
integrity sha512-8bwJ2gxJGkZZnpQSq5uSiZSJjyVTWmlGft4oH8vxHdvO1Asy4TwVepAhPgxIQIMxXZFUNMych1YjIV4oQ4I7dA==

"@ethersproject/networks@^5.1.0":
version "5.1.0"
resolved "https://registry.yarnpkg.com/@ethersproject/networks/-/networks-5.1.0.tgz#f537290cb05aa6dc5e81e910926c04cfd5814bca"
Expand All @@ -800,6 +812,13 @@
dependencies:
"@ethersproject/logger" "^5.1.0"

"@ethersproject/properties@^5.3.0":
version "5.3.0"
resolved "https://registry.yarnpkg.com/@ethersproject/properties/-/properties-5.3.0.tgz#feef4c4babeb7c10a6b3449575016f4ad2c092b2"
integrity sha512-PaHxJyM5/bfusk6vr3yP//JMnm4UEojpzuWGTmtL5X4uNhNnFNvlYilZLyDr4I9cTkIbipCMsAuIcXWsmdRnEw==
dependencies:
"@ethersproject/logger" "^5.3.0"

"@ethersproject/providers@^5.1.0":
version "5.1.0"
resolved "https://registry.yarnpkg.com/@ethersproject/providers/-/providers-5.1.0.tgz#27695a02cfafa370428cde1c7a4abab13afb6a35"
Expand Down Expand Up @@ -858,6 +877,14 @@
"@ethersproject/bytes" "^5.1.0"
"@ethersproject/logger" "^5.1.0"

"@ethersproject/random@^5.3.0":
version "5.3.0"
resolved "https://registry.yarnpkg.com/@ethersproject/random/-/random-5.3.0.tgz#7c46bf36e50cb0d0550bc8c666af8e1d4496dc1a"
integrity sha512-A5SL/4inutSwt3Fh2OD0x2gz+x6GHmuUnIPkR7zAiTidMD2N8F6tZdMF1hlQKWVCcVMWhEQg8mWijhEzm6BBYw==
dependencies:
"@ethersproject/bytes" "^5.3.0"
"@ethersproject/logger" "^5.3.0"

"@ethersproject/rlp@^5.1.0":
version "5.1.0"
resolved "https://registry.yarnpkg.com/@ethersproject/rlp/-/rlp-5.1.0.tgz#700f4f071c27fa298d3c1d637485fefe919dd084"
Expand Down Expand Up @@ -886,6 +913,18 @@
bn.js "^4.4.0"
elliptic "6.5.4"

"@ethersproject/signing-key@^5.3.0":
version "5.3.0"
resolved "https://registry.yarnpkg.com/@ethersproject/signing-key/-/signing-key-5.3.0.tgz#a96c88f8173e1abedfa35de32d3e5db7c48e5259"
integrity sha512-+DX/GwHAd0ok1bgedV1cKO0zfK7P/9aEyNoaYiRsGHpCecN7mhLqcdoUiUzE7Uz86LBsxm5ssK0qA1kBB47fbQ==
dependencies:
"@ethersproject/bytes" "^5.3.0"
"@ethersproject/logger" "^5.3.0"
"@ethersproject/properties" "^5.3.0"
bn.js "^4.11.9"
elliptic "6.5.4"
hash.js "1.1.7"

"@ethersproject/strings@^5.1.0":
version "5.1.0"
resolved "https://registry.yarnpkg.com/@ethersproject/strings/-/strings-5.1.0.tgz#0f95a56c3c8c9d5510a06c241d818779750e2da5"
Expand Down Expand Up @@ -6216,7 +6255,7 @@ hash.js@1.1.3:
inherits "^2.0.3"
minimalistic-assert "^1.0.0"

hash.js@^1.0.0, hash.js@^1.0.3:
hash.js@1.1.7, hash.js@^1.0.0, hash.js@^1.0.3:
version "1.1.7"
resolved "https://registry.yarnpkg.com/hash.js/-/hash.js-1.1.7.tgz#0babca538e8d4ee4a0f8988d68866537a003cf42"
integrity sha512-taOaskGt4z4SOANNseOviYDvjEJinIkRgmp7LbKP2YTTmVxWBl87s/uzK9r+44BclBSp2X7K1hqeNfz9JbBeXA==
Expand Down

0 comments on commit 75e356c

Please sign in to comment.