diff --git a/mpc-core-kit-web/mpc-core-kit-bitcoin/package-lock.json b/mpc-core-kit-web/mpc-core-kit-bitcoin/package-lock.json index 4cfc1e98..11757a7e 100644 --- a/mpc-core-kit-web/mpc-core-kit-bitcoin/package-lock.json +++ b/mpc-core-kit-web/mpc-core-kit-bitcoin/package-lock.json @@ -20,7 +20,7 @@ "@vitejs/plugin-react": "^4.3.1", "@web3auth/base": "^9.4.5", "@web3auth/ethereum-mpc-provider": "^9.4.5", - "@web3auth/mpc-core-kit": "^4.1.0-alpha.0", + "@web3auth/mpc-core-kit": "file:web3auth-mpc-core-kit-4.0.0-alpha.1.tgz", "axios": "^1.7.7", "bitcoinjs-lib": "^6.1.5", "bn.js": "^5.2.1", @@ -4096,19 +4096,34 @@ "integrity": "sha512-htUWzL2JZoKTtw++WLdQ1AK3wPTe0yezv/twWjpQIzLFkkfoO9Urnl5n9S6jFx98Z1dDRJRBWSED9PSuqY/x7w==" }, "node_modules/@toruslabs/tss-frost-client": { - "version": "1.0.0-alpha.0", - "resolved": "https://registry.npmjs.org/@toruslabs/tss-frost-client/-/tss-frost-client-1.0.0-alpha.0.tgz", - "integrity": "sha512-MvWl8Qt+/DIrNP+vqozYssXlWD1Ofo8jgRmUkiODuOew/wpePhIQv41XTcir7vdv2UU2SsG8N4L0FLU9O69Guw==", + "version": "1.0.0-alpha.1", + "resolved": "file:toruslabs-tss-frost-client-1.0.0-alpha.1.tgz", + "integrity": "sha512-0ySOgZ3Y4ZwC+FgFtOvWj/6zopQokouFaHc23cIWrMyKW583567NWDPzi+MosvbneWajWZKk8DKB8SrFR//9Uw==", + "license": "ISC", "dependencies": { + "@toruslabs/elliptic-wrapper": "^0.1.2-alpha.0", "@toruslabs/tss-client-util": "^0.1.1", - "@toruslabs/tss-frost-common": "^1.0.1", + "@toruslabs/tss-frost-common": "^1.1.0-alpha.0", "socket.io-client": "^4.7.2" } }, + "node_modules/@toruslabs/tss-frost-client/node_modules/@toruslabs/elliptic-wrapper": { + "version": "0.1.2-alpha.0", + "resolved": "https://registry.npmjs.org/@toruslabs/elliptic-wrapper/-/elliptic-wrapper-0.1.2-alpha.0.tgz", + "integrity": "sha512-GO5gAb6uGslKVmxsW7d/EwEKisJJjobbbqbvmtT/C0ZxJb9Xb3Xa5WtRTuy2gUDioXIRR970vl08TM71uGETkQ==", + "license": "ISC", + "dependencies": { + "@toruslabs/config": "^2.0.2", + "@toruslabs/eslint-config-typescript": "^3.0.3", + "bn.js": "^5.2.1", + "elliptic": "^6.5.4" + } + }, "node_modules/@toruslabs/tss-frost-common": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@toruslabs/tss-frost-common/-/tss-frost-common-1.0.1.tgz", - "integrity": "sha512-WmunNSH9XOM/oHQ/CjsTCn4KN9eqxo4keTRV6Yf6roq/S5hzKjOoowWM86vpwPJ6mfa2Qho9bndE2CCS11nKwg==" + "version": "1.1.0-alpha.0", + "resolved": "file:toruslabs-tss-frost-common-1.1.0-alpha.0.tgz", + "integrity": "sha512-VOF1lQ7LTQ3RIKOxxp4uCZve7SNoP4Brg6hp+p5XzZBTZ6s28PVL/5GqQa/MYKQ5b88oqYNfjiOEhIhsGeW/uA==", + "license": "ISC" }, "node_modules/@toruslabs/tss-frost-lib-bip340": { "version": "0.1.0-alpha.0", @@ -4730,9 +4745,10 @@ } }, "node_modules/@web3auth/mpc-core-kit": { - "version": "4.1.0-alpha.0", - "resolved": "https://registry.npmjs.org/@web3auth/mpc-core-kit/-/mpc-core-kit-4.1.0-alpha.0.tgz", - "integrity": "sha512-xVCJFJdtazsyLE7aj6IAaTtLTg29+ybazeq2KBXM6iIX+2owNN9L2kG9gd7IY34UTE9151UQ9VfMOX4FVaz0PA==", + "version": "4.0.0-alpha.1", + "resolved": "file:web3auth-mpc-core-kit-4.0.0-alpha.1.tgz", + "integrity": "sha512-tiJPjgTqm0IS4L3fIg2BxbfnzfLfAn+0MpvW5ckDwaS6fzgKAXJTloc5UPCZE5HAlqqB1gXWg49p/f7M6Z5tvA==", + "license": "ISC", "dependencies": { "@tkey/common-types": "^15.1.0", "@tkey/core": "^15.1.0", @@ -4747,10 +4763,10 @@ "@toruslabs/metadata-helpers": "^6.0.0", "@toruslabs/openlogin-utils": "^8.2.1", "@toruslabs/session-manager": "^3.1.0", - "@toruslabs/torus.js": "15.2.0-alpha.0", + "@toruslabs/torus.js": "^15.1.1", "@toruslabs/tss-client": "^3.3.0-alpha.0", - "@toruslabs/tss-frost-client": "^1.0.0-alpha.0", - "@toruslabs/tss-frost-common": "^1.0.1", + "@toruslabs/tss-frost-client": "file:toruslabs-tss-frost-client-1.0.0-alpha.1.tgz", + "@toruslabs/tss-frost-common": "file:toruslabs-tss-frost-common-1.1.0-alpha.0.tgz", "bn.js": "^5.2.1", "bowser": "^2.11.0", "elliptic": "^6.5.7", @@ -4781,29 +4797,7 @@ "version": "14.2.0", "resolved": "https://registry.npmjs.org/@toruslabs/constants/-/constants-14.2.0.tgz", "integrity": "sha512-Mb5EfYNSPyvvw5s1JXnpZwritCgp4NmLni1imTqrSKGV3yikYhUn1ufyLMAHGnBBgv4AuMIXBIe3EpJJ+SpA0g==", - "engines": { - "node": ">=18.x", - "npm": ">=9.x" - }, - "peerDependencies": { - "@babel/runtime": "7.x" - } - }, - "node_modules/@web3auth/mpc-core-kit/node_modules/@toruslabs/torus.js": { - "version": "15.2.0-alpha.0", - "resolved": "https://registry.npmjs.org/@toruslabs/torus.js/-/torus.js-15.2.0-alpha.0.tgz", - "integrity": "sha512-W0HXmffYTbA9pFC3gdj6ON+FsmzJlSksT6hW5mDkRLZp1qSprYppjHnnnelq5n46yOs+290En8LP5s/U5viluw==", - "dependencies": { - "@toruslabs/bs58": "^1.0.0", - "@toruslabs/constants": "^14.0.0", - "@toruslabs/eccrypto": "^5.0.4", - "@toruslabs/http-helpers": "^7.0.0", - "bn.js": "^5.2.1", - "elliptic": "^6.5.7", - "ethereum-cryptography": "^2.2.1", - "json-stable-stringify": "^1.1.1", - "loglevel": "^1.9.2" - }, + "license": "MIT", "engines": { "node": ">=18.x", "npm": ">=9.x" diff --git a/mpc-core-kit-web/mpc-core-kit-bitcoin/package.json b/mpc-core-kit-web/mpc-core-kit-bitcoin/package.json index bed0e42c..fade42b7 100644 --- a/mpc-core-kit-web/mpc-core-kit-bitcoin/package.json +++ b/mpc-core-kit-web/mpc-core-kit-bitcoin/package.json @@ -15,7 +15,7 @@ "@vitejs/plugin-react": "^4.3.1", "@web3auth/base": "^9.4.5", "@web3auth/ethereum-mpc-provider": "^9.4.5", - "@web3auth/mpc-core-kit": "^4.1.0-alpha.0", + "@web3auth/mpc-core-kit": "file:web3auth-mpc-core-kit-4.0.0-alpha.1.tgz", "axios": "^1.7.7", "bitcoinjs-lib": "^6.1.5", "bn.js": "^5.2.1", @@ -70,4 +70,4 @@ "build": "tsc && vite build", "serve": "vite preview" } -} \ No newline at end of file +} diff --git a/mpc-core-kit-web/mpc-core-kit-bitcoin/src/App.tsx b/mpc-core-kit-web/mpc-core-kit-bitcoin/src/App.tsx index c2438a92..a5586953 100644 --- a/mpc-core-kit-web/mpc-core-kit-bitcoin/src/App.tsx +++ b/mpc-core-kit-web/mpc-core-kit-bitcoin/src/App.tsx @@ -44,7 +44,7 @@ let evmProvider: EthereumSigningProvider; if (typeof window !== "undefined") { coreKitInstance = new Web3AuthMPCCoreKit({ web3AuthClientId, - web3AuthNetwork: WEB3AUTH_NETWORK.MAINNET, + web3AuthNetwork: WEB3AUTH_NETWORK.DEVNET, storage: window.localStorage, manualSync: true, tssLib: tssLibFrostBip340, // tssLibDkls | tssLibFrostBip340 - Taproot only diff --git a/mpc-core-kit-web/mpc-core-kit-bitcoin/src/BitcoinComponent.tsx b/mpc-core-kit-web/mpc-core-kit-bitcoin/src/BitcoinComponent.tsx index c33138a8..746c652e 100644 --- a/mpc-core-kit-web/mpc-core-kit-bitcoin/src/BitcoinComponent.tsx +++ b/mpc-core-kit-web/mpc-core-kit-bitcoin/src/BitcoinComponent.tsx @@ -12,7 +12,7 @@ const ECPair = ECPairFactory(ecc); bitcoinjs.initEccLib(ecc); const BTCValidator = (pubkey: Buffer, msghash: Buffer, signature: Buffer): boolean => { - return ECPair.fromPublicKey(pubkey).verify(msghash, signature); + return ecc.verifySchnorr(Uint8Array.from(msghash), Uint8Array.from(pubkey), Uint8Array.from(signature)); }; const uiConsole = (...args: any): void => { @@ -77,7 +77,9 @@ export const BitcoinComponent: React.FC = ({ coreKitInsta const fetchUtxos = async (address: string) => { try { - const response = await axios.get(`https://blockstream.info/testnet/api/address/${address}/utxo`); + const url = `https://blockstream.info/testnet/api/address/${address}/utxo`; + console.log(url); + const response = await axios.get(url); return response.data.filter((utxo: { status: { confirmed: boolean } }) => utxo.status.confirmed); } catch (error) { console.error("Error fetching UTXOs:", error); @@ -128,9 +130,9 @@ export const BitcoinComponent: React.FC = ({ coreKitInsta const maxFee = Math.max(...Object.values(feeResponse.data as Record)); const fee = Math.ceil(maxFee * 1.2); // Adding 20% buffer to the fee - if (utxo.value <= fee) { - throw new Error(`Insufficient funds: ${utxo.value} satoshis <= ${fee} satoshis (estimated fee)`); - } + // if (utxo.value <= fee) { + // throw new Error(`Insufficient funds: ${utxo.value} satoshis <= ${fee} satoshis (estimated fee)`); + // } const sendAmount = amount ? parseInt(amount) : utxo.value - fee; diff --git a/mpc-core-kit-web/mpc-core-kit-bitcoin/src/BitcoinSigner.ts b/mpc-core-kit-web/mpc-core-kit-bitcoin/src/BitcoinSigner.ts index 0297cea5..6bcd54f1 100644 --- a/mpc-core-kit-web/mpc-core-kit-bitcoin/src/BitcoinSigner.ts +++ b/mpc-core-kit-web/mpc-core-kit-bitcoin/src/BitcoinSigner.ts @@ -5,6 +5,7 @@ import * as bitcoinjs from "bitcoinjs-lib"; import ECPairFactory from "ecpair"; import ecc from "@bitcoinerlab/secp256k1"; +import BN from "bn.js"; const ECPair = ECPairFactory(ecc); @@ -21,20 +22,26 @@ export function createBitcoinJsSigner(props: { coreKitInstance: Web3AuthMPCCoreK } -export function createBitcoinJsSignerBip340(props: { coreKitInstance: Web3AuthMPCCoreKit; network: networks.Network }): SignerAsync { +export function createBitcoinJsSignerBip340(props: { coreKitInstance: Web3AuthMPCCoreKit; network: networks.Network; }): SignerAsync { const bufPubKey = props.coreKitInstance.getPubKeyPoint().toSEC1(secp256k1, true); const xOnlyPubKey = bufPubKey.subarray(1, 33); const keyPair = ECPair.fromPublicKey(bufPubKey); - const tweakedChildNode = keyPair.tweak(bitcoinjs.crypto.taggedHash("TapTweak", xOnlyPubKey)); return { + const tweak = bitcoinjs.crypto.taggedHash("TapTweak", xOnlyPubKey); + const tweakedChildNode = keyPair.tweak(tweak); + const pk = tweakedChildNode.publicKey; + + // const pk = props.coreKitInstance.getPubKeyPoint().toSEC1(secp256k1, true); + return { sign: async (msg: Buffer) => { let sig = await props.coreKitInstance.sign(msg); return sig; }, signSchnorr: async (msg: Buffer) => { - let sig = await props.coreKitInstance.sign(msg); + const keyTweak = new BN(tweak); + let sig = await props.coreKitInstance.sign(msg, { keyTweak }); return sig; }, - publicKey: tweakedChildNode.publicKey, + publicKey: pk, network: props.network, }; } diff --git a/mpc-core-kit-web/mpc-core-kit-bitcoin/toruslabs-tss-frost-client-1.0.0-alpha.1.tgz b/mpc-core-kit-web/mpc-core-kit-bitcoin/toruslabs-tss-frost-client-1.0.0-alpha.1.tgz new file mode 100644 index 00000000..80c4c936 Binary files /dev/null and b/mpc-core-kit-web/mpc-core-kit-bitcoin/toruslabs-tss-frost-client-1.0.0-alpha.1.tgz differ diff --git a/mpc-core-kit-web/mpc-core-kit-bitcoin/toruslabs-tss-frost-common-1.1.0-alpha.0.tgz b/mpc-core-kit-web/mpc-core-kit-bitcoin/toruslabs-tss-frost-common-1.1.0-alpha.0.tgz new file mode 100644 index 00000000..f6c10236 Binary files /dev/null and b/mpc-core-kit-web/mpc-core-kit-bitcoin/toruslabs-tss-frost-common-1.1.0-alpha.0.tgz differ diff --git a/mpc-core-kit-web/mpc-core-kit-bitcoin/web3auth-mpc-core-kit-4.0.0-alpha.1.tgz b/mpc-core-kit-web/mpc-core-kit-bitcoin/web3auth-mpc-core-kit-4.0.0-alpha.1.tgz new file mode 100644 index 00000000..c7747f33 Binary files /dev/null and b/mpc-core-kit-web/mpc-core-kit-bitcoin/web3auth-mpc-core-kit-4.0.0-alpha.1.tgz differ