From 3ce0f1560eb5f92121b9c53a8c74482810eae7ee Mon Sep 17 00:00:00 2001 From: minibits-cash Date: Thu, 29 Jan 2026 10:10:36 +0100 Subject: [PATCH] Add quickCrypto patch for nested @scure/bip32 in cashu-ts Patch cashu-ts's nested @scure/bip32@2.0.1 dependency to use react-native-quick-crypto for HMAC-SHA512 operations in BIP32 key derivation. This improves wallet recovery performance. - Add patches/@cashu+cashu-ts++@scure+bip32+2.0.1.patch - Enable scripts in .yarnrc.yml for patch-package Co-Authored-By: Claude Opus 4.5 --- .yarnrc.yml | 2 ++ .../@cashu+cashu-ts++@scure+bip32+2.0.1.patch | 34 +++++++++++++++++++ yarn.lock | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 patches/@cashu+cashu-ts++@scure+bip32+2.0.1.patch diff --git a/.yarnrc.yml b/.yarnrc.yml index 2cfa2b0..82441b6 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -3,3 +3,5 @@ nodeLinker: node-modules yarnPath: .yarn/releases/yarn-3.6.4.cjs checksumBehavior: update + +enableScripts: true diff --git a/patches/@cashu+cashu-ts++@scure+bip32+2.0.1.patch b/patches/@cashu+cashu-ts++@scure+bip32+2.0.1.patch new file mode 100644 index 0000000..68c0832 --- /dev/null +++ b/patches/@cashu+cashu-ts++@scure+bip32+2.0.1.patch @@ -0,0 +1,34 @@ +diff --git a/node_modules/@cashu/cashu-ts/node_modules/@scure/bip32/index.js b/node_modules/@cashu/cashu-ts/node_modules/@scure/bip32/index.js +index 935277b..6a76a8c 100644 +--- a/node_modules/@cashu/cashu-ts/node_modules/@scure/bip32/index.js ++++ b/node_modules/@cashu/cashu-ts/node_modules/@scure/bip32/index.js +@@ -23,6 +23,7 @@ import { ripemd160 } from '@noble/hashes/legacy.js'; + import { sha256, sha512 } from '@noble/hashes/sha2.js'; + import { abytes, concatBytes, createView } from '@noble/hashes/utils.js'; + import { createBase58check } from '@scure/base'; ++import quickCrypto from 'react-native-quick-crypto'; + const Point = secp.Point; + const { Fn } = Point; + const base58check = createBase58check(sha256); +@@ -87,7 +88,9 @@ export class HDKey { + throw new Error('HDKey: seed length must be between 128 and 512 bits; 256 bits is advised, got ' + + seed.length); + } +- const I = hmac(sha512, MASTER_SECRET, seed); ++ // const I = hmac(sha512, MASTER_SECRET, seed); ++ console.log('[bip32 v2.0.1 fromMasterSeed] Using quickCrypto HMAC'); ++ const I = new Uint8Array(quickCrypto.createHmac('sha512', MASTER_SECRET).update(seed).digest()); + const privateKey = I.slice(0, 32); + const chainCode = I.slice(32); + return new HDKey({ versions, chainCode, privateKey }); +@@ -206,7 +209,9 @@ export class HDKey { + // Normal child: serP(point(kpar)) || ser32(index) + data = concatBytes(this._publicKey, data); + } +- const I = hmac(sha512, this.chainCode, data); ++ // const I = hmac(sha512, this.chainCode, data); ++ console.log('[bip32 v2.0.1 deriveChild] Using quickCrypto HMAC'); ++ const I = new Uint8Array(quickCrypto.createHmac('sha512', this.chainCode).update(data).digest()); + const childTweak = I.slice(0, 32); + const chainCode = I.slice(32); + if (!secp.utils.isValidSecretKey(childTweak)) { diff --git a/yarn.lock b/yarn.lock index b2e7bcf..7210278 100644 --- a/yarn.lock +++ b/yarn.lock @@ -16545,7 +16545,7 @@ __metadata: peerDependenciesMeta: "@expo/config-plugins": optional: true - checksum: 4f38adfbd60124f96121a31eaadecd48cb72d50afcfff228be7bfba92ec1051154a2b8acd2cf8c8d0e0c6d12172f48237791d0ecb3a726f8915151ab652b79a5 + checksum: efd9e1eeee2b75a83d366687a9acf58b4f0a4f4a32b563783cacf1b9308bdccb81afdb065d7df469e5308e3163d5f6b5e2561ea5c8ea5e9abc1ded623b19d697 languageName: node linkType: hard