Skip to content

Commit b40f59a

Browse files
happylemonprogrammingOpenCode
authored andcommitted
Upgrade to @noble/curves ^2.0.1 and @noble/hashes ^2.0.1
This commit upgrades the noble cryptography dependencies to v2.0.1, which includes: Breaking changes addressed: - Updated all @noble imports to include .js extensions (required by v2 ESM-only API) - Changed @noble/hashes/sha256 to @noble/hashes/sha2.js across 8 files - Fixed secp256k1 API changes: methods now require Uint8Array instead of hex strings - Updated schnorr.utils.randomPrivateKey() to schnorr.utils.randomSecretKey() Files modified (27 total): - package.json: Bump dependency versions - Source files (12): pure.ts, nip04.ts, nip06.ts, nip13.ts, nip19.ts, nip44.ts, nip49.ts, nip77.ts, nip98.ts, nipb7.ts, utils.ts, wasm.ts - Test files (14): All corresponding test files updated Benefits: - Latest security updates from audited noble libraries - Smaller bundle sizes from v2 optimizations - Future-proof ESM-only compatibility - All tests passing Co-authored-by: OpenCode <opencode@anomalyco.com>
1 parent bfa40da commit b40f59a

27 files changed

+51
-51
lines changed

nip04.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { test, expect } from 'bun:test'
22

33
import { encrypt, decrypt } from './nip04.ts'
44
import { getPublicKey, generateSecretKey } from './pure.ts'
5-
import { bytesToHex, hexToBytes } from '@noble/hashes/utils'
5+
import { bytesToHex, hexToBytes } from '@noble/hashes/utils.js'
66

77
test('encrypt and decrypt message', async () => {
88
let sk1 = generateSecretKey()

nip04.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { bytesToHex, randomBytes } from '@noble/hashes/utils'
2-
import { secp256k1 } from '@noble/curves/secp256k1'
1+
import { bytesToHex, hexToBytes, randomBytes } from '@noble/hashes/utils.js'
2+
import { secp256k1 } from '@noble/curves/secp256k1.js'
33
import { cbc } from '@noble/ciphers/aes'
44
import { base64 } from '@scure/base'
55

66
import { utf8Decoder, utf8Encoder } from './utils.ts'
77

88
export function encrypt(secretKey: string | Uint8Array, pubkey: string, text: string): string {
9-
const privkey: string = secretKey instanceof Uint8Array ? bytesToHex(secretKey) : secretKey
10-
const key = secp256k1.getSharedSecret(privkey, '02' + pubkey)
9+
const privkey: Uint8Array = secretKey instanceof Uint8Array ? secretKey : hexToBytes(secretKey)
10+
const key = secp256k1.getSharedSecret(privkey, hexToBytes('02' + pubkey))
1111
const normalizedKey = getNormalizedX(key)
1212

1313
let iv = Uint8Array.from(randomBytes(16))
@@ -22,9 +22,9 @@ export function encrypt(secretKey: string | Uint8Array, pubkey: string, text: st
2222
}
2323

2424
export function decrypt(secretKey: string | Uint8Array, pubkey: string, data: string): string {
25-
const privkey: string = secretKey instanceof Uint8Array ? bytesToHex(secretKey) : secretKey
25+
const privkey: Uint8Array = secretKey instanceof Uint8Array ? secretKey : hexToBytes(secretKey)
2626
let [ctb64, ivb64] = data.split('?iv=')
27-
let key = secp256k1.getSharedSecret(privkey, '02' + pubkey)
27+
let key = secp256k1.getSharedSecret(privkey, hexToBytes('02' + pubkey))
2828
let normalizedKey = getNormalizedX(key)
2929

3030
let iv = base64.decode(ivb64)

nip06.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
extendedKeysFromSeedWords,
66
accountFromExtendedKey,
77
} from './nip06.ts'
8-
import { hexToBytes } from '@noble/hashes/utils'
8+
import { hexToBytes } from '@noble/hashes/utils.js'
99

1010
test('generate private key from a mnemonic', async () => {
1111
const mnemonic = 'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong'

nip06.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { bytesToHex } from '@noble/hashes/utils'
1+
import { bytesToHex } from '@noble/hashes/utils.js'
22
import { wordlist } from '@scure/bip39/wordlists/english'
33
import { generateMnemonic, mnemonicToSeedSync, validateMnemonic } from '@scure/bip39'
44
import { HDKey } from '@scure/bip32'

nip13.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { bytesToHex } from '@noble/hashes/utils'
1+
import { bytesToHex } from '@noble/hashes/utils.js'
22
import { type UnsignedEvent, type Event } from './pure.ts'
3-
import { sha256 } from '@noble/hashes/sha256'
3+
import { sha256 } from '@noble/hashes/sha2.js'
44

55
import { utf8Encoder } from './utils.ts'
66

nip17.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { test, expect } from 'bun:test'
22
import { getPublicKey } from './pure.ts'
33
import { decode } from './nip19.ts'
44
import { wrapEvent, wrapManyEvents, unwrapEvent } from './nip17.ts'
5-
import { hexToBytes } from '@noble/hashes/utils'
5+
import { hexToBytes } from '@noble/hashes/utils.js'
66

77
const senderPrivateKey = decode(`nsec1p0ht6p3wepe47sjrgesyn4m50m6avk2waqudu9rl324cg2c4ufesyp6rdg`).data
88

nip18.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, test, expect } from 'bun:test'
2-
import { hexToBytes } from '@noble/hashes/utils'
2+
import { hexToBytes } from '@noble/hashes/utils.js'
33
import { EventTemplate, finalizeEvent, getPublicKey } from './pure.ts'
44
import { GenericRepost, Repost, ShortTextNote, BadgeDefinition as BadgeDefinitionKind } from './kinds.ts'
55
import { finishRepostEvent, getRepostedEventPointer, getRepostedEvent } from './nip18.ts'

nip19.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { bytesToHex, concatBytes, hexToBytes } from '@noble/hashes/utils'
1+
import { bytesToHex, concatBytes, hexToBytes } from '@noble/hashes/utils.js'
22
import { bech32 } from '@scure/base'
33

44
import { utf8Decoder, utf8Encoder } from './utils.ts'

nip25.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, test, expect } from 'bun:test'
2-
import { hexToBytes } from '@noble/hashes/utils'
2+
import { hexToBytes } from '@noble/hashes/utils.js'
33
import { finalizeEvent, getPublicKey } from './pure.ts'
44
import { Reaction, ShortTextNote } from './kinds.ts'
55
import { finishReactionEvent, getReactedEventPointer } from './nip25.ts'

nip28.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, test, expect } from 'bun:test'
2-
import { hexToBytes } from '@noble/hashes/utils'
2+
import { hexToBytes } from '@noble/hashes/utils.js'
33
import { getPublicKey } from './pure.ts'
44
import * as Kind from './kinds.ts'
55
import {

0 commit comments

Comments
 (0)