Closed drhanlondon closed 2 weeks ago
You can already do this by implementing a custom AsyncSigner and passing it into the async signing methods.
SignerAsync interface. (Need signSchnorr method if you plan on signing p2tr)
Then pass it in as the second argument here, or there are other methods like signAllInputsAsync
Thank you for your comment. First, regarding Schnorr signatures: this is currently outside our business scope since neither Fireblocks nor AWS KMS supports Schnorr signatures.
It seems there might be a slight misunderstanding of my request. Here’s some background:
bitcoinjs-lib
; it’s generated and held in custody by Fireblocks or AWS KMS.bitcoinjs-lib
, specifically the Psbt
class, to construct the Bitcoin transaction.For example, on the Ethereum blockchain, we have a function that generates a hashed message for signing.
/**
* Returns the hashed serialized unsigned tx, which can be used
* to sign the transaction (e.g. for sending to a hardware wallet).
*/
getHashedMessageToSign() {
const message = this.getMessageToSign()
return this.keccakFunction(RLP.encode(message))
}
Similarly, for Bitcoin, we need a custom getHashForSigning
function as outlined above. I was asking if it would be possible to add this function to the Psbt
class.
It seems there might be a slight misunderstanding
There is no misunderstanding.
class MyAWSSigner implements SignerAsync {
private pubkeyCache?: Uint8Array;
constructor(private readonly awsCredentials: AWSCredentials) {}
async initPubkey() {
this.pubkeyCache = await somefunctionToGetThePublicKey(this.awsCredentials);
}
get publicKey(): Uint8Array {
if (!this.pubkeyCache) throw new Error('Run initPubkey() first');
return this.pubkeyCache
}
async sign(hash: Uint8Array, lowR?: boolean): Promise<Uint8Array> {
// The `hash` parameter inside this function is what you want
return await signUsingYourAWSHSM(this.awsCredentials, hash);
}
}
Then you use it
const signer = new MyAWSSigner("... Some AWS credential from env or something...");
await signer.initPubkey();
await psbt.signAllInputsAsync(signer);
Hello,
I’d like to suggest a new feature that allows us to get a hash from the input and sign it using an external custodian, such as Fireblocks or AWS KMS. I’ve added the function below to the
Psbt
class in my personal Git fork of this repo and tested it; it works well.https://github.com/drhanlondon/bitcoinjs-lib-quant/blob/138aedec1780e212e1485d8f64697881a36457ca/ts_src/psbt.ts#L877
Thank you. Dr S Han