关键点AI不行了,要不你看看

import json

import hashlib

import time

from ecdsa import SigningKey, SECP256k1 # Make sure to install the library for signing

def create_event(pubkey, created_at, kind, tags, content, private_key):

# Step 1: Create the event structure

event_structure = [

0,

pubkey.lower(),

created_at,

kind,

tags,

content

]

# Step 2: Serialize to JSON

serialized_event = json.dumps(event_structure, separators=(',', ':')).encode('utf-8')

# Step 3: Calculate the ID

event_id = hashlib.sha256(serialized_event).hexdigest()

# Step 4: Sign the serialized event

sk = SigningKey.from_string(bytes.fromhex(private_key), curve=SECP256k1)

signature = sk.sign(hashlib.sha256(serialized_event).digest()).hex()

# Step 5: Construct the final event object

event = {

"id": event_id,

"pubkey": pubkey.lower(),

"created_at": created_at,

"kind": kind,

"tags": tags,

"content": content,

"sig": signature

}

return event

# Example usage

pubkey = "7ccedbafd024939c4077942dcc8f998a398ab6e214036e827ff5edc1f3a62f39"

created_at = int(time.time())

kind = 1

tags = []

content = "hello world"

private_key = "f45df7a0accd3226ec5d01a56c9238c131495b288127d984c98d7b17a763c427" # Replace with your actual private key

event = create_event(pubkey, created_at, kind, tags, content, private_key)

event_json = json.dumps(event, separators=(',', ':'), indent=2)

print(event_json)

Reply to this note

Please Login to reply.

Discussion

产生的事件到nak看就已经是sig:no了

我和你水平差不多😅,没看懂你的问题是什么,你的问题是什么

来自Nostrmo

签名无效,总是返回bad signature