Skip to main content

Strict DER signature encoding/decoding.

Project description

Strict DER signature encoding/decoding.

See bip66.

  • This module works only with two's complement numbers.
  • BIP66 doesn't check that r or s are fully valid.
    • check/decode doesn't check that r or s great than 33 bytes or that this number represent valid point on elliptic curve.
    • encode doesn't check that r/s represent valid point on elliptic curve.

Example

import bip66
r = "29db2d5f4e1dcc04e19266cce3cb135865784c62ab653b307f0e0bb744f5c2aa"
s = "00a97f5826912cac8b44d9f577a26f169a2f8db781f2ddb7de2bc886e93b6844"
encoded = bip66.encode(binascii.unhexlify(r), binascii.unhexlify(s))
signature = binascii.hexlify(encoded).decode()
# > 00a97f5826912cac8b44d9f577a26f169a2f8db781f2ddb7de2bc886e93b6844

DER = "3044022029db2d5f4e1dcc04e19266cce3cb135865784c62ab653b307f0e0bb" \
      "744f5c2aa022000a97f5826912cac8b44d9f577a26f169a2f8db781f2ddb7de2bc886e93b6844"
r, s = bip66.decode(binascii.unhexlify(DER))
print(binascii.hexlify(r).decode())
print(binascii.hexlify(s).decode())

# > 29db2d5f4e1dcc04e19266cce3cb135865784c62ab653b307f0e0bb744f5c2aa
# > 00a97f5826912cac8b44d9f577a26f169a2f8db781f2ddb7de2bc886e93b6844

A catch-all exception regex:

/Expected DER (integer|sequence)|(R|S) value (excessively padded|is negative)|(R|S|DER sequence) length is (zero|too short|too long|invalid)/

LICENSE MIT

Project details


Release history Release notifications | RSS feed

This version

0.4

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bip66-0.4-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file bip66-0.4-py3-none-any.whl.

File metadata

  • Download URL: bip66-0.4-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for bip66-0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 aa79b753db54bdf57cabcf68315700316bab7da30561e810603c1c01c74df350
MD5 187859bbb1b0208b5e4598fcb51ba608
BLAKE2b-256 ec39b383faec6f161c9a5f22a41ab4e2e7ea4439ab17a7730f9c667a35089761

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page