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

add: method to validate SP payment code #10

Merged
merged 1 commit into from
May 28, 2024
Merged

Conversation

Overtorment
Copy link
Member

@josibake merging it. FYI only

@Overtorment Overtorment merged commit cccf286 into master May 28, 2024
1 check passed
@Overtorment Overtorment deleted the add-validation-method branch May 28, 2024 18:42
try {
const result = bech32m.decode(pc, 118);
const version = result.words.shift();
if (version !== 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silent payment addresses are meant to be forward compatible, so that a v0 sender can send to a v1, v2, v3, etc address without needing to make any changes. BIP352 specifies the following rules for a v0 sp sender when checking an address:

  1. If version === 0, check that the data part is exactly 66-bytes (2 public keys). Otherwise, fail
  2. If 0 < version < 31, read the first 66-bytes of the data part and ignore the remaining bytes
  3. If version === 31, fail.


static isPaymentCodeValid(pc: string) {
try {
const result = bech32m.decode(pc, 118);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, this 118 is the char limit being passed to decode? Since new versions of sp address can (and likely will) have more data added to the data part, might be better to use 1024 here? This is the recommended number from the BIP

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.

2 participants