Skip to content

Instantly share code, notes, and snippets.

@vikramacharya
Created August 23, 2022 16:31
Show Gist options
  • Save vikramacharya/e3a2e5acb6fae9aecf21ebeb9def7adb to your computer and use it in GitHub Desktop.
Save vikramacharya/e3a2e5acb6fae9aecf21ebeb9def7adb to your computer and use it in GitHub Desktop.
import base64
import datetime
import os
import re
import json
import nacl.encoding
import nacl.hash
from nacl.bindings import crypto_sign_ed25519_sk_to_seed
from nacl.signing import SigningKey, VerifyKey
def create_authorisation_header(request_body=request_body_json,
created=os.getenv("CREATED", "1641287875"),
expires=os.getenv("EXPIRES", "1641291475")):
signing_key = create_signing_string(hash_message(json.dumps(request_body, separators=(',', ':'))),
created=created, expires=expires)
signature = sign_response(signing_key, private_key=os.getenv("BPP_PRIVATE_KEY"))
subscriber_id = os.getenv("SUBSCRIBER_ID", "your_subscriver_id")
unique_key_id = os.getenv("UNIQUE_KEY_ID", "Your_unique_key")
header = f'Signature keyId="{subscriber_id}|{unique_key_id}|ed25519",algorithm="ed25519",created=' \
f'"{created}",expires="{expires}",headers="(created) (expires) digest",signature="{signature}"'
return header
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment