Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught Error: Expected property "pubkey" of type ?isPoint, got Uint8Array #2209

Open
moodisk opened this issue Feb 9, 2025 · 1 comment

Comments

@moodisk
Copy link

moodisk commented Feb 9, 2025

This problem has been bothering me for many days, I want to generate a P2WPKH address from an existing private key, but I always get an error. Thank you for helping me.

root@instance-2:/bitcoinjs-lib# npm install bitcoinjs-lib
root@instance-2:
/bitcoinjs-lib# npm install ecpair bip32
root@instance-2:~/bitcoinjs-lib# npm install tiny-secp256k1

root@instance-2:~/bitcoinjs-lib# node
Welcome to Node.js v22.12.0.
Type ".help" for more information.

const bitcoin = require('bitcoinjs-lib');
undefined
const ECPairFactory = require('ecpair');
undefined
const ecc = require('tiny-secp256k1');
undefined
const ECPair = ECPairFactory.ECPairFactory(ecc);
undefined
const keyPair = ECPair.fromWIF('KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn');
undefined
const { address } = bitcoin.payments.p2pkh({pubkey:keyPair.publicKey});
Uncaught Error: Expected property "pubkey" of type ?isPoint, got Uint8Array
at captureStackTrace (/root/bitcoinjs-lib/node_modules/typeforce/errors.js:20:11)
at tfSubError (/root/bitcoinjs-lib/node_modules/typeforce/errors.js:99:3)
at _object (/root/bitcoinjs-lib/node_modules/typeforce/index.js:117:15)
at typeforce (/root/bitcoinjs-lib/node_modules/typeforce/index.js:233:9)
at typeforce (/root/bitcoinjs-lib/node_modules/typeforce/index.js:239:10)
at Object.p2pkh (/root/bitcoinjs-lib/node_modules/bitcoinjs-lib/src/payments/p2pkh.js:25:25) {
__label: undefined,
__property: 'pubkey',
__type: [Function: _maybe] { toJSON: [Function (anonymous)] },
__value: Uint8Array(33) [
2, 121, 190, 102, 126, 249, 220, 187,
172, 85, 160, 98, 149, 206, 135, 11,
7, 2, 155, 252, 219, 45, 206, 40,
217, 89, 242, 129, 91, 22, 248, 23,
152
],
__valueTypeName: 'Uint8Array'
}

@HenryPendry
Copy link

HenryPendry commented Feb 23, 2025

try this

const { address } = bitcoin.payments.p2pkh( {pubkey: Buffer.from(keyPair.publicKey)} )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants