After looking through your code, duplicating it, trying to get it to work with GaiaHub, I’m deciding to wait until it gets put into the browser/blockstack.js and tested by you guys because it keeps failing for a multitude of reasons.
This was my process:
Here, the iss
field should be the public key of a whitelisted address. The childtoAssociate
should be equal to the iss
field of the authentication JWT.
This is quite ambiguous, but I finally figured it to mean the iss
is the publicKey of the whitelisted account address in hex. The childToAssociate
field should be the publicKey of the app, in hex.
Compare this to the auth reply from the browser to the app, which has the public key in in compressed form, not hex, and is also delivered as did:btc-addr:<address>
instead for some odd reason.
Once all this was sorted, I properly gave the association token with the right fields and a randomly generated salt, with the app’s public key in hex (and properly tested to be able to return back to it’s address form for double checking), however Gaia still didn’t want it throwing this error:
Which, if I did double check correctly, the GaiaHub has a bug here that was never actually tested, making this entire day a mess to begin with.
(this was my testing code:)
import { payments } from 'bitcoinjs-lib';
import { hexStringToECPair } from 'blockstack';
// ...
// this worked because the ECPair has a `.publicKey` field.
function getAddress(node: bip32, network?: any) {
return payments.p2pkh({ pubkey: node.publicKey }).address;
}
// ...
const appPublicKey = hexStringToECPair(appPrivateKey).publicKey.toString('hex');
// v- showed the correct public (compressed) address
console.warn('DEBUG\n' + getAddress(ECPair.fromPublicKey(Buffer.from(appPublicKey, 'hex'))));
I do hope we can get these issues ironed out and a proper implementation so that users can start using their own gaiahubs soon.