Skip to content

Commit

Permalink
feat: export setSignEntropy
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Nov 21, 2024
1 parent ce1b8af commit a22c5b1
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .changeset/ninety-suits-invite.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
"viem": minor
"viem": patch
---

Improved security of signature generation. Resolves #3028.
Added `setSignEntropy` export to improve security of signature generation.
1 change: 1 addition & 0 deletions src/accounts/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ test('exports utils', () => {
"mnemonicToAccount",
"privateKeyToAccount",
"toAccount",
"setSignEntropy",
"sign",
"signatureToHex",
"serializeSignature",
Expand Down
1 change: 1 addition & 0 deletions src/accounts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export {
type SignErrorType,
type SignParameters,
type SignReturnType,
setSignEntropy,
sign,
} from './utils/sign.js'
export {
Expand Down
9 changes: 6 additions & 3 deletions src/accounts/utils/sign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ export type SignReturnType<to extends To = 'object'> =

export type SignErrorType = NumberToHexErrorType | ErrorType

let extraEntropy: Hex | boolean = true
let extraEntropy: Hex | boolean = false

/** @internal */
export function setSignEntropy(entropy: Hex | boolean) {
/**
* Sets extra entropy for signing functions.
*/
export function setSignEntropy(entropy: true | Hex) {
if (!entropy) throw new Error('must be a `true` or a hex value.')
extraEntropy = entropy
}

Expand Down
3 changes: 0 additions & 3 deletions test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ import { cleanupCache, listenersCache } from '~viem/utils/observe.js'
import { promiseCache, responseCache } from '~viem/utils/promise/withCache.js'
import { socketClientCache } from '~viem/utils/rpc/socket.js'

import { setSignEntropy } from '../src/accounts/utils/sign.js'
import { setErrorConfig } from '../src/errors/base.js'
import * as instances from './src/anvil.js'

const client = instances.anvilMainnet.getClient()

setSignEntropy(false)

beforeAll(() => {
setErrorConfig({
getDocsUrl({ docsBaseUrl, docsPath }) {
Expand Down
3 changes: 0 additions & 3 deletions vectors/src/transaction.vectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import { signTransaction } from '../../src/accounts/utils/signTransaction.js'
import { parseTransaction } from '../../src/index.js'
import { serializeTransaction } from '../../src/utils/transaction/serializeTransaction.js'
import { readGzippedJson } from '../utils.js'
import { setSignEntropy } from '../../src/accounts/utils/sign.js'

setSignEntropy(false)

const transactions_ = await readGzippedJson(
join(import.meta.dir, './transaction.json.gz'),
Expand Down

0 comments on commit a22c5b1

Please sign in to comment.