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

feat(sdk): integrate bip322-js to sign & verify non-legacy address messages #91

Merged
merged 5 commits into from
Nov 3, 2023

Conversation

iamcrazycoder
Copy link
Contributor

What this PR does / why we need it:

This PR installs & integrates bip322-js lib to sign and verify messages generated using p2wpkh, p2sh-p2wpkh, and single-key-spend p2tr addresses.

bitcoinjs-message only supports p2pkh and despite their latest support to segwit, we would like to keep the segregation of libs that are capable to handle and well-designed for a specific purpose.

BIP-322 outlines the approach bip322-js follows to enable message signing and verification for non-legacy addresses.

@iamcrazycoder iamcrazycoder self-assigned this Nov 2, 2023
@iamcrazycoder
Copy link
Contributor Author

iamcrazycoder commented Nov 3, 2023

Tested!

Network: testnet
Message: Hello World

p2pkh

{
  valid: true,
  address: 'mwwTsmPhVcJzbW6dCeLVYoJQMraW1EeeuN',
  signature: 'GxRHEfAIsIAsn4jy0MPMEh7jORud5z+INr1ij/31/0E9IAQut/4A+DIKHHx2yi0GejWMun4hHv57JaTd078s7JQ='
}

p2wpkh

{
  valid: true,
  address: 'tb1q7fr9dx0zdc4hf9puv09fyn4kfhrh5kqtgmf8gf',
  signature: 'AkgwRQIhANHPqlEHGfRzyHMPSqZ+ieyWQAfuoX3NgQbdRvltlxNjAiBQASTQO62Y/qhpNeoBvAvRPGWRncDX43dUp2GaSDysyQEhAoXBzTNkinNc96Yquo2eZDvtNZ7dUoVlznDJmz0we1XT'
}

p2sh-p2wpkh

{
  valid: true,
  address: '2NBmNuuZptq8gZy8iijWbVixRgCyKz9ceVq',
  signature: 'AkcwRAIgD1wiaWXRMkVUS9tGKg4dAFCee6LvIffpPqzjN+lpb3sCIFAvY4DiwX0GOfuqy+T1wENCFqQL2Q0VKnuhYf3JwLc5ASEC5lFOxlAracNgXcAw33sWb1kT3nan9kjHZZNbfq1Txf4='
}

p2tr

{
  valid: true,
  address: 'tb1p98dv6f5jp5qr4z2dtaljvwrhq34xrr8zuaqgv4ajf36vg2mmsruqt5m3lv',
  signature: 'AUHTRNsNOd/GEyqahL6ZSGZsebcf4j60kA5GQ3LP62YcETZszVg+XeaH4fI0b/WaWVjQVQvLIPL0DdG1CcWB5VL+AQ=='
}

Code used to test:

import { Ordit, verifyMessage } from '@sadoprotocol/ordit-sdk'

async function main() {
  const network = 'testnet'
  const wallet = new Ordit({
      bip39: '<mnemonic>',
      network
  })
  wallet.setDefaultAddress('taproot')

  const message = 'Hello World'
  const signature = wallet.signMessage(message)

  const valid = verifyMessage({
    address: wallet.selectedAddress,
    message,
    signature
  })

  console.log({
    valid,
    address: wallet.selectedAddress,
    signature
  })
}

main();

@iamcrazycoder iamcrazycoder marked this pull request as ready for review November 3, 2023 07:43
@iamcrazycoder iamcrazycoder merged commit de0fdf1 into main Nov 3, 2023
2 checks passed
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

Successfully merging this pull request may close these issues.

1 participant