diff --git a/README.md b/README.md index b0e4eac..61a0aab 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ _Code examples are using `snippets.py` which is not part of the go library._ from nats_jwt.v2.snippets import Operator from nats_jwt.v2.account_claims import Export from nats_jwt.nkeys_ext import nkeys2 -from nkeys import nkeys +import nkeys # create raw seed - 32 'random' bytes raw_seed: bytes = nkeys2.create_seed() diff --git a/nats_jwt/nkeys_ext/nkeys2.py b/nats_jwt/nkeys_ext/nkeys2.py index bba5332..32867e4 100644 --- a/nats_jwt/nkeys_ext/nkeys2.py +++ b/nats_jwt/nkeys_ext/nkeys2.py @@ -18,9 +18,8 @@ import os import typing -import ed25519 import nkeys -from ed25519 import VerifyingKey +from nacl.signing import VerifyKey from nkeys import crc16 if typing.TYPE_CHECKING: @@ -46,8 +45,9 @@ class PublicKey: def __init__(self, pub_key: bytes): self.kp = pub_key - def get_verifying_key(self) -> VerifyingKey: - return VerifyingKey(self.kp) + @property + def verify_key(self) -> VerifyKey: + return VerifyKey(self.kp) def keypair_from_pubkey(pub_key: bytes) -> "nkeys.KeyPair": @@ -149,10 +149,7 @@ def encode_seed(prefix: int, seed: bytes) -> bytes: def create_pair_with_rand(prefix: int, seed: bytes = None) -> nkeys.KeyPair: seed = seed or create_seed() - return nkeys.KeyPair( - seed=encode_seed(prefix, seed), - keys=ed25519.SigningKey(seed), - ) + return nkeys.from_seed(encode_seed(prefix,seed)) def create_operator_pair() -> nkeys.KeyPair: diff --git a/nats_jwt/v2/account_claims.py b/nats_jwt/v2/account_claims.py index 6ad0864..919a8b8 100644 --- a/nats_jwt/v2/account_claims.py +++ b/nats_jwt/v2/account_claims.py @@ -19,7 +19,7 @@ from typing import Final, TYPE_CHECKING, Literal from dataclasses_json import config, dataclass_json -from nkeys import nkeys +import nkeys from nats_jwt.nkeys_ext import Decode from nats_jwt.v2.claims import _claim_data_config, AccountClaim, Claims, ClaimsData, GenericFields diff --git a/nats_jwt/v2/snippets.py b/nats_jwt/v2/snippets.py index 4fb25bc..180aa15 100644 --- a/nats_jwt/v2/snippets.py +++ b/nats_jwt/v2/snippets.py @@ -22,7 +22,7 @@ import typing as t from abc import ABC, abstractmethod -from nkeys import from_seed, KeyPair, nkeys +from nkeys import from_seed, KeyPair, ErrInvalidSignature from nats_jwt.nkeys_ext import create_account_pair, create_operator_pair, create_user_pair, keypair_from_pubkey from nats_jwt.v2.account_claims import AccountClaims @@ -214,7 +214,7 @@ def verify(self, jwt: JWT) -> bool: # if claims are set, we can verify with them return self.claims.verify_jwt(jwt) - except nkeys.ErrInvalidSignature as e: + except ErrInvalidSignature as e: return False diff --git a/nats_jwt/v2/user_claims.py b/nats_jwt/v2/user_claims.py index 4b836b4..bf6490f 100644 --- a/nats_jwt/v2/user_claims.py +++ b/nats_jwt/v2/user_claims.py @@ -17,7 +17,7 @@ from dataclasses import dataclass, field from typing import Final -import nkeys.nkeys +import nkeys from nats_jwt.nkeys_ext import Decode from nats_jwt.v2.claims import _claim_data_config, ClaimsData, GenericFields, PrefixByte, UserClaim diff --git a/poetry.lock b/poetry.lock index 43211d9..6db7371 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,14 +1,14 @@ -# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. [[package]] name = "argcomplete" -version = "3.2.2" +version = "3.5.0" description = "Bash tab completion for argparse" optional = false python-versions = ">=3.8" files = [ - {file = "argcomplete-3.2.2-py3-none-any.whl", hash = "sha256:e44f4e7985883ab3e73a103ef0acd27299dbfe2dfed00142c35d4ddd3005901d"}, - {file = "argcomplete-3.2.2.tar.gz", hash = "sha256:f3e49e8ea59b4026ee29548e24488af46e30c9de57d48638e24f54a1ea1000a2"}, + {file = "argcomplete-3.5.0-py3-none-any.whl", hash = "sha256:d4bcf3ff544f51e16e54228a7ac7f486ed70ebf2ecfe49a63a91171c76bf029b"}, + {file = "argcomplete-3.5.0.tar.gz", hash = "sha256:4349400469dccfb7950bb60334a680c58d88699bff6159df61251878dc6bf74b"}, ] [package.extras] diff --git a/pyproject.toml b/pyproject.toml index fb88d64..dbff15c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,12 +9,13 @@ packages = [{include = "nats_jwt"}] [tool.poetry.dependencies] python = "^3.9" -nkeys = "^0.1.0" +nkeys = "^0.2.0" pycryptodome = "^3.20.0" pytz = "^2024.1" dataclasses-json = "^0.6.4" dacite = "^1.8.1" +pysodium = "^0.7.18" [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api"